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 LoadAndFormatString(IN HINSTANCE hInstance
,
100 OUT LPWSTR
*lpTarget
,
107 if (AllocAndLoadString(&lpFormat
,
111 va_start(lArgs
, lpTarget
);
112 /* let's use FormatMessage to format it because it has the ability to allocate
113 memory automatically */
114 Ret
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
123 LocalFree((HLOCAL
)lpFormat
);
131 ListViewGetSelectedItemData(IN HWND hwnd
)
135 Index
= ListView_GetNextItem(hwnd
,
142 li
.mask
= LVIF_PARAM
;
146 if (ListView_GetItem(hwnd
,
158 ConvertMultiByteToUnicode(IN LPCSTR lpMultiByteStr
,
164 nLength
= MultiByteToWideChar(uCodePage
,
173 lpUnicodeStr
= HeapAlloc(GetProcessHeap(),
175 nLength
* sizeof(WCHAR
));
176 if (lpUnicodeStr
== NULL
)
179 if (!MultiByteToWideChar(uCodePage
,
186 HeapFree(GetProcessHeap(),
197 GetDeviceManufacturerString(IN HDEVINFO DeviceInfoSet
,
198 IN PSP_DEVINFO_DATA DeviceInfoData
,
205 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
210 BufferSize
* sizeof(WCHAR
),
212 RegDataType
!= REG_SZ
)
215 if (LoadString(hDllInstance
,
225 /* FIXME - check string for NULL termination! */
234 GetDeviceLocationString(IN DEVINST dnDevInst
,
243 DataSize
= BufferSize
* sizeof(WCHAR
);
244 cRet
= CM_Get_DevNode_Registry_Property(dnDevInst
,
245 CM_DRP_LOCATION_INFORMATION
,
250 if (cRet
!= CR_SUCCESS
||
251 RegDataType
!= REG_SZ
)
254 if (LoadString(hDllInstance
,
264 /* FIXME - check string for NULL termination! */
268 if (szBuffer
[0] >= L
'0' && szBuffer
[0] <= L
'9')
270 /* convert the string to an integer value and create a
273 ULONG ulLocation
= (ULONG
)wcstoul(szBuffer
,
276 if (LoadAndFormatString(hDllInstance
,
285 szBuffer
[BufferSize
- 1] = L
'\0';
286 LocalFree((HLOCAL
)szFormatted
);
297 GetDeviceStatusString(IN HDEVINFO DeviceInfoSet
,
298 IN PSP_DEVINFO_DATA DeviceInfoData
,
302 return LoadString(hDllInstance
,
310 GetDeviceTypeString(IN PSP_DEVINFO_DATA DeviceInfoData
,
316 if (!SetupDiGetClassDescription(&DeviceInfoData
->ClassGuid
,
322 if (LoadString(hDllInstance
,
332 /* FIXME - check string for NULL termination! */
341 LoadAndInitComctl32(VOID
)
343 typedef VOID (WINAPI
*PINITCOMMONCONTROLS
)(VOID
);
344 PINITCOMMONCONTROLS pInitCommonControls
;
347 hComCtl32
= LoadLibrary(L
"comctl32.dll");
348 if (hComCtl32
!= NULL
)
350 /* initialize the common controls */
351 pInitCommonControls
= (PINITCOMMONCONTROLS
)GetProcAddress(hComCtl32
,
352 "InitCommonControls");
353 if (pInitCommonControls
== NULL
)
355 FreeLibrary(hComCtl32
);
359 pInitCommonControls();
368 DllMain(IN HINSTANCE hinstDLL
,
370 IN LPVOID lpvReserved
)
374 case DLL_PROCESS_ATTACH
:
375 DisableThreadLibraryCalls(hinstDLL
);
376 hDllInstance
= hinstDLL
;