From 612e3a0420e067d736ce599abbe91830cae651ba Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Sat, 3 Dec 2005 14:07:38 +0000 Subject: [PATCH] - document and partly implement DevicePropertiesExA/W() - minor fixes svn path=/trunk/; revision=19837 --- reactos/lib/devmgr/advprop.c | 208 ++++++++++++++++++++++++++++++++--- reactos/lib/devmgr/hwpage.c | 10 +- reactos/lib/devmgr/misc.c | 3 + reactos/lib/devmgr/precomp.h | 56 ++++++---- reactos/lib/devmgr/stubs.c | 76 ------------- 5 files changed, 228 insertions(+), 125 deletions(-) diff --git a/reactos/lib/devmgr/advprop.c b/reactos/lib/devmgr/advprop.c index f284d559d24..9463290f222 100644 --- a/reactos/lib/devmgr/advprop.c +++ b/reactos/lib/devmgr/advprop.c @@ -67,6 +67,7 @@ typedef struct _DEVADVPROP_INFO BOOL DeviceUsageChanged : 1; BOOL CloseDevInst : 1; BOOL IsAdmin : 1; + BOOL DoDefaultDevAction : 1; WCHAR szDevName[255]; WCHAR szTemp[255]; @@ -682,7 +683,8 @@ DisplayDeviceAdvancedProperties(IN HWND hWndParent, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData, IN HINSTANCE hComCtl32, - IN LPCWSTR lpMachineName) + IN LPCWSTR lpMachineName, + IN DWORD dwFlags) { PROPSHEETHEADER psh = {0}; PROPSHEETPAGE pspGeneral = {0}; @@ -755,6 +757,7 @@ DisplayDeviceAdvancedProperties(IN HWND hWndParent, (DevIdSize * sizeof(WCHAR))); if (DevAdvPropInfo == NULL) { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); goto Cleanup; } @@ -788,6 +791,7 @@ DisplayDeviceAdvancedProperties(IN HWND hWndParent, DevAdvPropInfo->hComCtl32 = hComCtl32; DevAdvPropInfo->IsAdmin = IsUserAdmin(); + DevAdvPropInfo->DoDefaultDevAction = ((dwFlags & DPF_DEVICE_STATUS_ACTION) != 0); psh.dwSize = sizeof(PROPSHEETHEADER); psh.dwFlags = PSH_PROPTITLE | PSH_NOAPPLYNOW; @@ -940,19 +944,15 @@ Cleanup: * lpDeviceID: Specifies the device whose properties are to be shown * * RETURN VALUE - * -1: if errors occured - * - * REVISIONS - * - * NOTE + * Always returns -1, a call to GetLastError returns 0 if successful * * @implemented */ INT_PTR WINAPI -DeviceAdvancedPropertiesW(HWND hWndParent, - LPCWSTR lpMachineName, - LPCWSTR lpDeviceID) +DeviceAdvancedPropertiesW(IN HWND hWndParent OPTIONAL, + IN LPCWSTR lpMachineName OPTIONAL, + IN LPCWSTR lpDeviceID) { HDEVINFO hDevInfo; SP_DEVINFO_DATA DevInfoData; @@ -981,7 +981,8 @@ DeviceAdvancedPropertiesW(HWND hWndParent, hDevInfo, &DevInfoData, hComCtl32, - lpMachineName); + lpMachineName, + 0); } SetupDiDestroyDeviceInfoList(hDevInfo); @@ -1008,19 +1009,15 @@ DeviceAdvancedPropertiesW(HWND hWndParent, * lpDeviceID: Specifies the device whose properties are to be shown * * RETURN VALUE - * -1: if errors occured - * - * REVISIONS - * - * NOTE + * Always returns -1, a call to GetLastError returns 0 if successful * * @implemented */ INT_PTR WINAPI -DeviceAdvancedPropertiesA(HWND hWndParent, - LPCSTR lpMachineName, - LPCSTR lpDeviceID) +DeviceAdvancedPropertiesA(IN HWND hWndParent OPTIONAL, + IN LPCSTR lpMachineName OPTIONAL, + IN LPCSTR lpDeviceID) { LPWSTR lpMachineNameW = NULL; LPWSTR lpDeviceIDW = NULL; @@ -1063,3 +1060,178 @@ Cleanup: return Ret; } + + +/*************************************************************************** + * NAME EXPORTED + * DevicePropertiesExA + * + * DESCRIPTION + * Invokes the extended device properties dialog + * + * ARGUMENTS + * hWndParent: Handle to the parent window + * lpMachineName: Machine Name, NULL is the local machine + * lpDeviceID: Specifies the device whose properties are to be shown + * dwFlags: This parameter can be a combination of the following flags: + * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes + * the default device status action button + * to be clicked (Troubleshoot, Enable + * Device, etc) + * bShowDevMgr: If non-zero it displays the device manager instead of + * the advanced device property dialog + * + * RETURN VALUE + * 1: if bShowDevMgr is non-zero and no error occured + * -1: a call to GetLastError returns 0 if successful + * + * @implemented + */ +INT_PTR +WINAPI +DevicePropertiesExA(IN HWND hWndParent OPTIONAL, + IN LPCSTR lpMachineName OPTIONAL, + IN LPCSTR lpDeviceID OPTIONAL, + IN DWORD dwFlags OPTIONAL, + IN BOOL bShowDevMgr) +{ + LPWSTR lpMachineNameW = NULL; + LPWSTR lpDeviceIDW = NULL; + INT_PTR Ret = -1; + + if (lpMachineName != NULL) + { + if (!(lpMachineNameW = ConvertMultiByteToUnicode(lpMachineName, + CP_ACP))) + { + goto Cleanup; + } + } + if (lpDeviceID != NULL) + { + if (!(lpDeviceIDW = ConvertMultiByteToUnicode(lpDeviceID, + CP_ACP))) + { + goto Cleanup; + } + } + + Ret = DevicePropertiesExW(hWndParent, + lpMachineNameW, + lpDeviceIDW, + dwFlags, + bShowDevMgr); + +Cleanup: + if (lpMachineNameW != NULL) + { + HeapFree(GetProcessHeap(), + 0, + lpMachineNameW); + } + if (lpDeviceIDW != NULL) + { + HeapFree(GetProcessHeap(), + 0, + lpDeviceIDW); + } + + return Ret; +} + + +/*************************************************************************** + * NAME EXPORTED + * DevicePropertiesExW + * + * DESCRIPTION + * Invokes the extended device properties dialog + * + * ARGUMENTS + * hWndParent: Handle to the parent window + * lpMachineName: Machine Name, NULL is the local machine + * lpDeviceID: Specifies the device whose properties are to be shown + * dwFlags: This parameter can be a combination of the following flags: + * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes + * the default device status action button + * to be clicked (Troubleshoot, Enable + * Device, etc) + * bShowDevMgr: If non-zero it displays the device manager instead of + * the advanced device property dialog + * + * RETURN VALUE + * 1: if bShowDevMgr is non-zero and no error occured + * -1: a call to GetLastError returns 0 if successful + * + * @unimplemented + */ +INT_PTR +WINAPI +DevicePropertiesExW(IN HWND hWndParent OPTIONAL, + IN LPCWSTR lpMachineName OPTIONAL, + IN LPCWSTR lpDeviceID OPTIONAL, + IN DWORD dwFlags OPTIONAL, + IN BOOL bShowDevMgr) +{ + INT_PTR Ret = -1; + + if (dwFlags & ~(DPF_UNKNOWN | DPF_DEVICE_STATUS_ACTION)) + { + DPRINT1("DevPropertiesExW: Invalid flags: 0x%x\n", + dwFlags & ~(DPF_UNKNOWN | DPF_DEVICE_STATUS_ACTION)); + SetLastError(ERROR_INVALID_FLAGS); + return -1; + } + + if (bShowDevMgr) + { + DPRINT("DevPropertiesExW doesn't support bShowDevMgr!\n"); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + } + else + { + HDEVINFO hDevInfo; + SP_DEVINFO_DATA DevInfoData; + HINSTANCE hComCtl32; + + if (lpDeviceID == NULL) + { + SetLastError(ERROR_INVALID_PARAMETER); + return -1; + } + + /* dynamically load comctl32 */ + hComCtl32 = LoadAndInitComctl32(); + if (hComCtl32 != NULL) + { + hDevInfo = SetupDiCreateDeviceInfoListEx(NULL, + hWndParent, + lpMachineName, + NULL); + if (hDevInfo != INVALID_HANDLE_VALUE) + { + DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA); + if (SetupDiOpenDeviceInfo(hDevInfo, + lpDeviceID, + hWndParent, + 0, + &DevInfoData)) + { + Ret = DisplayDeviceAdvancedProperties(hWndParent, + lpDeviceID, + hDevInfo, + &DevInfoData, + hComCtl32, + lpMachineName, + dwFlags); + } + + SetupDiDestroyDeviceInfoList(hDevInfo); + } + + FreeLibrary(hComCtl32); + } + } + + return Ret; +} diff --git a/reactos/lib/devmgr/hwpage.c b/reactos/lib/devmgr/hwpage.c index 19e86d54b52..bb422977cd7 100644 --- a/reactos/lib/devmgr/hwpage.c +++ b/reactos/lib/devmgr/hwpage.c @@ -30,13 +30,6 @@ #define NDEBUG #include -typedef enum -{ - HWPD_STANDARDLIST = 0, - HWPD_LARGELIST, - HWPD_MAX = HWPD_LARGELIST -} HWPAGE_DISPLAYMODE, *PHWPAGE_DISPLAYMODE; - typedef struct _HWDEVINFO { struct _HWCLASSDEVINFO *ClassDevInfo; @@ -139,7 +132,8 @@ DisplaySelectedDeviceProperties(IN PHARDWARE_PAGE_DATA hpd) HwDevInfo->ClassDevInfo->hDevInfo, &HwDevInfo->DevInfoData, hpd->hComCtl32, - NULL) != -1; + NULL, + 0) != -1; } return Ret; diff --git a/reactos/lib/devmgr/misc.c b/reactos/lib/devmgr/misc.c index 92795cc3eb7..93bbc4832ff 100644 --- a/reactos/lib/devmgr/misc.c +++ b/reactos/lib/devmgr/misc.c @@ -254,7 +254,10 @@ ConvertMultiByteToUnicode(IN LPCSTR lpMultiByteStr, 0, nLength * sizeof(WCHAR)); if (lpUnicodeStr == NULL) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); return NULL; + } if (!MultiByteToWideChar(uCodePage, 0, diff --git a/reactos/lib/devmgr/precomp.h b/reactos/lib/devmgr/precomp.h index ce07e49a6e2..da367b2f379 100644 --- a/reactos/lib/devmgr/precomp.h +++ b/reactos/lib/devmgr/precomp.h @@ -120,15 +120,22 @@ DeviceManagerPrintW(LPCWSTR lpMachineName, INT_PTR WINAPI -DeviceAdvancedPropertiesA(HWND hWndParent, - LPCSTR lpMachineName, - LPCSTR lpDeviceID); +DeviceAdvancedPropertiesA(IN HWND hWndParent OPTIONAL, + IN LPCSTR lpMachineName OPTIONAL, + IN LPCSTR lpDeviceID); INT_PTR WINAPI -DeviceAdvancedPropertiesW(HWND hWndParent, - LPCWSTR lpMachineName, - LPCWSTR lpDeviceID); +DeviceAdvancedPropertiesW(IN HWND hWndParent OPTIONAL, + IN LPCWSTR lpMachineName OPTIONAL, + IN LPCWSTR lpDeviceID); + +typedef enum +{ + HWPD_STANDARDLIST = 0, + HWPD_LARGELIST, + HWPD_MAX = HWPD_LARGELIST +} HWPAGE_DISPLAYMODE, *PHWPAGE_DISPLAYMODE; HWND WINAPI @@ -137,26 +144,28 @@ DeviceCreateHardwarePage(HWND hWndParent, HWND WINAPI -DeviceCreateHardwarePageEx(HWND hWndParent, - LPGUID lpGuids, - UINT uNumberOfGuids, - UINT Unknown); +DeviceCreateHardwarePageEx(IN HWND hWndParent, + IN LPGUID lpGuids, + IN UINT uNumberOfGuids, + IN HWPAGE_DISPLAYMODE DisplayMode); -int +#define DPF_UNKNOWN (0x1) +#define DPF_DEVICE_STATUS_ACTION (0x2) +INT_PTR WINAPI -DevicePropertiesExA(HWND hWndParent, - LPCSTR lpMachineName, - LPCSTR lpDeviceID, - HINSTANCE hInst, - DWORD Unknown); +DevicePropertiesExA(IN HWND hWndParent OPTIONAL, + IN LPCSTR lpMachineName OPTIONAL, + IN LPCSTR lpDeviceID OPTIONAL, + IN DWORD dwFlags OPTIONAL, + IN BOOL bShowDevMgr); -int +INT_PTR WINAPI -DevicePropertiesExW(HWND hWndParent, - LPCWSTR lpMachineName, - LPCWSTR lpDeviceID, - HINSTANCE hInst, - DWORD Unknown); +DevicePropertiesExW(IN HWND hWndParent OPTIONAL, + IN LPCWSTR lpMachineName OPTIONAL, + IN LPCWSTR lpDeviceID OPTIONAL, + IN DWORD dwFlags OPTIONAL, + IN BOOL bShowDevMgr); #ifdef UNICODE #define DeviceManager_Execute DeviceManager_ExecuteW @@ -188,7 +197,8 @@ DisplayDeviceAdvancedProperties(IN HWND hWndParent, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData, IN HINSTANCE hComCtl32, - IN LPCWSTR lpMachineName); + IN LPCWSTR lpMachineName, + IN DWORD dwFlags); /* MISC.C */ diff --git a/reactos/lib/devmgr/stubs.c b/reactos/lib/devmgr/stubs.c index ffa37dca954..00f064a002f 100644 --- a/reactos/lib/devmgr/stubs.c +++ b/reactos/lib/devmgr/stubs.c @@ -544,79 +544,3 @@ DeviceManagerPrintW(LPCWSTR lpMachineName, UNIMPLEMENTED; return FALSE; } - - -/*************************************************************************** - * NAME EXPORTED - * DevicePropertiesExA - * - * DESCRIPTION - * Invokes the extended device properties dialog - * - * ARGUMENTS - * hWndParent: Handle to the parent window - * hInst: Handle to the application instance - * lpMachineName: Machine Name, NULL is the local machine - * lpDeviceID: Specifies the device whose properties are to be shown - * Unknown: Unknown parameter, see NOTEs - * - * RETURN VALUE - * >=0: if no errors occured - * -1: if errors occured - * - * REVISIONS - * - * NOTE - * Unknown seems to be a BOOL, not sure what it affects - * - * @unimplemented - */ -int -WINAPI -DevicePropertiesExA(HWND hWndParent, - LPCSTR lpMachineName, - LPCSTR lpDeviceID, - HINSTANCE hInst, - DWORD Unknown) -{ - UNIMPLEMENTED; - return -1; -} - - -/*************************************************************************** - * NAME EXPORTED - * DevicePropertiesExW - * - * DESCRIPTION - * Invokes the extended device properties dialog - * - * ARGUMENTS - * hWndParent: Handle to the parent window - * hInst: Handle to the application instance - * lpMachineName: Machine Name, NULL is the local machine - * lpDeviceID: Specifies the device whose properties are to be shown - * Unknown: Unknown parameter, see NOTEs - * - * RETURN VALUE - * >=0: if no errors occured - * -1: if errors occured - * - * REVISIONS - * - * NOTE - * Unknown seems to be a BOOL, not sure what it affects - * - * @unimplemented - */ -int -WINAPI -DevicePropertiesExW(HWND hWndParent, - LPCWSTR lpMachineName, - LPCWSTR lpDeviceID, - HINSTANCE hInst, - DWORD Unknown) -{ - UNIMPLEMENTED; - return -1; -} -- 2.17.1