3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS devmgr.dll
5 * FILE: dll/win32/devmgr/api.cpp
6 * PURPOSE: devmgr.dll interface
7 * PROGRAMMER: Thomas Weidenmueller (w3seek@users.sourceforge.net)
8 * Ged Murphy (gedmurphy@reactos.org)
10 * Some helpful resources:
11 * http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;815320
12 * http://www.jsiinc.com/SUBO/tip7400/rh7482.htm
13 * http://www.jsiinc.com/SUBM/tip6400/rh6490.htm
20 #include "devmgmt/MainWindow.h"
21 #include "properties/properties.h"
23 HINSTANCE hDllInstance
= NULL
;
27 /***************************************************************************
29 * DeviceAdvancedPropertiesW
32 * Invokes the device properties dialog, this version may add some property pages
36 * hWndParent: Handle to the parent window
37 * lpMachineName: Machine Name, NULL is the local machine
38 * lpDeviceID: Specifies the device whose properties are to be shown
41 * Always returns -1, a call to GetLastError returns 0 if successful
47 DeviceAdvancedPropertiesW(IN HWND hWndParent OPTIONAL
,
48 IN LPCWSTR lpMachineName OPTIONAL
,
49 IN LPCWSTR lpDeviceID
)
52 SP_DEVINFO_DATA DevInfoData
;
56 if (lpDeviceID
== NULL
)
58 SetLastError(ERROR_INVALID_PARAMETER
);
62 /* dynamically load comctl32 */
63 hComCtl32
= LoadAndInitComctl32();
64 if (hComCtl32
!= NULL
)
66 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
70 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
72 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
73 if (SetupDiOpenDeviceInfo(hDevInfo
,
79 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
88 SetupDiDestroyDeviceInfoList(hDevInfo
);
91 FreeLibrary(hComCtl32
);
98 /***************************************************************************
100 * DeviceAdvancedPropertiesA
103 * Invokes the device properties dialog, this version may add some property pages
107 * hWndParent: Handle to the parent window
108 * lpMachineName: Machine Name, NULL is the local machine
109 * lpDeviceID: Specifies the device whose properties are to be shown
112 * Always returns -1, a call to GetLastError returns 0 if successful
118 DeviceAdvancedPropertiesA(IN HWND hWndParent OPTIONAL
,
119 IN LPCSTR lpMachineName OPTIONAL
,
120 IN LPCSTR lpDeviceID
)
122 LPWSTR lpMachineNameW
= NULL
;
123 LPWSTR lpDeviceIDW
= NULL
;
126 if (lpMachineName
!= NULL
)
128 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
134 if (lpDeviceID
!= NULL
)
136 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
143 Ret
= DeviceAdvancedPropertiesW(hWndParent
,
148 if (lpMachineNameW
!= NULL
)
150 HeapFree(GetProcessHeap(),
154 if (lpDeviceIDW
!= NULL
)
156 HeapFree(GetProcessHeap(),
165 /***************************************************************************
167 * DevicePropertiesExA
170 * Invokes the extended device properties dialog
173 * hWndParent: Handle to the parent window
174 * lpMachineName: Machine Name, NULL is the local machine
175 * lpDeviceID: Specifies the device whose properties are to be shown, optional if
176 * bShowDevMgr is nonzero
177 * dwFlags: This parameter can be a combination of the following flags:
178 * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
179 * the default device status action button
180 * to be clicked (Troubleshoot, Enable
182 * bShowDevMgr: If non-zero it displays the device manager instead of
183 * the advanced device property dialog
186 * 1: if bShowDevMgr is non-zero and no error occured
187 * -1: a call to GetLastError returns 0 if successful
193 DevicePropertiesExA(IN HWND hWndParent OPTIONAL
,
194 IN LPCSTR lpMachineName OPTIONAL
,
195 IN LPCSTR lpDeviceID OPTIONAL
,
196 IN DWORD dwFlags OPTIONAL
,
199 LPWSTR lpMachineNameW
= NULL
;
200 LPWSTR lpDeviceIDW
= NULL
;
203 if (lpMachineName
!= NULL
)
205 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
211 if (lpDeviceID
!= NULL
)
213 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
220 Ret
= DevicePropertiesExW(hWndParent
,
227 if (lpMachineNameW
!= NULL
)
229 HeapFree(GetProcessHeap(),
233 if (lpDeviceIDW
!= NULL
)
235 HeapFree(GetProcessHeap(),
244 /***************************************************************************
246 * DevicePropertiesExW
249 * Invokes the extended device properties dialog
252 * hWndParent: Handle to the parent window
253 * lpMachineName: Machine Name, NULL is the local machine
254 * lpDeviceID: Specifies the device whose properties are to be shown, optional if
255 * bShowDevMgr is nonzero
256 * dwFlags: This parameter can be a combination of the following flags:
257 * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
258 * the default device status action button
259 * to be clicked (Troubleshoot, Enable
261 * bShowDevMgr: If non-zero it displays the device manager instead of
262 * the advanced device property dialog
265 * 1: if bShowDevMgr is non-zero and no error occured
266 * -1: a call to GetLastError returns 0 if successful
272 DevicePropertiesExW(IN HWND hWndParent OPTIONAL
,
273 IN LPCWSTR lpMachineName OPTIONAL
,
274 IN LPCWSTR lpDeviceID OPTIONAL
,
275 IN DWORD dwFlags OPTIONAL
,
280 if (dwFlags
& ~(DPF_EXTENDED
| DPF_DEVICE_STATUS_ACTION
))
282 FIXME("DevPropertiesExW: Invalid flags: 0x%x\n",
283 dwFlags
& ~(DPF_EXTENDED
| DPF_DEVICE_STATUS_ACTION
));
284 SetLastError(ERROR_INVALID_FLAGS
);
290 FIXME("DevPropertiesExW doesn't support bShowDevMgr!\n");
291 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
296 SP_DEVINFO_DATA DevInfoData
;
299 if (lpDeviceID
== NULL
)
301 SetLastError(ERROR_INVALID_PARAMETER
);
305 /* dynamically load comctl32 */
306 hComCtl32
= LoadAndInitComctl32();
307 if (hComCtl32
!= NULL
)
309 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
313 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
315 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
316 if (SetupDiOpenDeviceInfo(hDevInfo
,
322 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
331 SetupDiDestroyDeviceInfoList(hDevInfo
);
334 FreeLibrary(hComCtl32
);
342 /***************************************************************************
347 * Invokes the device properties dialog directly
350 * hWndParent: Handle to the parent window
351 * lpMachineName: Machine Name, NULL is the local machine
352 * lpDeviceID: Specifies the device whose properties are to be shown
353 * bShowDevMgr: If non-zero it displays the device manager instead of
354 * the device property dialog
357 * >=0: if no errors occured
358 * -1: if errors occured
366 DevicePropertiesA(HWND hWndParent
,
367 LPCSTR lpMachineName
,
371 return DevicePropertiesExA(hWndParent
,
379 /***************************************************************************
384 * Invokes the device properties dialog directly
387 * hWndParent: Handle to the parent window
388 * lpMachineName: Machine Name, NULL is the local machine
389 * lpDeviceID: Specifies the device whose properties are to be shown
390 * bShowDevMgr: If non-zero it displays the device manager instead of
391 * the device property dialog
394 * >=0: if no errors occured
395 * -1: if errors occured
403 DevicePropertiesW(HWND hWndParent
,
404 LPCWSTR lpMachineName
,
408 return DevicePropertiesExW(hWndParent
,
416 /***************************************************************************
418 * DeviceProperties_RunDLLA
421 * Invokes the device properties dialog
424 * hWndParent: Handle to the parent window
425 * hInst: Handle to the application instance
426 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
428 * nCmdShow: Specifies how the window should be shown
435 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
436 * (/MachineName is optional). This function only parses this string and eventually
437 * calls DeviceProperties().
443 DeviceProperties_RunDLLA(HWND hWndParent
,
448 LPWSTR lpDeviceCmdW
= NULL
;
450 if (lpDeviceCmd
!= NULL
)
452 if ((lpDeviceCmdW
= ConvertMultiByteToUnicode(lpDeviceCmd
,
455 DeviceProperties_RunDLLW(hWndParent
,
462 if (lpDeviceCmdW
!= NULL
)
464 HeapFree(GetProcessHeap(),
471 /***************************************************************************
473 * DeviceProperties_RunDLLW
476 * Invokes the device properties dialog
479 * hWndParent: Handle to the parent window
480 * hInst: Handle to the application instance
481 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
483 * nCmdShow: Specifies how the window should be shown
490 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
491 * (/MachineName is optional). This function only parses this string and eventually
492 * calls DeviceProperties().
498 DeviceProperties_RunDLLW(HWND hWndParent
,
503 WCHAR szDeviceID
[MAX_DEVICE_ID_LEN
+ 1];
504 WCHAR szMachineName
[MAX_COMPUTERNAME_LENGTH
+ 1];
505 LPWSTR lpString
= (LPWSTR
)lpDeviceCmd
;
507 if (!GetDeviceAndComputerName(lpString
,
511 ERR("DeviceProperties_RunDLLW DeviceID: %S, MachineName: %S\n", szDeviceID
, szMachineName
);
515 DevicePropertiesW(hWndParent
,
523 /***************************************************************************
525 * DeviceManager_ExecuteA
528 * Starts the Device Manager
531 * hWndParent: Handle to the parent window
532 * hInst: Handle to the application instance
533 * lpMachineName: Machine Name, NULL is the local machine
534 * nCmdShow: Specifies how the window should be shown
537 * TRUE: if no errors occured
538 * FALSE: if the device manager could not be executed
543 * - Win runs the device manager in a separate process, so hWndParent is somehow
550 DeviceManager_ExecuteA(HWND hWndParent
,
552 LPCSTR lpMachineName
,
555 LPWSTR lpMachineNameW
= NULL
;
558 if (lpMachineName
!= NULL
)
560 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
567 Ret
= DeviceManager_ExecuteW(hWndParent
,
572 if (lpMachineNameW
!= NULL
)
574 HeapFree(GetProcessHeap(),
584 /***************************************************************************
586 * DeviceManager_ExecuteW
589 * Starts the Device Manager
592 * hWndParent: Handle to the parent window
593 * hInst: Handle to the application instance
594 * lpMachineName: Machine Name, NULL is the local machine
595 * nCmdShow: Specifies how the window should be shown
598 * TRUE: if no errors occured
599 * FALSE: if the device manager could not be executed
604 * - Win runs the device manager in a separate process, so hWndParent is somehow
611 DeviceManager_ExecuteW(HWND hWndParent
,
613 LPCWSTR lpMachineName
,
616 // FIXME: Call mmc with devmgmt.msc
618 CDeviceManager DevMgr
;
619 return DevMgr
.Create(hWndParent
, hInst
, lpMachineName
, nCmdShow
);
623 /***************************************************************************
625 * DeviceProblemWizard_RunDLLA
628 * Calls the device problem wizard
631 * hWndParent: Handle to the parent window
632 * hInst: Handle to the application instance
633 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
635 * nCmdShow: Specifies how the window should be shown
642 * - Win XP exports this function as DeviceProblenWizard_RunDLLA, apparently it's
643 * a typo so we additionally export an alias function
644 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
645 * (/MachineName is optional). This function only parses this string and eventually
646 * calls DeviceProperties().
652 DeviceProblemWizard_RunDLLA(HWND hWndParent
,
661 /***************************************************************************
663 * DeviceProblemWizard_RunDLLW
666 * Calls the device problem wizard
669 * hWndParent: Handle to the parent window
670 * hInst: Handle to the application instance
671 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
673 * nCmdShow: Specifies how the window should be shown
680 * - Win XP exports this function as DeviceProblenWizard_RunDLLA, apparently it's
681 * a typo so we additionally export an alias function
682 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
683 * (/MachineName is optional). This function only parses this string and eventually
684 * calls DeviceProperties().
690 DeviceProblemWizard_RunDLLW(HWND hWndParent
,
699 /***************************************************************************
701 * DeviceManagerPrintA
704 * Calls the device problem wizard
707 * lpMachineName: Machine Name, NULL is the local machine
708 * lpPrinter: Filename of the printer where it should be printed on
709 * nPrintMode: Specifies what kind of information is to be printed
710 * DEV_PRINT_ABSTRACT: Prints an abstract of system information, the parameters
711 * uNumberOfGuids, Guids are ignored
712 * DEV_PRINT_SELECTED: Prints information about the devices listed in Guids
713 * DEV_PRINT_ALL: Prints an abstract of system information and all
715 * uNumberOfGuids: Numbers of guids in the Guids array, this parameter is ignored unless
716 * nPrintMode is DEV_PRINT_SELECTED
717 * lpGuids: Array of device guids, this parameter is ignored unless
718 * nPrintMode is DEV_PRINT_SELECTED
721 * TRUE: if no errors occured
722 * FALSE: if errors occured
732 DeviceManagerPrintA(LPCSTR lpMachineName
,
743 /***************************************************************************
745 * DeviceManagerPrintW
748 * Calls the device problem wizard
751 * lpMachineName: Machine Name, NULL is the local machine
752 * lpPrinter: Filename of the printer where it should be printed on
753 * nPrintMode: Specifies what kind of information is to be printed
754 * DEV_PRINT_ABSTRACT: Prints an abstract of system information, the parameters
755 * uNumberOfGuids, Guids are ignored
756 * DEV_PRINT_SELECTED: Prints information about the devices listed in Guids
757 * DEV_PRINT_ALL: Prints an abstract of system information and all
759 * uNumberOfGuids: Numbers of guids in the Guids array, this parameter is ignored unless
760 * nPrintMode is DEV_PRINT_SELECTED
761 * lpGuids: Array of device guids, this parameter is ignored unless
762 * nPrintMode is DEV_PRINT_SELECTED
765 * TRUE: if no errors occured
766 * FALSE: if errors occured
776 DeviceManagerPrintW(LPCWSTR lpMachineName
,
786 class CDevMgrUIModule
: public CComModule
791 CDevMgrUIModule gModule
;
793 STDAPI
DllCanUnloadNow()
795 return gModule
.DllCanUnloadNow();
798 STDAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
800 return gModule
.DllGetClassObject(rclsid
, riid
, ppv
);
803 STDAPI
DllRegisterServer()
805 return gModule
.DllRegisterServer(FALSE
);
808 STDAPI
DllUnregisterServer()
810 return gModule
.DllUnregisterServer(FALSE
);
817 DllMain(_In_ HINSTANCE hinstDLL
,
819 _In_ LPVOID lpvReserved
)
823 case DLL_PROCESS_ATTACH
:
824 DisableThreadLibraryCalls(hinstDLL
);
825 hDllInstance
= hinstDLL
;