2 * ReactOS Device Manager Applet
3 * Copyright (C) 2004 - 2005 ReactOS Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /* $Id: devmgr.c 12852 2005-01-06 13:58:04Z mf $
21 * PROJECT: ReactOS devmgr.dll
22 * FILE: lib/devmgr/misc.c
23 * PURPOSE: ReactOS Device Manager
24 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
30 HINSTANCE hDllInstance
= NULL
;
34 LengthOfStrResource(IN HINSTANCE hInst
,
46 /* There are always blocks of 16 strings */
47 lpName
= (LPWSTR
)MAKEINTRESOURCE((uID
>> 4) + 1);
49 /* Find the string table block */
50 if ((hrSrc
= FindResourceW(hInst
, lpName
, (LPWSTR
)RT_STRING
)) &&
51 (hRes
= LoadResource(hInst
, hrSrc
)) &&
52 (lpStr
= LockResource(hRes
)))
56 /* Find the string we're looking for */
57 uID
&= 0xF; /* position in the block, same as % 16 */
58 for (x
= 0; x
< uID
; x
++)
60 lpStr
+= (*lpStr
) + 1;
63 /* Found the string */
71 AllocAndLoadString(OUT LPWSTR
*lpTarget
,
77 ln
= LengthOfStrResource(hInst
,
81 (*lpTarget
) = (LPWSTR
)LocalAlloc(LMEM_FIXED
,
83 if ((*lpTarget
) != NULL
)
86 if (!(Ret
= LoadStringW(hInst
, uID
, *lpTarget
, ln
)))
88 LocalFree((HLOCAL
)(*lpTarget
));
98 AllocAndLoadStringsCat(OUT LPWSTR
*lpTarget
,
105 ln
= LengthOfStrResource(hInst
,
107 ln
+= LengthOfStrResource(hInst
,
111 (*lpTarget
) = (LPWSTR
)LocalAlloc(LMEM_FIXED
,
113 if ((*lpTarget
) != NULL
)
116 if (!(Ret
= LoadStringW(hInst
, uID1
, *lpTarget
, ln
)))
118 LocalFree((HLOCAL
)(*lpTarget
));
120 else if (!(Ret2
= LoadStringW(hInst
, uID2
, *lpTarget
+ Ret
, ln
- Ret
)))
122 LocalFree((HLOCAL
)(*lpTarget
));
133 LoadAndFormatString(IN HINSTANCE hInstance
,
135 OUT LPWSTR
*lpTarget
,
142 if (AllocAndLoadString(&lpFormat
,
146 va_start(lArgs
, lpTarget
);
147 /* let's use FormatMessage to format it because it has the ability to allocate
148 memory automatically */
149 Ret
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
158 LocalFree((HLOCAL
)lpFormat
);
166 LoadAndFormatStringsCat(IN HINSTANCE hInstance
,
169 OUT LPWSTR
*lpTarget
,
176 if (AllocAndLoadStringsCat(&lpFormat
,
181 va_start(lArgs
, lpTarget
);
182 /* let's use FormatMessage to format it because it has the ability to allocate
183 memory automatically */
184 Ret
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
193 LocalFree((HLOCAL
)lpFormat
);
201 ListViewGetSelectedItemData(IN HWND hwnd
)
205 Index
= ListView_GetNextItem(hwnd
,
212 li
.mask
= LVIF_PARAM
;
216 if (ListView_GetItem(hwnd
,
228 ConvertMultiByteToUnicode(IN LPCSTR lpMultiByteStr
,
234 nLength
= MultiByteToWideChar(uCodePage
,
243 lpUnicodeStr
= HeapAlloc(GetProcessHeap(),
245 nLength
* sizeof(WCHAR
));
246 if (lpUnicodeStr
== NULL
)
249 if (!MultiByteToWideChar(uCodePage
,
256 HeapFree(GetProcessHeap(),
267 GetDeviceManufacturerString(IN HDEVINFO DeviceInfoSet
,
268 IN PSP_DEVINFO_DATA DeviceInfoData
,
275 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
280 BufferSize
* sizeof(WCHAR
),
282 RegDataType
!= REG_SZ
)
285 if (LoadString(hDllInstance
,
295 /* FIXME - check string for NULL termination! */
304 GetDeviceLocationString(IN DEVINST dnDevInst
,
313 DataSize
= BufferSize
* sizeof(WCHAR
);
314 cRet
= CM_Get_DevNode_Registry_Property(dnDevInst
,
315 CM_DRP_LOCATION_INFORMATION
,
320 if (cRet
!= CR_SUCCESS
||
321 RegDataType
!= REG_SZ
)
324 if (LoadString(hDllInstance
,
334 /* FIXME - check string for NULL termination! */
338 if (szBuffer
[0] >= L
'0' && szBuffer
[0] <= L
'9')
340 /* convert the string to an integer value and create a
343 ULONG ulLocation
= (ULONG
)wcstoul(szBuffer
,
346 if (LoadAndFormatString(hDllInstance
,
355 szBuffer
[BufferSize
- 1] = L
'\0';
356 LocalFree((HLOCAL
)szFormatted
);
366 static const UINT ProblemStringId
[] =
369 IDS_DEV_NOT_CONFIGURED
,
370 IDS_DEV_OUT_OF_MEMORY
,
371 IDS_DEV_ENTRY_IS_WRONG_TYPE
,
372 IDS_DEV_LACKED_ARBITRATOR
,
373 IDS_DEV_BOOT_CONFIG_CONFLICT
,
374 IDS_DEV_FAILED_FILTER
,
375 IDS_DEV_DEVLOADER_NOT_FOUND
,
376 IDS_DEV_INVALID_DATA
,
377 IDS_DEV_FAILED_START
,
379 IDS_DEV_NORMAL_CONFLICT
,
380 IDS_DEV_NOT_VERIFIED
,
381 IDS_DEV_NEED_RESTART
,
382 IDS_DEV_REENUMERATION
,
383 IDS_DEV_PARTIAL_LOG_CONF
,
384 IDS_DEV_UNKNOWN_RESOURCE
,
387 IDS_UNKNOWN
, /* CM_PROB_VXDLDR, not used on NT */
388 IDS_DEV_WILL_BE_REMOVED
,
390 IDS_DEV_DEVLOADER_NOT_READY
,
391 IDS_DEV_DEVICE_NOT_THERE
,
394 IDS_DEV_NO_VALID_LOG_CONF
,
395 IDS_DEV_FAILED_INSTALL
,
396 IDS_DEV_HARDWARE_DISABLED
,
397 IDS_DEV_CANT_SHARE_IRQ
,
399 IDS_DEV_DISABLED_SERVICE
,
400 IDS_DEV_TRANSLATION_FAILED
,
401 IDS_DEV_NO_SOFTCONFIG
,
403 IDS_DEV_IRQ_TRANSLATION_FAILED
,
404 IDS_DEV_FAILED_DRIVER_ENTRY
,
405 IDS_DEV_DRIVER_FAILED_PRIOR_UNLOAD
,
406 IDS_DEV_DRIVER_FAILED_LOAD
,
407 IDS_DEV_DRIVER_SERVICE_KEY_INVALID
,
408 IDS_DEV_LEGACY_SERVICE_NO_DEVICES
,
409 IDS_DEV_DUPLICATE_DEVICE
,
410 IDS_DEV_FAILED_POST_START
,
413 IDS_DEV_SYSTEM_SHUTDOWN
,
414 IDS_DEV_HELD_FOR_EJECT
,
415 IDS_DEV_DRIVER_BLOCKED
,
416 IDS_DEV_REGISTRY_TOO_LARGE
,
417 IDS_DEV_SETPROPERTIES_FAILED
,
422 GetDeviceStatusString(IN DEVINST DevInst
,
428 ULONG Status
, ProblemNumber
;
431 if (hMachine
!= NULL
)
433 cr
= CM_Get_DevNode_Status_Ex(&Status
,
441 cr
= CM_Get_DevNode_Status(&Status
,
447 if (cr
== CR_SUCCESS
)
451 if (ProblemNumber
< sizeof(ProblemStringId
) / sizeof(ProblemStringId
[0]))
452 MessageId
= ProblemStringId
[ProblemNumber
];
454 MessageId
= IDS_UNKNOWN
;
457 if (ProblemNumber
== 0)
459 if (LoadString(hDllInstance
,
471 if (LoadAndFormatStringsCat(hDllInstance
,
480 szBuffer
[BufferSize
- 1] = L
'\0';
482 LocalFree((HLOCAL
)szProblem
);
494 GetDeviceTypeString(IN PSP_DEVINFO_DATA DeviceInfoData
,
500 if (!SetupDiGetClassDescription(&DeviceInfoData
->ClassGuid
,
506 if (LoadString(hDllInstance
,
516 /* FIXME - check string for NULL termination! */
525 GetDeviceDescriptionString(IN HDEVINFO DeviceInfoSet
,
526 IN PSP_DEVINFO_DATA DeviceInfoData
,
533 if ((SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
538 BufferSize
* sizeof(WCHAR
),
540 SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
545 BufferSize
* sizeof(WCHAR
),
547 RegDataType
== REG_SZ
)
549 /* FIXME - check string for NULL termination! */
555 if (LoadString(hDllInstance
,
569 LoadAndInitComctl32(VOID
)
571 typedef VOID (WINAPI
*PINITCOMMONCONTROLS
)(VOID
);
572 PINITCOMMONCONTROLS pInitCommonControls
;
575 hComCtl32
= LoadLibrary(L
"comctl32.dll");
576 if (hComCtl32
!= NULL
)
578 /* initialize the common controls */
579 pInitCommonControls
= (PINITCOMMONCONTROLS
)GetProcAddress(hComCtl32
,
580 "InitCommonControls");
581 if (pInitCommonControls
== NULL
)
583 FreeLibrary(hComCtl32
);
587 pInitCommonControls();
596 DllMain(IN HINSTANCE hinstDLL
,
598 IN LPVOID lpvReserved
)
602 case DLL_PROCESS_ATTACH
:
603 DisableThreadLibraryCalls(hinstDLL
);
604 hDllInstance
= hinstDLL
;