PGENERAL_GROUP_DATA pGroupData)
{
LOCALGROUP_INFO_1 groupInfo;
- LPTSTR pszComment = NULL;
- INT nLength;
NET_API_STATUS status;
DWORD dwIndex;
/* Get the group description */
- nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_GROUP_GENERAL_DESCRIPTION));
- if (nLength == 0)
- {
- groupInfo.lgrpi1_comment = NULL;
- }
- else
- {
- pszComment = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
- GetDlgItemText(hwndDlg, IDC_GROUP_GENERAL_DESCRIPTION, pszComment, nLength + 1);
- groupInfo.lgrpi1_comment = pszComment;
- }
+ groupInfo.lgrpi1_comment = GetDlgItemTextAlloc(hwndDlg, IDC_GROUP_GENERAL_DESCRIPTION);
status = NetLocalGroupSetInfo(NULL, pGroupData->szGroupName, 1, (LPBYTE)&groupInfo, &dwIndex);
if (status != NERR_Success)
ERR("NetLocalGroupSetInfo failed. Status: %lu Index: %lu", status, dwIndex);
}
- if (pszComment)
- HeapFree(GetProcessHeap(), 0, pszComment);
+ HeapFree(GetProcessHeap(), 0, groupInfo.lgrpi1_comment);
return TRUE;
}
break;
}
- nLength = SendDlgItemMessage(hwndDlg, IDC_GROUP_NEW_NAME, WM_GETTEXTLENGTH, 0, 0);
- if (nLength > 0)
- {
- groupInfo->lgrpi1_name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
- GetDlgItemText(hwndDlg, IDC_GROUP_NEW_NAME, groupInfo->lgrpi1_name, nLength + 1);
- }
+ /* Get Name */
+ groupInfo->lgrpi1_name = GetDlgItemTextAlloc(hwndDlg, IDC_GROUP_NEW_NAME);
- nLength = SendDlgItemMessage(hwndDlg, IDC_GROUP_NEW_DESCRIPTION, WM_GETTEXTLENGTH, 0, 0);
- if (nLength > 0)
- {
- groupInfo->lgrpi1_comment = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
- GetDlgItemText(hwndDlg, IDC_GROUP_NEW_DESCRIPTION, groupInfo->lgrpi1_comment, nLength + 1);
- }
+ /* Get Description */
+ groupInfo->lgrpi1_comment = GetDlgItemTextAlloc(hwndDlg, IDC_GROUP_NEW_DESCRIPTION);
EndDialog(hwndDlg, IDOK);
break;
group.lgrpi1_comment);
}
- if (group.lgrpi1_name)
- HeapFree(GetProcessHeap(), 0, group.lgrpi1_name);
-
- if (group.lgrpi1_comment)
- HeapFree(GetProcessHeap(), 0, group.lgrpi1_comment);
+ HeapFree(GetProcessHeap(), 0, group.lgrpi1_name);
+ HeapFree(GetProcessHeap(), 0, group.lgrpi1_comment);
}
PPROFILE_USER_DATA pUserData)
{
PUSER_INFO_3 pUserInfo = NULL;
- LPTSTR pszProfilePath = NULL;
- LPTSTR pszScriptPath = NULL;
- LPTSTR pszHomeDir = NULL;
- LPTSTR pszHomeDrive = NULL;
NET_API_STATUS status;
DWORD dwIndex;
- INT nLength;
INT nIndex;
NetUserGetInfo(NULL, pUserData->szUserName, 3, (LPBYTE*)&pUserInfo);
/* Get the profile path */
- nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_PROFILE_PATH));
- if (nLength == 0)
- {
- pUserInfo->usri3_profile = NULL;
- }
- else
- {
- pszProfilePath = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
- GetDlgItemText(hwndDlg, IDC_USER_PROFILE_PATH, pszProfilePath, nLength + 1);
- pUserInfo->usri3_profile = pszProfilePath;
- }
+ pUserInfo->usri3_profile = GetDlgItemTextAlloc(hwndDlg, IDC_USER_PROFILE_PATH);
/* Get the script path */
- nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_PROFILE_SCRIPT));
- if (nLength == 0)
- {
- pUserInfo->usri3_script_path = NULL;
- }
- else
- {
- pszScriptPath = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
- GetDlgItemText(hwndDlg, IDC_USER_PROFILE_SCRIPT, pszScriptPath, nLength + 1);
- pUserInfo->usri3_script_path = pszScriptPath;
- }
+ pUserInfo->usri3_script_path = GetDlgItemTextAlloc(hwndDlg, IDC_USER_PROFILE_SCRIPT);
if (IsDlgButtonChecked(hwndDlg, IDC_USER_PROFILE_LOCAL) == BST_CHECKED)
{
/* Local home directory */
- nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_PROFILE_LOCAL_PATH));
- if (nLength == 0)
- {
- pUserInfo->usri3_home_dir = NULL;
- }
- else
- {
- pszHomeDir = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
- GetDlgItemText(hwndDlg, IDC_USER_PROFILE_LOCAL_PATH, pszHomeDir, nLength + 1);
- pUserInfo->usri3_home_dir = pszHomeDir;
- }
+ pUserInfo->usri3_home_dir = GetDlgItemTextAlloc(hwndDlg, IDC_USER_PROFILE_LOCAL_PATH);
}
else
{
/* Remote home directory */
- nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_PROFILE_REMOTE_PATH));
- if (nLength == 0)
- {
- pUserInfo->usri3_home_dir = NULL;
- }
- else
- {
- pszHomeDir = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
- GetDlgItemText(hwndDlg, IDC_USER_PROFILE_REMOTE_PATH, pszHomeDir, nLength + 1);
- pUserInfo->usri3_home_dir = pszHomeDir;
- }
+ pUserInfo->usri3_home_dir = GetDlgItemTextAlloc(hwndDlg, IDC_USER_PROFILE_REMOTE_PATH);
nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE), CB_GETCURSEL, 0, 0);
if (nIndex != CB_ERR)
{
- nLength = SendMessage(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE), CB_GETLBTEXTLEN, nIndex, 0);
- pszHomeDrive = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
- SendMessage(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE), CB_GETLBTEXT, nIndex, (LPARAM)pszHomeDrive);
- pUserInfo->usri3_home_dir_drive = pszHomeDrive;
+ pUserInfo->usri3_home_dir_drive =
+ GetComboBoxLBTextAlloc(hwndDlg, IDC_USER_PROFILE_DRIVE, nIndex);
+ }
+ else
+ {
+ pUserInfo->usri3_home_dir_drive =
+ HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TCHAR));
}
}
ERR("NetUserSetInfo failed. Status: %lu Index: %lu", status, dwIndex);
}
- if (pszProfilePath)
- HeapFree(GetProcessHeap(), 0, pszProfilePath);
-
- if (pszScriptPath)
- HeapFree(GetProcessHeap(), 0, pszScriptPath);
-
- if (pszHomeDir)
- HeapFree(GetProcessHeap(), 0, pszHomeDir);
-
- if (pszHomeDrive)
- HeapFree(GetProcessHeap(), 0, pszHomeDrive);
+ HeapFree(GetProcessHeap(), 0, pUserInfo->usri3_profile);
+ HeapFree(GetProcessHeap(), 0, pUserInfo->usri3_script_path);
+ HeapFree(GetProcessHeap(), 0, pUserInfo->usri3_home_dir);
+ HeapFree(GetProcessHeap(), 0, pUserInfo->usri3_home_dir_drive);
NetApiBufferFree(pUserInfo);
PGENERAL_USER_DATA pUserData)
{
PUSER_INFO_3 pUserInfo = NULL;
- LPTSTR pszFullName = NULL;
- LPTSTR pszComment = NULL;
NET_API_STATUS status;
DWORD dwIndex;
- INT nLength;
NetUserGetInfo(NULL, pUserData->szUserName, 3, (LPBYTE*)&pUserInfo);
pUserInfo->usri3_password_expired = pUserData->dwPasswordExpired;
- nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_GENERAL_FULL_NAME));
- if (nLength == 0)
- {
- pUserInfo->usri3_full_name = NULL;
- }
- else
- {
- pszFullName = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
- GetDlgItemText(hwndDlg, IDC_USER_GENERAL_FULL_NAME, pszFullName, nLength + 1);
- pUserInfo->usri3_full_name = pszFullName;
- }
+ /* Get full name */
+ pUserInfo->usri3_full_name = GetDlgItemTextAlloc(hwndDlg, IDC_USER_GENERAL_FULL_NAME);
- nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_GENERAL_DESCRIPTION));
- if (nLength == 0)
- {
- pUserInfo->usri3_full_name = NULL;
- }
- else
- {
- pszComment = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
- GetDlgItemText(hwndDlg, IDC_USER_GENERAL_DESCRIPTION, pszComment, nLength + 1);
- pUserInfo->usri3_comment = pszComment;
- }
+ /* Get desciption */
+ pUserInfo->usri3_comment = GetDlgItemTextAlloc(hwndDlg, IDC_USER_GENERAL_DESCRIPTION);
status = NetUserSetInfo(NULL, pUserData->szUserName, 3, (LPBYTE)pUserInfo, &dwIndex);
if (status != NERR_Success)
ERR("NetUserSetInfo failed. Status: %lu Index: %lu", status, dwIndex);
}
- if (pszFullName)
- HeapFree(GetProcessHeap(), 0, pszFullName);
-
- if (pszComment)
- HeapFree(GetProcessHeap(), 0, pszComment);
+ HeapFree(GetProcessHeap(), 0, pUserInfo->usri3_full_name);
+ HeapFree(GetProcessHeap(), 0, pUserInfo->usri3_comment);
NetApiBufferFree(pUserInfo);
LPARAM lParam)
{
PUSER_INFO_1003 userInfo;
- INT nLength;
UNREFERENCED_PARAMETER(wParam);
case IDOK:
if (CheckPasswords(hwndDlg, IDC_EDIT_PASSWORD1, IDC_EDIT_PASSWORD2))
{
-
/* Store the password */
- nLength = SendDlgItemMessage(hwndDlg, IDC_EDIT_PASSWORD1, WM_GETTEXTLENGTH, 0, 0);
- if (nLength > 0)
- {
- userInfo->usri1003_password = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
- GetDlgItemText(hwndDlg, IDC_EDIT_PASSWORD1, userInfo->usri1003_password, nLength + 1);
- }
+ userInfo->usri1003_password =
+ GetDlgItemTextAlloc(hwndDlg, IDC_EDIT_PASSWORD1);
EndDialog(hwndDlg, IDOK);
}
}
}
- if (user.usri1003_password)
- HeapFree(GetProcessHeap(), 0, user.usri1003_password);
+ HeapFree(GetProcessHeap(), 0, user.usri1003_password);
}
}
/* Store the user name */
- nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_NAME, WM_GETTEXTLENGTH, 0, 0);
- if (nLength > 0)
- {
- userInfo->usri3_name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
- GetDlgItemText(hwndDlg, IDC_USER_NEW_NAME, userInfo->usri3_name, nLength + 1);
- }
+ userInfo->usri3_name = GetDlgItemTextAlloc(hwndDlg, IDC_USER_NEW_NAME);
/* Store the full user name */
- nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_FULL_NAME, WM_GETTEXTLENGTH, 0, 0);
- if (nLength > 0)
- {
- userInfo->usri3_full_name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
- GetDlgItemText(hwndDlg, IDC_USER_NEW_FULL_NAME, userInfo->usri3_full_name, nLength + 1);
- }
+ userInfo->usri3_full_name = GetDlgItemTextAlloc(hwndDlg, IDC_USER_NEW_FULL_NAME);
/* Store the description */
- nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_DESCRIPTION, WM_GETTEXTLENGTH, 0, 0);
- if (nLength > 0)
- {
- userInfo->usri3_comment = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
- GetDlgItemText(hwndDlg, IDC_USER_NEW_DESCRIPTION, userInfo->usri3_comment, nLength + 1);
- }
+ userInfo->usri3_comment = GetDlgItemTextAlloc(hwndDlg, IDC_USER_NEW_DESCRIPTION);
/* Store the password */
- nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_PASSWORD1, WM_GETTEXTLENGTH, 0, 0);
- if (nLength > 0)
- {
- userInfo->usri3_password = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
- GetDlgItemText(hwndDlg, IDC_USER_NEW_PASSWORD1, userInfo->usri3_password, nLength + 1);
- }
+ userInfo->usri3_password = GetDlgItemTextAlloc(hwndDlg, IDC_USER_NEW_PASSWORD1);
EndDialog(hwndDlg, IDOK);
break;
user.usri3_comment);
}
- if (user.usri3_name)
- HeapFree(GetProcessHeap(), 0, user.usri3_name);
-
- if (user.usri3_full_name)
- HeapFree(GetProcessHeap(), 0, user.usri3_full_name);
-
- if (user.usri3_comment)
- HeapFree(GetProcessHeap(), 0, user.usri3_comment);
-
- if (user.usri3_password)
- HeapFree(GetProcessHeap(), 0, user.usri3_password);
+ HeapFree(GetProcessHeap(), 0, user.usri3_name);
+ HeapFree(GetProcessHeap(), 0, user.usri3_full_name);
+ HeapFree(GetProcessHeap(), 0, user.usri3_comment);
+ HeapFree(GetProcessHeap(), 0, user.usri3_password);
}
* PURPOSE: Main functions
*
* PROGRAMMERS: Eric Kohl
+ * Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
*/
#include "usrmgr.h"
HINSTANCE hApplet = 0;
+LPTSTR GetDlgItemTextAlloc(HWND hwndDlg, INT nDlgItem)
+{
+ INT nLength = GetWindowTextLength(GetDlgItem(hwndDlg, nDlgItem));
+ LPTSTR psz = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
+ if (psz)
+ GetDlgItemText(hwndDlg, nDlgItem, psz, nLength + 1);
+ return psz;
+}
+
+LPTSTR GetComboBoxLBTextAlloc(HWND hwndDlg, INT nDlgItem, INT nIndex)
+{
+ INT nLength = (INT)SendDlgItemMessage(hwndDlg, nDlgItem, CB_GETLBTEXTLEN, nIndex, 0);
+ LPTSTR psz = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
+ if (psz)
+ SendDlgItemMessage(hwndDlg, nDlgItem, CB_GETLBTEXT, nIndex, (LPARAM)psz);
+ return psz;
+}
+
/* Applets */
APPLET Applets[NUM_APPLETS] =
{
}
};
-
static VOID
InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc)
{
extern HINSTANCE hApplet;
-
INT_PTR CALLBACK UsersPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK GroupsPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK ExtraPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
+LPTSTR GetDlgItemTextAlloc(HWND hwndDlg, INT nDlgItem);
+LPTSTR GetComboBoxLBTextAlloc(HWND hwndDlg, INT nDlgItem, INT nIndex);
+
/* groupprops.c */
BOOL
GroupProperties(HWND hwndDlg);