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 <devmgr/devmgr.h>
21 #include "devmgmt/MainWindow.h"
22 #include "properties/properties.h"
24 HINSTANCE hDllInstance
= NULL
;
28 /***************************************************************************
30 * DeviceAdvancedPropertiesW
33 * Invokes the device properties dialog, this version may add some property pages
37 * hWndParent: Handle to the parent window
38 * lpMachineName: Machine Name, NULL is the local machine
39 * lpDeviceID: Specifies the device whose properties are to be shown
42 * Always returns -1, a call to GetLastError returns 0 if successful
48 DeviceAdvancedPropertiesW(IN HWND hWndParent OPTIONAL
,
49 IN LPCWSTR lpMachineName OPTIONAL
,
50 IN LPCWSTR lpDeviceID
)
53 SP_DEVINFO_DATA DevInfoData
;
57 if (lpDeviceID
== NULL
)
59 SetLastError(ERROR_INVALID_PARAMETER
);
63 /* dynamically load comctl32 */
64 hComCtl32
= LoadAndInitComctl32();
65 if (hComCtl32
!= NULL
)
67 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
71 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
73 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
74 if (SetupDiOpenDeviceInfo(hDevInfo
,
80 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
89 SetupDiDestroyDeviceInfoList(hDevInfo
);
92 FreeLibrary(hComCtl32
);
99 /***************************************************************************
101 * DeviceAdvancedPropertiesA
104 * Invokes the device properties dialog, this version may add some property pages
108 * hWndParent: Handle to the parent window
109 * lpMachineName: Machine Name, NULL is the local machine
110 * lpDeviceID: Specifies the device whose properties are to be shown
113 * Always returns -1, a call to GetLastError returns 0 if successful
119 DeviceAdvancedPropertiesA(IN HWND hWndParent OPTIONAL
,
120 IN LPCSTR lpMachineName OPTIONAL
,
121 IN LPCSTR lpDeviceID
)
123 LPWSTR lpMachineNameW
= NULL
;
124 LPWSTR lpDeviceIDW
= NULL
;
127 if (lpMachineName
!= NULL
)
129 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
135 if (lpDeviceID
!= NULL
)
137 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
144 Ret
= DeviceAdvancedPropertiesW(hWndParent
,
149 if (lpMachineNameW
!= NULL
)
151 HeapFree(GetProcessHeap(),
155 if (lpDeviceIDW
!= NULL
)
157 HeapFree(GetProcessHeap(),
166 /***************************************************************************
168 * DevicePropertiesExA
171 * Invokes the extended device properties dialog
174 * hWndParent: Handle to the parent window
175 * lpMachineName: Machine Name, NULL is the local machine
176 * lpDeviceID: Specifies the device whose properties are to be shown, optional if
177 * bShowDevMgr is nonzero
178 * dwFlags: This parameter can be a combination of the following flags:
179 * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
180 * the default device status action button
181 * to be clicked (Troubleshoot, Enable
183 * bShowDevMgr: If non-zero it displays the device manager instead of
184 * the advanced device property dialog
187 * 1: if bShowDevMgr is non-zero and no error occured
188 * -1: a call to GetLastError returns 0 if successful
194 DevicePropertiesExA(IN HWND hWndParent OPTIONAL
,
195 IN LPCSTR lpMachineName OPTIONAL
,
196 IN LPCSTR lpDeviceID OPTIONAL
,
197 IN DWORD dwFlags OPTIONAL
,
200 LPWSTR lpMachineNameW
= NULL
;
201 LPWSTR lpDeviceIDW
= NULL
;
204 if (lpMachineName
!= NULL
)
206 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
212 if (lpDeviceID
!= NULL
)
214 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
221 Ret
= DevicePropertiesExW(hWndParent
,
228 if (lpMachineNameW
!= NULL
)
230 HeapFree(GetProcessHeap(),
234 if (lpDeviceIDW
!= NULL
)
236 HeapFree(GetProcessHeap(),
245 /***************************************************************************
247 * DevicePropertiesExW
250 * Invokes the extended device properties dialog
253 * hWndParent: Handle to the parent window
254 * lpMachineName: Machine Name, NULL is the local machine
255 * lpDeviceID: Specifies the device whose properties are to be shown, optional if
256 * bShowDevMgr is nonzero
257 * dwFlags: This parameter can be a combination of the following flags:
258 * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
259 * the default device status action button
260 * to be clicked (Troubleshoot, Enable
262 * bShowDevMgr: If non-zero it displays the device manager instead of
263 * the advanced device property dialog
266 * 1: if bShowDevMgr is non-zero and no error occured
267 * -1: a call to GetLastError returns 0 if successful
273 DevicePropertiesExW(IN HWND hWndParent OPTIONAL
,
274 IN LPCWSTR lpMachineName OPTIONAL
,
275 IN LPCWSTR lpDeviceID OPTIONAL
,
276 IN DWORD dwFlags OPTIONAL
,
281 if (dwFlags
& ~(DPF_EXTENDED
| DPF_DEVICE_STATUS_ACTION
))
283 FIXME("DevPropertiesExW: Invalid flags: 0x%x\n",
284 dwFlags
& ~(DPF_EXTENDED
| DPF_DEVICE_STATUS_ACTION
));
285 SetLastError(ERROR_INVALID_FLAGS
);
291 FIXME("DevPropertiesExW doesn't support bShowDevMgr!\n");
292 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
297 SP_DEVINFO_DATA DevInfoData
;
300 if (lpDeviceID
== NULL
)
302 SetLastError(ERROR_INVALID_PARAMETER
);
306 /* dynamically load comctl32 */
307 hComCtl32
= LoadAndInitComctl32();
308 if (hComCtl32
!= NULL
)
310 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
314 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
316 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
317 if (SetupDiOpenDeviceInfo(hDevInfo
,
323 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
332 SetupDiDestroyDeviceInfoList(hDevInfo
);
335 FreeLibrary(hComCtl32
);
343 /***************************************************************************
348 * Invokes the device properties dialog directly
351 * hWndParent: Handle to the parent window
352 * lpMachineName: Machine Name, NULL is the local machine
353 * lpDeviceID: Specifies the device whose properties are to be shown
354 * bShowDevMgr: If non-zero it displays the device manager instead of
355 * the device property dialog
358 * >=0: if no errors occured
359 * -1: if errors occured
367 DevicePropertiesA(HWND hWndParent
,
368 LPCSTR lpMachineName
,
372 return DevicePropertiesExA(hWndParent
,
380 /***************************************************************************
385 * Invokes the device properties dialog directly
388 * hWndParent: Handle to the parent window
389 * lpMachineName: Machine Name, NULL is the local machine
390 * lpDeviceID: Specifies the device whose properties are to be shown
391 * bShowDevMgr: If non-zero it displays the device manager instead of
392 * the device property dialog
395 * >=0: if no errors occured
396 * -1: if errors occured
404 DevicePropertiesW(HWND hWndParent
,
405 LPCWSTR lpMachineName
,
409 return DevicePropertiesExW(hWndParent
,
417 /***************************************************************************
419 * DeviceProperties_RunDLLA
422 * Invokes the device properties dialog
425 * hWndParent: Handle to the parent window
426 * hInst: Handle to the application instance
427 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
429 * nCmdShow: Specifies how the window should be shown
436 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
437 * (/MachineName is optional). This function only parses this string and eventually
438 * calls DeviceProperties().
444 DeviceProperties_RunDLLA(HWND hWndParent
,
449 LPWSTR lpDeviceCmdW
= NULL
;
451 if (lpDeviceCmd
!= NULL
)
453 if ((lpDeviceCmdW
= ConvertMultiByteToUnicode(lpDeviceCmd
,
456 DeviceProperties_RunDLLW(hWndParent
,
463 if (lpDeviceCmdW
!= NULL
)
465 HeapFree(GetProcessHeap(),
472 /***************************************************************************
474 * DeviceProperties_RunDLLW
477 * Invokes the device properties dialog
480 * hWndParent: Handle to the parent window
481 * hInst: Handle to the application instance
482 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
484 * nCmdShow: Specifies how the window should be shown
491 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
492 * (/MachineName is optional). This function only parses this string and eventually
493 * calls DeviceProperties().
499 DeviceProperties_RunDLLW(HWND hWndParent
,
504 WCHAR szDeviceID
[MAX_DEVICE_ID_LEN
+ 1];
505 WCHAR szMachineName
[MAX_COMPUTERNAME_LENGTH
+ 1];
506 LPWSTR lpString
= (LPWSTR
)lpDeviceCmd
;
508 if (!GetDeviceAndComputerName(lpString
,
512 ERR("DeviceProperties_RunDLLW DeviceID: %S, MachineName: %S\n", szDeviceID
, szMachineName
);
516 DevicePropertiesW(hWndParent
,
524 /***************************************************************************
526 * DeviceManager_ExecuteA
529 * Starts the Device Manager
532 * hWndParent: Handle to the parent window
533 * hInst: Handle to the application instance
534 * lpMachineName: Machine Name, NULL is the local machine
535 * nCmdShow: Specifies how the window should be shown
538 * TRUE: if no errors occured
539 * FALSE: if the device manager could not be executed
544 * - Win runs the device manager in a separate process, so hWndParent is somehow
551 DeviceManager_ExecuteA(HWND hWndParent
,
553 LPCSTR lpMachineName
,
556 LPWSTR lpMachineNameW
= NULL
;
559 if (lpMachineName
!= NULL
)
561 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
568 Ret
= DeviceManager_ExecuteW(hWndParent
,
573 if (lpMachineNameW
!= NULL
)
575 HeapFree(GetProcessHeap(),
585 /***************************************************************************
587 * DeviceManager_ExecuteW
590 * Starts the Device Manager
593 * hWndParent: Handle to the parent window
594 * hInst: Handle to the application instance
595 * lpMachineName: Machine Name, NULL is the local machine
596 * nCmdShow: Specifies how the window should be shown
599 * TRUE: if no errors occured
600 * FALSE: if the device manager could not be executed
605 * - Win runs the device manager in a separate process, so hWndParent is somehow
612 DeviceManager_ExecuteW(HWND hWndParent
,
614 LPCWSTR lpMachineName
,
617 // FIXME: Call mmc with devmgmt.msc
619 CDeviceManager DevMgr
;
620 return DevMgr
.Create(hWndParent
, hInst
, lpMachineName
, nCmdShow
);
624 /***************************************************************************
626 * DeviceProblemWizard_RunDLLA
629 * Calls the device problem wizard
632 * hWndParent: Handle to the parent window
633 * hInst: Handle to the application instance
634 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
636 * nCmdShow: Specifies how the window should be shown
643 * - Win XP exports this function as DeviceProblenWizard_RunDLLA, apparently it's
644 * a typo so we additionally export an alias function
645 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
646 * (/MachineName is optional). This function only parses this string and eventually
647 * calls DeviceProperties().
653 DeviceProblemWizard_RunDLLA(HWND hWndParent
,
662 /***************************************************************************
664 * DeviceProblemWizard_RunDLLW
667 * Calls the device problem wizard
670 * hWndParent: Handle to the parent window
671 * hInst: Handle to the application instance
672 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
674 * nCmdShow: Specifies how the window should be shown
681 * - Win XP exports this function as DeviceProblenWizard_RunDLLA, apparently it's
682 * a typo so we additionally export an alias function
683 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
684 * (/MachineName is optional). This function only parses this string and eventually
685 * calls DeviceProperties().
691 DeviceProblemWizard_RunDLLW(HWND hWndParent
,
700 /***************************************************************************
702 * DeviceManagerPrintA
705 * Calls the device problem wizard
708 * lpMachineName: Machine Name, NULL is the local machine
709 * lpPrinter: Filename of the printer where it should be printed on
710 * nPrintMode: Specifies what kind of information is to be printed
711 * DEV_PRINT_ABSTRACT: Prints an abstract of system information, the parameters
712 * uNumberOfGuids, Guids are ignored
713 * DEV_PRINT_SELECTED: Prints information about the devices listed in Guids
714 * DEV_PRINT_ALL: Prints an abstract of system information and all
716 * uNumberOfGuids: Numbers of guids in the Guids array, this parameter is ignored unless
717 * nPrintMode is DEV_PRINT_SELECTED
718 * lpGuids: Array of device guids, this parameter is ignored unless
719 * nPrintMode is DEV_PRINT_SELECTED
722 * TRUE: if no errors occured
723 * FALSE: if errors occured
733 DeviceManagerPrintA(LPCSTR lpMachineName
,
744 /***************************************************************************
746 * DeviceManagerPrintW
749 * Calls the device problem wizard
752 * lpMachineName: Machine Name, NULL is the local machine
753 * lpPrinter: Filename of the printer where it should be printed on
754 * nPrintMode: Specifies what kind of information is to be printed
755 * DEV_PRINT_ABSTRACT: Prints an abstract of system information, the parameters
756 * uNumberOfGuids, Guids are ignored
757 * DEV_PRINT_SELECTED: Prints information about the devices listed in Guids
758 * DEV_PRINT_ALL: Prints an abstract of system information and all
760 * uNumberOfGuids: Numbers of guids in the Guids array, this parameter is ignored unless
761 * nPrintMode is DEV_PRINT_SELECTED
762 * lpGuids: Array of device guids, this parameter is ignored unless
763 * nPrintMode is DEV_PRINT_SELECTED
766 * TRUE: if no errors occured
767 * FALSE: if errors occured
777 DeviceManagerPrintW(LPCWSTR lpMachineName
,
790 DllMain(IN HINSTANCE hinstDLL
,
792 IN LPVOID lpvReserved
)
796 case DLL_PROCESS_ATTACH
:
797 DisableThreadLibraryCalls(hinstDLL
);
798 hDllInstance
= hinstDLL
;
805 class CDevMgrUIModule
: public CComModule
810 CDevMgrUIModule gModule
;
812 STDAPI
DllCanUnloadNow()
814 return gModule
.DllCanUnloadNow();
817 STDAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
819 return gModule
.DllGetClassObject(rclsid
, riid
, ppv
);
822 STDAPI
DllRegisterServer()
824 return gModule
.DllRegisterServer(FALSE
);
827 STDAPI
DllUnregisterServer()
829 return gModule
.DllUnregisterServer(FALSE
);