ReactOS 0.4.15-dev-7788-g1ad9096
misc.cpp
Go to the documentation of this file.
1/*
2 * ReactOS Device Manager Applet
3 * Copyright (C) 2004 - 2005 ReactOS Team
4 *
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.
9 *
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.
14 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19/*
20 * PROJECT: ReactOS devmgr.dll
21 * FILE: lib/devmgr/misc.c
22 * PURPOSE: ReactOS Device Manager
23 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
24 * UPDATE HISTORY:
25 * 2005/11/24 Created
26 */
27
28#include "precomp.h"
29#include "properties.h"
30#include "resource.h"
31
32
33INT
35 IN UINT uID)
36{
37 HRSRC hrSrc;
38 HGLOBAL hRes;
39 LPWSTR lpName, lpStr;
40
41 if (hInst == NULL)
42 {
43 return -1;
44 }
45
46 /* There are always blocks of 16 strings */
47 lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1);
48
49 /* Find the string table block */
50 if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) &&
51 (hRes = LoadResource(hInst, hrSrc)) &&
52 (lpStr = (LPWSTR)LockResource(hRes)))
53 {
54 UINT x;
55
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++)
59 {
60 lpStr += (*lpStr) + 1;
61 }
62
63 /* Found the string */
64 return (int)(*lpStr);
65 }
66 return -1;
67}
68
69
70static INT
73 IN UINT uID)
74{
75 INT ln;
76
78 uID);
79 if (ln++ > 0)
80 {
81 (*lpTarget) = (LPWSTR)LocalAlloc(LMEM_FIXED,
82 ln * sizeof(WCHAR));
83 if ((*lpTarget) != NULL)
84 {
85 INT Ret;
86 if (!(Ret = LoadStringW(hInst, uID, *lpTarget, ln)))
87 {
88 LocalFree((HLOCAL)(*lpTarget));
89 }
90 return Ret;
91 }
92 }
93 return 0;
94}
95
96
97static INT
100 IN UINT *uID,
101 IN UINT nIDs)
102{
103 INT ln = 0;
104 UINT i;
105
106 for (i = 0;
107 i != nIDs;
108 i++)
109 {
111 uID[i]);
112 }
113
114 if (ln != 0)
115 {
116 (*lpTarget) = (LPWSTR)LocalAlloc(LMEM_FIXED,
117 (ln + 1) * sizeof(WCHAR));
118 if ((*lpTarget) != NULL)
119 {
120 LPWSTR s = *lpTarget;
121 INT Ret = 0;
122
123 for (i = 0;
124 i != nIDs;
125 i++)
126 {
127 if (!(Ret = LoadStringW(hInst, uID[i], s, ln)))
128 {
129 LocalFree((HLOCAL)(*lpTarget));
130 return 0;
131 }
132
133 s += Ret;
134 }
135
136 return s - *lpTarget;
137 }
138 }
139 return 0;
140}
141
142
143DWORD
145 IN UINT uID,
146 OUT LPWSTR *lpTarget,
147 ...)
148{
149 DWORD Ret = 0;
151 va_list lArgs;
152
154 hInstance,
155 uID) != 0)
156 {
157 va_start(lArgs, lpTarget);
158 /* let's use FormatMessage to format it because it has the ability to allocate
159 memory automatically */
161 lpFormat,
162 0,
163 0,
164 (LPWSTR)lpTarget,
165 0,
166 &lArgs);
167 va_end(lArgs);
168
170 }
171
172 return Ret;
173}
174
175
176DWORD
178 IN UINT *uID,
179 IN UINT nIDs,
180 OUT LPWSTR *lpTarget,
181 ...)
182{
183 DWORD Ret = 0;
185 va_list lArgs;
186
188 hInstance,
189 uID,
190 nIDs) != 0)
191 {
192 va_start(lArgs, lpTarget);
193 /* let's use FormatMessage to format it because it has the ability to allocate
194 memory automatically */
196 lpFormat,
197 0,
198 0,
199 (LPWSTR)lpTarget,
200 0,
201 &lArgs);
202 va_end(lArgs);
203
205 }
206
207 return Ret;
208}
209
210
211LPARAM
213{
214 int Index;
215
217 -1,
219 if (Index != -1)
220 {
221 LVITEM li;
222
223 li.mask = LVIF_PARAM;
224 li.iItem = Index;
225 li.iSubItem = 0;
226
228 &li))
229 {
230 return li.lParam;
231 }
232 }
233
234 return 0;
235}
236
237
238LPWSTR
240 IN UINT uCodePage)
241{
242 LPWSTR lpUnicodeStr;
243 INT nLength;
244
245 nLength = MultiByteToWideChar(uCodePage,
246 0,
247 lpMultiByteStr,
248 -1,
249 NULL,
250 0);
251 if (nLength == 0)
252 return NULL;
253
254 lpUnicodeStr = (LPWSTR)HeapAlloc(GetProcessHeap(),
255 0,
256 nLength * sizeof(WCHAR));
257 if (lpUnicodeStr == NULL)
258 {
260 return NULL;
261 }
262
263 if (!MultiByteToWideChar(uCodePage,
264 0,
265 lpMultiByteStr,
266 nLength,
267 lpUnicodeStr,
268 nLength))
269 {
271 0,
272 lpUnicodeStr);
273 return NULL;
274 }
275
276 return lpUnicodeStr;
277}
278
279
280BOOL
283 OUT LPWSTR szBuffer,
285{
286 DWORD RegDataType;
287 BOOL Ret = FALSE;
288
291 SPDRP_MFG,
292 &RegDataType,
293 (PBYTE)szBuffer,
294 BufferSize * sizeof(WCHAR),
295 NULL) ||
296 RegDataType != REG_SZ)
297 {
298 szBuffer[0] = L'\0';
301 szBuffer,
302 BufferSize))
303 {
304 Ret = TRUE;
305 }
306 }
307 else
308 {
309 /* FIXME - check string for NULL termination! */
310 Ret = TRUE;
311 }
312
313 return Ret;
314}
315
316
317BOOL
320 IN DEVINST dnParentDevInst OPTIONAL,
321 OUT LPWSTR szBuffer,
323{
324 DWORD RegDataType;
326 CONFIGRET cRet;
327 LPWSTR szFormatted;
328 HKEY hKey;
329 DWORD dwSize, dwType;
330 BOOL Ret = FALSE;
331
332 DataSize = BufferSize * sizeof(WCHAR);
333 szBuffer[0] = L'\0';
334
338 0,
339 DIREG_DRV,
342 {
343 /* query the LocationInformationOverride value */
346 L"LocationInformationOverride",
347 NULL,
348 &dwType,
349 (LPBYTE)szBuffer,
350 &dwSize) == ERROR_SUCCESS &&
351 dwType == REG_SZ &&
352 szBuffer[0] != L'\0')
353 {
354 Ret = TRUE;
355 }
356 else
357 {
358 szBuffer[0] = L'\0';
359 }
360
362 }
363
364
365 if (!Ret)
366 {
367 if (dnParentDevInst != 0)
368 {
369 /* query the parent node name */
370 if (CM_Get_DevNode_Registry_Property(dnParentDevInst,
372 &RegDataType,
373 szBuffer,
374 &DataSize,
375 0) == CR_SUCCESS &&
376 RegDataType == REG_SZ &&
379 &szFormatted,
380 szBuffer) != 0)
381 {
382 wcsncpy(szBuffer,
383 szFormatted,
384 BufferSize - 1);
385 szBuffer[BufferSize - 1] = L'\0';
386 LocalFree((HLOCAL)szFormatted);
387 Ret = TRUE;
388 }
389 }
390 else if (DeviceInfoData->DevInst != 0)
391 {
394 &RegDataType,
395 szBuffer,
396 &DataSize,
397 0);
398 if (cRet == CR_SUCCESS && RegDataType == REG_SZ)
399 {
400 /* FIXME - check string for NULL termination! */
401 Ret = TRUE;
402 }
403
404 if (Ret && szBuffer[0] >= L'0' && szBuffer[0] <= L'9')
405 {
406 /* convert the string to an integer value and create a
407 formatted string */
408 ULONG ulLocation = (ULONG)wcstoul(szBuffer,
409 NULL,
410 10);
413 &szFormatted,
414 ulLocation,
415 szBuffer) != 0)
416 {
417 wcsncpy(szBuffer,
418 szFormatted,
419 BufferSize - 1);
420 szBuffer[BufferSize - 1] = L'\0';
421 LocalFree((HLOCAL)szFormatted);
422 }
423 else
424 Ret = FALSE;
425 }
426 }
427 }
428
429 if (!Ret &&
432 szBuffer,
433 BufferSize))
434 {
435 Ret = TRUE;
436 }
437
438 return Ret;
439}
440
441
442BOOL
444 IN HMACHINE hMachine,
445 OUT LPWSTR szBuffer,
447{
448 CONFIGRET cr;
449 ULONG Status, ProblemNumber;
450 UINT MessageId = IDS_UNKNOWN;
451 BOOL Ret = FALSE;
452
453 szBuffer[0] = L'\0';
455 &ProblemNumber,
456 DevInst,
457 0,
458 hMachine);
459 if (cr == CR_SUCCESS)
460 {
462 {
463 UINT uRet;
464
465 uRet = DeviceProblemTextW(hMachine,
466 DevInst,
467 ProblemNumber,
468 szBuffer,
469 (BufferSize != 0 ? BufferSize : BufferSize - 1));
470
471 Ret = (uRet != 0 && uRet < BufferSize);
472 }
473 else
474 {
476 {
477 MessageId = IDS_NODRIVERLOADED;
478 }
479 else
480 {
481 MessageId = IDS_DEV_NO_PROBLEM;
482 }
483
484 goto GeneralMessage;
485 }
486 }
487 else
488 {
489GeneralMessage:
491 MessageId,
492 szBuffer,
493 (int)BufferSize))
494 {
495 Ret = TRUE;
496 }
497 }
498
499 return Ret;
500}
501
502
503BOOL
506 OUT LPWSTR szBuffer,
508{
509 HKEY hKey;
510 DWORD dwSize, dwType;
511 BOOL Ret = FALSE;
512
513 szBuffer[0] = L'\0';
514
515 /* get driver provider, date and version */
519 0,
520 DIREG_DRV,
523 {
524 /* query the driver provider */
528 NULL,
529 &dwType,
530 (LPBYTE)szBuffer,
531 &dwSize) == ERROR_SUCCESS &&
532 dwType == REG_SZ &&
533 szBuffer[0] != L'\0')
534 {
535 Ret = TRUE;
536 }
537 else
538 {
539 szBuffer[0] = L'\0';
540 }
541
543 }
544
545 if (szBuffer[0] == L'\0')
546 {
547 /* unable to query the information */
550 szBuffer,
551 BufferSize))
552 {
553 Ret = TRUE;
554 }
555 }
556
557 return Ret;
558}
559
560
561BOOL
564 OUT LPWSTR szBuffer,
566{
567 HKEY hKey;
568 DWORD dwSize, dwType;
569 BOOL Ret = FALSE;
570
571 szBuffer[0] = L'\0';
572
573 /* get driver provider, date and version */
577 0,
578 DIREG_DRV,
581 {
582 /* query the driver provider */
585 L"DriverVersion",
586 NULL,
587 &dwType,
588 (LPBYTE)szBuffer,
589 &dwSize) == ERROR_SUCCESS &&
590 dwType == REG_SZ &&
591 szBuffer[0] != L'\0')
592 {
593 Ret = TRUE;
594 }
595 else
596 {
597 szBuffer[0] = L'\0';
598 }
599
601 }
602
603 if (szBuffer[0] == L'\0')
604 {
605 /* unable to query the information */
608 szBuffer,
609 BufferSize))
610 {
611 Ret = TRUE;
612 }
613 }
614
615 return Ret;
616}
617
618BOOL
621 OUT LPWSTR szBuffer,
623{
624 HKEY hKey;
625 FILETIME DriverDate;
626 SYSTEMTIME SystemTime, LocalTime;
627 DWORD dwSize, dwType;
628 BOOL Ret = FALSE;
629
630 szBuffer[0] = L'\0';
631
632 /* get driver provider, date and version */
636 0,
637 DIREG_DRV,
640 {
641 /* query the driver provider */
642 dwSize = sizeof(FILETIME);
644 L"DriverDateData",
645 NULL,
646 &dwType,
647 (LPBYTE)&DriverDate,
648 &dwSize) == ERROR_SUCCESS &&
649 dwType == REG_BINARY &&
650 dwSize == sizeof(FILETIME) &&
651 FileTimeToSystemTime(&DriverDate,
652 &SystemTime) &&
654 &SystemTime,
655 &LocalTime) &&
658 &LocalTime,
659 NULL,
660 szBuffer,
661 BufferSize) != 0)
662 {
663 Ret = TRUE;
664 }
665
667 }
668
669 if (!Ret)
670 {
671 /* unable to query the information */
674 szBuffer,
675 BufferSize))
676 {
677 Ret = TRUE;
678 }
679 }
680
681 return Ret;
682}
683
684
685
686BOOL
688 IN HMACHINE hMachine,
689 OUT BOOL *IsHidden)
690{
691 CONFIGRET cr;
692 ULONG Status, ProblemNumber;
693 BOOL Ret = FALSE;
694
696 &ProblemNumber,
697 DevInst,
698 0,
699 hMachine);
700 if (cr == CR_SUCCESS)
701 {
702 *IsHidden = ((Status & DN_NO_SHOW_IN_DM) != 0);
703 Ret = TRUE;
704 }
705
706 return Ret;
707}
708
709
710BOOL
712 IN HMACHINE hMachine,
713 OUT BOOL *CanDisable)
714{
715 CONFIGRET cr;
716 ULONG Status, ProblemNumber;
717 BOOL Ret = FALSE;
718
720 &ProblemNumber,
721 DevInst,
722 0,
723 hMachine);
724 if (cr == CR_SUCCESS)
725 {
726 *CanDisable = ((Status & DN_DISABLEABLE) != 0);
727 Ret = TRUE;
728 }
729
730 return Ret;
731}
732
733
734BOOL
736 IN HMACHINE hMachine,
737 OUT BOOL *IsStarted)
738{
739 CONFIGRET cr;
740 ULONG Status, ProblemNumber;
741 BOOL Ret = FALSE;
742
744 &ProblemNumber,
745 DevInst,
746 0,
747 hMachine);
748 if (cr == CR_SUCCESS)
749 {
750 *IsStarted = ((Status & DN_STARTED) != 0);
751 Ret = TRUE;
752 }
753
754 return Ret;
755}
756
757
758BOOL
760 IN HMACHINE hMachine,
761 OUT BOOL *Installed)
762{
763 CONFIGRET cr;
764 ULONG Status, ProblemNumber;
765 BOOL Ret = FALSE;
766
768 &ProblemNumber,
769 DevInst,
770 0,
771 hMachine);
772 if (cr == CR_SUCCESS)
773 {
774 *Installed = ((Status & DN_HAS_PROBLEM) != 0 ||
775 (Status & (DN_DRIVER_LOADED | DN_STARTED)) != 0);
776 Ret = TRUE;
777 }
778
779 return Ret;
780}
781
782
783BOOL
785 IN PSP_DEVINFO_DATA DevInfoData OPTIONAL,
787 IN DWORD HardwareProfile OPTIONAL,
788 OUT BOOL *bNeedReboot OPTIONAL)
789{
792 DWORD LastErr;
793 BOOL Ret = FALSE;
794
797 pcp.HwProfile = HardwareProfile;
798
799 if (bEnable)
800 {
801 /* try to enable the device on the global profile */
804
805 /* ignore errors */
806 LastErr = GetLastError();
808 DevInfoData,
810 sizeof(SP_PROPCHANGE_PARAMS)))
811 {
814 DevInfoData);
815 }
816 SetLastError(LastErr);
817 }
818
819 /* try config-specific */
822
824 DevInfoData,
826 sizeof(SP_PROPCHANGE_PARAMS)) &&
829 DevInfoData))
830 {
831 dp.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
833 DevInfoData,
834 &dp))
835 {
836 if (bNeedReboot != NULL)
837 {
838 *bNeedReboot = ((dp.Flags & (DI_NEEDRESTART | DI_NEEDREBOOT)) != 0);
839 }
840
841 Ret = TRUE;
842 }
843 }
844 return Ret;
845}
846
847
848BOOL
850 OUT LPWSTR szBuffer,
852{
853 BOOL Ret = FALSE;
854
856 szBuffer,
858 NULL))
859 {
860 szBuffer[0] = L'\0';
863 szBuffer,
864 BufferSize))
865 {
866 Ret = TRUE;
867 }
868 }
869 else
870 {
871 /* FIXME - check string for NULL termination! */
872 Ret = TRUE;
873 }
874
875 return Ret;
876}
877
878
879BOOL
882 OUT LPWSTR szBuffer,
884{
885 DWORD RegDataType;
886 BOOL Ret = FALSE;
887
891 &RegDataType,
892 (PBYTE)szBuffer,
893 BufferSize * sizeof(WCHAR),
894 NULL) ||
898 &RegDataType,
899 (PBYTE)szBuffer,
900 BufferSize * sizeof(WCHAR),
901 NULL)) &&
902 RegDataType == REG_SZ)
903 {
904 /* FIXME - check string for NULL termination! */
905 Ret = TRUE;
906 }
907 else
908 {
909 szBuffer[0] = L'\0';
912 szBuffer,
913 BufferSize))
914 {
915 Ret = TRUE;
916 }
917 }
918
919 return Ret;
920}
921
922
923BOOL
926 OUT PSP_DRVINFO_DATA DriverInfoData)
927{
929 SP_DEVINSTALL_PARAMS InstallParams = {0};
930 SP_DRVINFO_DETAIL_DATA DriverInfoDetailData = {0};
931 WCHAR InfPath[MAX_PATH];
932 WCHAR InfSection[LINE_LEN];
933 DWORD dwType, dwLength;
934 DWORD i = 0;
935 LONG rc;
936 BOOL Ret = FALSE;
937
938 /* Steps to find the right driver:
939 * 1) Get the device install parameters
940 * 2) Open the driver registry key
941 * 3) Read the .inf file name
942 * 4) Update install params, by setting DI_ENUMSINGLEINF and .inf file name
943 * 5) Build class driver list
944 * 6) Read inf section and inf section extension from registry
945 * 7) Enumerate drivers
946 * 8) Find the one who is in the same section as current driver?
947 */
948
949 /* 1) Get the install params */
950 InstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
953 &InstallParams))
954 {
955 ERR("SetupDiSetDeviceInstallParams() failed with error 0x%lx\n", GetLastError());
956 goto Cleanup;
957 }
958
959#ifdef DI_FLAGSEX_INSTALLEDDRIVER
960 InstallParams.FlagsEx |= (DI_FLAGSEX_INSTALLEDDRIVER | DI_FLAGSEX_ALLOWEXCLUDEDDRVS);
963 &InstallParams))
964 {
971 0,
972 DriverInfoData))
973 {
974 Ret = TRUE;
975 }
976
977 goto Cleanup;
978 }
979 InstallParams.FlagsEx &= ~(DI_FLAGSEX_INSTALLEDDRIVER | DI_FLAGSEX_ALLOWEXCLUDEDDRVS);
980#endif
981
982 /* 2) Open the driver registry key */
986 0,
987 DIREG_DRV,
990 {
991 ERR("SetupDiOpenDevRegKey() failed with error 0x%lx\n", GetLastError());
992 goto Cleanup;
993 }
994
995 /* 3) Read the .inf file name */
996 dwLength = (sizeof(InfPath) / sizeof(InfPath[0])) - 1;
999 0,
1000 &dwType,
1001 (LPBYTE)InfPath,
1002 &dwLength);
1003 if (rc != ERROR_SUCCESS)
1004 {
1005 ERR("RegQueryValueEx() failed with error 0x%lx\n", GetLastError());
1006 SetLastError(rc);
1007 goto Cleanup;
1008 }
1009 else if (dwType != REG_SZ)
1010 {
1011 ERR("Expected registry type REG_SZ (%lu), got %lu\n", REG_SZ, dwType);
1013 goto Cleanup;
1014 }
1015 InfPath[(dwLength / sizeof(WCHAR)) - 1] = L'\0';
1016
1017 /* 4) Update install params, by setting DI_ENUMSINGLEINF and .inf file name */
1018 InstallParams.Flags |= DI_ENUMSINGLEINF;
1019 InstallParams.FlagsEx |= DI_FLAGSEX_ALLOWEXCLUDEDDRVS;
1020 wcscpy(InstallParams.DriverPath, InfPath);
1023 &InstallParams))
1024 {
1025 ERR("SetupDiSetDeviceInstallParams() failed with error 0x%lx\n", GetLastError());
1026 goto Cleanup;
1027 }
1028
1029 /* 5) Build class driver list */
1033 {
1034 ERR("SetupDiBuildDriverInfoList() failed with error 0x%lx\n", GetLastError());
1035 goto Cleanup;
1036 }
1037
1038 /* 6) Read inf section and from registry */
1039 dwLength = (sizeof(InfSection) / sizeof(InfSection[0])) - 1;
1040 rc = RegQueryValueEx(hKey,
1042 0,
1043 &dwType,
1044 (LPBYTE)InfSection,
1045 &dwLength);
1046 if (rc != ERROR_SUCCESS)
1047 {
1048 ERR("RegQueryValueEx() failed with error 0x%lx\n", GetLastError());
1049 SetLastError(rc);
1050 goto Cleanup;
1051 }
1052 else if (dwType != REG_SZ)
1053 {
1054 ERR("Expected registry type REG_SZ (%lu), got %lu\n", REG_SZ, dwType);
1056 goto Cleanup;
1057 }
1058 InfPath[(dwLength / sizeof(WCHAR)) - 1] = L'\0';
1059
1060 /* 7) Enumerate drivers */
1061 DriverInfoData->cbSize = sizeof(SP_DRVINFO_DATA);
1062 DriverInfoDetailData.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
1066 i,
1067 DriverInfoData))
1068 {
1069 /* 8) Find the one who is in the same section as current driver */
1072 DriverInfoData,
1073 &DriverInfoDetailData,
1074 DriverInfoDetailData.cbSize,
1075 NULL) &&
1077 {
1078 ERR("SetupDiGetDriverInfoDetail() failed with error 0x%lx\n", GetLastError());
1079 goto Cleanup;
1080 }
1081 if (_wcsicmp(DriverInfoDetailData.SectionName, InfSection) == 0)
1082 {
1083 /* We have found the right driver */
1084 Ret = TRUE;
1085 goto Cleanup;
1086 }
1087
1088 i++;
1089 }
1091 {
1092 ERR("SetupDiEnumDriverInfo() failed with error 0x%lx\n", GetLastError());
1093 goto Cleanup;
1094 }
1095
1097
1098Cleanup:
1101 return Ret;
1102}
1103
1104
1107{
1108 typedef VOID (WINAPI *PINITCOMMONCONTROLS)(VOID);
1109 PINITCOMMONCONTROLS pInitCommonControls;
1110 HINSTANCE hComCtl32;
1111
1112 hComCtl32 = LoadLibrary(L"comctl32.dll");
1113 if (hComCtl32 != NULL)
1114 {
1115 /* initialize the common controls */
1116 pInitCommonControls = (PINITCOMMONCONTROLS)GetProcAddress(hComCtl32,
1117 "InitCommonControls");
1118 if (pInitCommonControls == NULL)
1119 {
1120 FreeLibrary(hComCtl32);
1121 return NULL;
1122 }
1123
1124 pInitCommonControls();
1125 }
1126
1127 return hComCtl32;
1128}
1129
1130
1131BOOL
1133 WCHAR szDeviceID[],
1134 WCHAR szMachineName[])
1135{
1136 BOOL ret = FALSE;
1137
1138 szDeviceID[0] = L'\0';
1139 szMachineName[0] = L'\0';
1140
1141 while (*lpString != L'\0')
1142 {
1143 if (*lpString == L'/')
1144 {
1145 lpString++;
1146 if (!_wcsnicmp(lpString, L"DeviceID", 8))
1147 {
1148 lpString += 9;
1149 if (*lpString != L'\0')
1150 {
1151 int i = 0;
1152 while ((*lpString != L' ') &&
1153 (*lpString != L'\0') &&
1154 (i <= MAX_DEVICE_ID_LEN))
1155 {
1156 szDeviceID[i++] = *lpString++;
1157 }
1158 szDeviceID[i] = L'\0';
1159 ret = TRUE;
1160 }
1161 }
1162 else if (!_wcsnicmp(lpString, L"MachineName", 11))
1163 {
1164 lpString += 12;
1165 if (*lpString != L'\0')
1166 {
1167 int i = 0;
1168 while ((*lpString != L' ') &&
1169 (*lpString != L'\0') &&
1171 {
1172 szMachineName[i++] = *lpString++;
1173 }
1174 szMachineName[i] = L'\0';
1175 }
1176 }
1177 /* knock the pointer back one and let the next
1178 * pointer deal with incrementing, otherwise we
1179 * go past the end of the string */
1180 lpString--;
1181 }
1182 lpString++;
1183 }
1184
1185 return ret;
1186}
#define VOID
Definition: acefi.h:82
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define IDS_UNKNOWN
Definition: resource.h:7
#define ERR(fmt,...)
Definition: debug.h:110
HANDLE HKEY
Definition: registry.h:26
#define RegCloseKey(hKey)
Definition: registry.h:49
#define DN_NO_SHOW_IN_DM
Definition: cfg.h:148
#define DN_DRIVER_LOADED
Definition: cfg.h:119
#define DN_DISABLEABLE
Definition: cfg.h:131
#define DN_HAS_PROBLEM
Definition: cfg.h:128
#define DN_STARTED
Definition: cfg.h:121
#define CM_DRP_LOCATION_INFORMATION
Definition: cfgmgr32.h:689
#define CM_DRP_DEVICEDESC
Definition: cfgmgr32.h:676
DWORD DEVINST
Definition: cfgmgr32.h:76
#define CM_Get_DevNode_Registry_Property
Definition: cfgmgr32.h:1733
RETURN_TYPE CONFIGRET
Definition: cfgmgr32.h:74
#define CR_SUCCESS
Definition: cfgmgr32.h:842
CONFIGRET WINAPI CM_Get_DevNode_Status_Ex(_Out_ PULONG pulStatus, _Out_ PULONG pulProblemNumber, _In_ DEVINST dnDevInst, _In_ ULONG ulFlags, _In_opt_ HMACHINE hMachine)
Definition: cfgmgr.c:3591
HINSTANCE hInstance
Definition: charmap.c:19
static HINSTANCE hDllInstance
Definition: clb.c:30
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define BufferSize
Definition: mmc.h:75
#define ERROR_SUCCESS
Definition: deptool.c:10
#define MAX_DEVICE_ID_LEN
Definition: devaction.c:40
UINT WINAPI DeviceProblemTextW(IN HMACHINE hMachine OPTIONAL, IN DEVINST dnDevInst, IN ULONG uProblemId, OUT LPWSTR lpString, IN UINT uMaxString)
Definition: devprblm.cpp:491
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define FreeLibrary(x)
Definition: compat.h:748
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define MultiByteToWideChar
Definition: compat.h:110
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.cpp:34
BOOL IsDeviceStarted(IN DEVINST DevInst, IN HMACHINE hMachine, OUT BOOL *IsStarted)
Definition: misc.cpp:735
LPWSTR ConvertMultiByteToUnicode(IN LPCSTR lpMultiByteStr, IN UINT uCodePage)
Definition: misc.cpp:239
BOOL FindCurrentDriver(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData, OUT PSP_DRVINFO_DATA DriverInfoData)
Definition: misc.cpp:924
static INT AllocAndLoadString(OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.cpp:71
static INT AllocAndLoadStringsCat(OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT *uID, IN UINT nIDs)
Definition: misc.cpp:98
BOOL GetDeviceLocationString(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData, IN DEVINST dnParentDevInst OPTIONAL, OUT LPWSTR szBuffer, IN DWORD BufferSize)
Definition: misc.cpp:318
BOOL GetDeviceManufacturerString(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData, OUT LPWSTR szBuffer, IN DWORD BufferSize)
Definition: misc.cpp:281
BOOL GetDriverVersionString(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData, OUT LPWSTR szBuffer, IN DWORD BufferSize)
Definition: misc.cpp:562
BOOL IsDeviceHidden(IN DEVINST DevInst, IN HMACHINE hMachine, OUT BOOL *IsHidden)
Definition: misc.cpp:687
BOOL GetDriverDateString(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData, OUT LPWSTR szBuffer, IN DWORD BufferSize)
Definition: misc.cpp:619
BOOL CanDisableDevice(IN DEVINST DevInst, IN HMACHINE hMachine, OUT BOOL *CanDisable)
Definition: misc.cpp:711
BOOL GetDriverProviderString(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData, OUT LPWSTR szBuffer, IN DWORD BufferSize)
Definition: misc.cpp:504
BOOL GetDeviceTypeString(IN PSP_DEVINFO_DATA DeviceInfoData, OUT LPWSTR szBuffer, IN DWORD BufferSize)
Definition: misc.cpp:849
DWORD LoadAndFormatString(IN HINSTANCE hInstance, IN UINT uID, OUT LPWSTR *lpTarget,...)
Definition: misc.cpp:144
BOOL GetDeviceStatusString(IN DEVINST DevInst, IN HMACHINE hMachine, OUT LPWSTR szBuffer, IN DWORD BufferSize)
Definition: misc.cpp:443
BOOL GetDeviceDescriptionString(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData, OUT LPWSTR szBuffer, IN DWORD BufferSize)
Definition: misc.cpp:880
DWORD LoadAndFormatStringsCat(IN HINSTANCE hInstance, IN UINT *uID, IN UINT nIDs, OUT LPWSTR *lpTarget,...)
Definition: misc.cpp:177
LPARAM ListViewGetSelectedItemData(IN HWND hwnd)
Definition: misc.cpp:212
HINSTANCE LoadAndInitComctl32(VOID)
Definition: misc.cpp:1106
BOOL EnableDevice(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DevInfoData OPTIONAL, IN BOOL bEnable, IN DWORD HardwareProfile OPTIONAL, OUT BOOL *bNeedReboot OPTIONAL)
Definition: misc.cpp:784
BOOL IsDriverInstalled(IN DEVINST DevInst, IN HMACHINE hMachine, OUT BOOL *Installed)
Definition: misc.cpp:759
BOOL GetDeviceAndComputerName(LPWSTR lpString, WCHAR szDeviceID[], WCHAR szMachineName[])
Definition: misc.cpp:1132
#define IDS_NODRIVERLOADED
Definition: resource.h:114
#define IDS_DEV_NO_PROBLEM
Definition: resource.h:133
#define IDS_DEVONPARENT
Definition: resource.h:115
#define IDS_UNKNOWNDEVICE
Definition: resource.h:113
#define IDS_LOCATIONSTR
Definition: resource.h:108
#define IDS_NOTAVAILABLE
Definition: resource.h:122
static DWORD DWORD * dwLength
Definition: fusion.c:86
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
BOOL WINAPI SystemTimeToTzSpecificLocalTime(CONST TIME_ZONE_INFORMATION *lpTimeZoneInformation, CONST SYSTEMTIME *lpUniversalTime, LPSYSTEMTIME lpLocalTime)
Definition: timezone.c:377
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
BOOL WINAPI SetupDiCallClassInstaller(DI_FUNCTION InstallFunction, HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:4024
HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Scope, DWORD HwProfile, DWORD KeyType, REGSAM samDesired)
Definition: devinst.c:5934
BOOL WINAPI SetupDiBuildDriverInfoList(IN HDEVINFO DeviceInfoSet, IN OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, IN DWORD DriverType)
Definition: driver.c:718
static const WCHAR Cleanup[]
Definition: register.c:80
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
Status
Definition: gdiplustypes.h:25
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble s
Definition: gl.h:2039
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define REG_SZ
Definition: layer.c:22
struct _FILETIME FILETIME
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
unsigned int UINT
Definition: ndis.h:50
#define REG_BINARY
Definition: nt_native.h:1496
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define LOCALE_USER_DEFAULT
#define L(x)
Definition: ntvdm.h:50
#define RT_STRING
Definition: pedump.c:368
BYTE * PBYTE
Definition: pedump.c:66
long LONG
Definition: pedump.c:60
#define LVNI_SELECTED
Definition: commctrl.h:2424
#define ListView_GetNextItem(hwnd, i, flags)
Definition: commctrl.h:2434
#define LVITEM
Definition: commctrl.h:2375
#define LVIF_PARAM
Definition: commctrl.h:2311
#define ListView_GetItem(hwnd, pitem)
Definition: commctrl.h:2394
#define REGSTR_VAL_INFPATH
Definition: regstr.h:439
#define REGSTR_VAL_INFSECTION
Definition: regstr.h:440
#define REGSTR_VAL_PROVIDER_NAME
Definition: regstr.h:540
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
struct _SP_CLASSINSTALL_HEADER SP_CLASSINSTALL_HEADER
#define DI_NEEDRESTART
Definition: setupapi.h:53
#define SetupDiGetDriverInfoDetail
Definition: setupapi.h:2604
#define SPDIT_CLASSDRIVER
Definition: setupapi.h:505
#define SPDRP_DEVICEDESC
Definition: setupapi.h:507
#define SetupDiGetDeviceInstallParams
Definition: setupapi.h:2599
SP_DEVINSTALL_PARAMS_A SP_DEVINSTALL_PARAMS
Definition: setupapi.h:1155
#define LINE_LEN
Definition: setupapi.h:20
#define SetupDiSetClassInstallParams
Definition: setupapi.h:2617
#define DICS_DISABLE
Definition: setupapi.h:114
#define SetupDiGetDeviceRegistryProperty
Definition: setupapi.h:2603
#define DI_ENUMSINGLEINF
Definition: setupapi.h:62
SP_DRVINFO_DATA_V2 SP_DRVINFO_DATA
Definition: setupapi.h:1054
#define DIREG_DRV
Definition: setupapi.h:182
#define ERROR_NO_DRIVER_SELECTED
Definition: setupapi.h:299
SP_DRVINFO_DETAIL_DATA_A SP_DRVINFO_DETAIL_DATA
Definition: setupapi.h:1162
#define DICS_ENABLE
Definition: setupapi.h:112
#define DICS_FLAG_CONFIGSPECIFIC
Definition: setupapi.h:115
#define SetupDiSetDeviceInstallParams
Definition: setupapi.h:2619
_In_opt_ PSP_DEVINFO_DATA DeviceInfoData
Definition: setupapi.h:1528
#define SetupDiGetClassDescription
Definition: setupapi.h:2590
#define SPDRP_MFG
Definition: setupapi.h:518
#define DI_NEEDREBOOT
Definition: setupapi.h:54
#define SetupDiEnumDriverInfo
Definition: setupapi.h:2587
#define DI_FLAGSEX_ALLOWEXCLUDEDDRVS
Definition: setupapi.h:87
#define DICS_FLAG_GLOBAL
Definition: setupapi.h:113
#define DIF_PROPERTYCHANGE
Definition: setupapi.h:137
#define SPDRP_FRIENDLYNAME
Definition: setupapi.h:519
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
DI_FUNCTION InstallFunction
Definition: setupapi.h:904
CHAR DriverPath[MAX_PATH]
Definition: setupapi.h:888
CHAR SectionName[LINE_LEN]
Definition: setupapi.h:1065
SP_CLASSINSTALL_HEADER ClassInstallHeader
Definition: setupapi.h:916
LPCWSTR lpFormat
Definition: trayclock.cpp:32
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
int ret
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:421
#define LoadLibrary
Definition: winbase.h:3797
_In_ LPCSTR lpName
Definition: winbase.h:2789
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
#define LMEM_FIXED
Definition: winbase.h:368
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:243
_In_ DWORD nLength
Definition: wincon.h:473
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
_In_ BOOL bEnable
Definition: winddi.h:3426
LONG_PTR LPARAM
Definition: windef.h:208
#define WINAPI
Definition: msvc.h:6
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
#define GetDateFormat
Definition: winnls.h:1184
#define DATE_SHORTDATE
Definition: winnls.h:196
#define RegQueryValueEx
Definition: winreg.h:524
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define LoadString
Definition: winuser.h:5819
#define MAKEINTRESOURCE
Definition: winuser.h:591
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184