80b535c3dab95aa8e4bfe0fab856e8465743e479
[reactos.git] / dll / win32 / setupapi / cfgmgr.c
1 /*
2 * Configuration manager functions
3 *
4 * Copyright 2000 James Hatheway
5 * Copyright 2005, 2006 Eric Kohl
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "setupapi_private.h"
23
24 #include <dbt.h>
25 #include <pnp_c.h>
26
27 #include "rpc_private.h"
28
29 /* Registry key and value names */
30 static const WCHAR Backslash[] = {'\\', 0};
31 static const WCHAR Class[] = {'C','l','a','s','s',0};
32
33 static const WCHAR ControlClass[] = {'S','y','s','t','e','m','\\',
34 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
35 'C','o','n','t','r','o','l','\\',
36 'C','l','a','s','s',0};
37
38 static const WCHAR DeviceClasses[] = {'S','y','s','t','e','m','\\',
39 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
40 'C','o','n','t','r','o','l','\\',
41 'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
42
43 typedef struct _MACHINE_INFO
44 {
45 WCHAR szMachineName[SP_MAX_MACHINENAME_LENGTH];
46 RPC_BINDING_HANDLE BindingHandle;
47 HSTRING_TABLE StringTable;
48 BOOL bLocal;
49 } MACHINE_INFO, *PMACHINE_INFO;
50
51
52 typedef struct _LOG_CONF_INFO
53 {
54 ULONG ulMagic;
55 DEVINST dnDevInst;
56 ULONG ulFlags;
57 ULONG ulTag;
58 } LOG_CONF_INFO, *PLOG_CONF_INFO;
59
60 #define LOG_CONF_MAGIC 0x464E434C /* "LCNF" */
61
62
63 typedef struct _NOTIFY_DATA
64 {
65 ULONG ulMagic;
66 ULONG ulNotifyData;
67 } NOTIFY_DATA, *PNOTIFY_DATA;
68
69 #define NOTIFY_MAGIC 0x44556677
70
71
72 typedef struct _INTERNAL_RANGE_ELEMENT
73 {
74 struct _INTERNAL_RANGE_ELEMENT *Next;
75 ULONG ulDummy;
76 } INTERNAL_RANGE_ELEMENT, *PINTERNAL_RANGE_ELEMENT;
77
78 typedef struct _INTERNAL_RANGE_LIST
79 {
80 ULONG ulMagic;
81 PINTERNAL_RANGE_ELEMENT Current;
82 PINTERNAL_RANGE_ELEMENT First;
83 } INTERNAL_RANGE_LIST, *PINTERNAL_RANGE_LIST;
84
85 #define RANGE_LIST_MAGIC 0x33445566
86
87
88 static
89 BOOL
90 GuidToString(
91 _In_ LPGUID Guid,
92 _Out_ LPWSTR String)
93 {
94 LPWSTR lpString;
95
96 if (UuidToStringW(Guid, &lpString) != RPC_S_OK)
97 return FALSE;
98
99 lstrcpyW(&String[1], lpString);
100
101 String[0] = '{';
102 String[MAX_GUID_STRING_LEN - 2] = '}';
103 String[MAX_GUID_STRING_LEN - 1] = UNICODE_NULL;
104
105 RpcStringFreeW(&lpString);
106
107 return TRUE;
108 }
109
110
111 static
112 CONFIGRET
113 RpcStatusToCmStatus(
114 _In_ RPC_STATUS Status)
115 {
116 return CR_FAILURE;
117 }
118
119
120 static
121 ULONG
122 GetRegistryPropertyType(
123 _In_ ULONG ulProperty)
124 {
125 switch (ulProperty)
126 {
127 case CM_DRP_DEVICEDESC:
128 case CM_DRP_SERVICE:
129 case CM_DRP_CLASS:
130 case CM_DRP_CLASSGUID:
131 case CM_DRP_DRIVER:
132 case CM_DRP_MFG:
133 case CM_DRP_FRIENDLYNAME:
134 case CM_DRP_LOCATION_INFORMATION:
135 case CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME:
136 case CM_DRP_ENUMERATOR_NAME:
137 case CM_DRP_SECURITY_SDS:
138 case CM_DRP_UI_NUMBER_DESC_FORMAT:
139 return REG_SZ;
140
141 case CM_DRP_HARDWAREID:
142 case CM_DRP_COMPATIBLEIDS:
143 case CM_DRP_UPPERFILTERS:
144 case CM_DRP_LOWERFILTERS:
145 return REG_MULTI_SZ;
146
147 case CM_DRP_CONFIGFLAGS:
148 case CM_DRP_CAPABILITIES:
149 case CM_DRP_UI_NUMBER:
150 case CM_DRP_LEGACYBUSTYPE:
151 case CM_DRP_BUSNUMBER:
152 case CM_DRP_DEVTYPE:
153 case CM_DRP_EXCLUSIVE:
154 case CM_DRP_CHARACTERISTICS:
155 case CM_DRP_ADDRESS:
156 case CM_DRP_REMOVAL_POLICY:
157 case CM_DRP_REMOVAL_POLICY_HW_DEFAULT:
158 case CM_DRP_REMOVAL_POLICY_OVERRIDE:
159 case CM_DRP_INSTALL_STATE:
160 return REG_DWORD;
161
162 case CM_DRP_BUSTYPEGUID:
163 case CM_DRP_SECURITY:
164 case CM_DRP_DEVICE_POWER_DATA:
165 default:
166 return REG_BINARY;
167 }
168
169 return REG_NONE;
170 }
171
172
173 static
174 VOID
175 SplitDeviceInstanceId(
176 _In_ PWSTR pszDeviceInstanceId,
177 _Out_ PWSTR pszDeviceId,
178 _Out_ PWSTR pszInstanceId)
179 {
180 PWCHAR ptr;
181
182 wcscpy(pszDeviceId, pszDeviceInstanceId);
183
184 ptr = wcschr(pszDeviceId, L'\\');
185 if (ptr != NULL)
186 {
187 *ptr = UNICODE_NULL;
188 ptr++;
189
190 wcscpy(pszInstanceId, ptr);
191 }
192 else
193 {
194 *pszInstanceId = UNICODE_NULL;
195 }
196 }
197
198
199 static
200 CONFIGRET
201 GetDeviceInstanceKeyPath(
202 _In_ RPC_BINDING_HANDLE BindingHandle,
203 _In_ PWSTR pszDeviceInst,
204 _Out_ PWSTR pszKeyPath,
205 _Out_ PWSTR pszInstancePath,
206 _In_ ULONG ulHardwareProfile,
207 _In_ ULONG ulFlags)
208 {
209 PWSTR pszBuffer = NULL;
210 ULONG ulType = 0;
211 ULONG ulTransferLength, ulLength;
212 CONFIGRET ret = CR_SUCCESS;
213
214 TRACE("GetDeviceInstanceKeyPath()\n");
215
216 /* Allocate a buffer for the device id */
217 pszBuffer = MyMalloc(300 * sizeof(WCHAR));
218 if (pszBuffer == NULL)
219 {
220 ERR("MyMalloc() failed\n");
221 return CR_OUT_OF_MEMORY;
222 }
223
224 if (ulFlags & CM_REGISTRY_SOFTWARE)
225 {
226 /* Software Key Path */
227
228 if (ulFlags & CM_REGISTRY_CONFIG)
229 {
230 SplitDeviceInstanceId(pszDeviceInst,
231 pszBuffer,
232 pszInstancePath);
233
234 if (ulHardwareProfile == 0)
235 {
236 wsprintfW(pszKeyPath,
237 L"%s\\%s\\%s\\%s",
238 L"System\\CurrentControlSet\\Hardware Profiles",
239 L"Current",
240 L"System\\CurrentControlSet\\Enum",
241 pszBuffer);
242 }
243 else
244 {
245 wsprintfW(pszKeyPath,
246 L"%s\\%04lu\\%s\\%s",
247 L"System\\CurrentControlSet\\Hardware Profiles",
248 ulHardwareProfile,
249 L"System\\CurrentControlSet\\Enum",
250 pszBuffer);
251 }
252 }
253 else if (ulFlags & CM_REGISTRY_USER)
254 {
255 wsprintfW(pszKeyPath,
256 L"%s\\%s",
257 L"System\\CurrentControlSet\\Enum",
258 pszDeviceInst);
259
260 wcscpy(pszInstancePath,
261 L"Device Parameters");
262 }
263 else
264 {
265 SplitDeviceInstanceId(pszDeviceInst,
266 pszBuffer,
267 pszInstancePath);
268
269 wsprintfW(pszKeyPath,
270 L"%s\\%s",
271 L"System\\CurrentControlSet\\Enum",
272 pszBuffer);
273 }
274 }
275 else
276 {
277 /* Hardware Key Path */
278
279 ulTransferLength = 300 * sizeof(WCHAR);
280 ulLength = 300 * sizeof(WCHAR);
281 ret = PNP_GetDeviceRegProp(BindingHandle,
282 pszDeviceInst,
283 CM_DRP_DRIVER,
284 &ulType,
285 (PVOID)pszBuffer,
286 &ulTransferLength,
287 &ulLength,
288 0);
289 if (ret != CR_SUCCESS)
290 {
291 ERR("PNP_GetDeviceRegProp() failed (Error %lu)\n", ret);
292 goto done;
293 }
294
295 TRACE("szBuffer: %S\n", pszBuffer);
296
297 SplitDeviceInstanceId(pszBuffer,
298 pszBuffer,
299 pszInstancePath);
300
301 TRACE("szBuffer: %S\n", pszBuffer);
302
303 if (ulFlags & CM_REGISTRY_CONFIG)
304 {
305 if (ulHardwareProfile == 0)
306 {
307 wsprintfW(pszKeyPath,
308 L"%s\\%s\\%s\\%s",
309 L"System\\CurrentControlSet\\Hardware Profiles",
310 L"Current",
311 L"System\\CurrentControlSet\\Control\\Class",
312 pszBuffer);
313 }
314 else
315 {
316 wsprintfW(pszKeyPath,
317 L"%s\\%04lu\\%s\\%s",
318 L"System\\CurrentControlSet\\Hardware Profiles",
319 ulHardwareProfile,
320 L"System\\CurrentControlSet\\Control\\Class",
321 pszBuffer);
322 }
323 }
324 else
325 {
326 wsprintfW(pszKeyPath,
327 L"%s\\%s",
328 L"System\\CurrentControlSet\\Control\\Class",
329 pszBuffer);
330 }
331 }
332
333 done:
334 if (pszBuffer != NULL)
335 MyFree(pszBuffer);
336
337 return ret;
338 }
339
340
341 /***********************************************************************
342 * CMP_GetBlockedDriverInfo [SETUPAPI.@]
343 */
344 CONFIGRET
345 WINAPI
346 CMP_GetBlockedDriverInfo(
347 _Out_opt_ LPWSTR pszNames,
348 _Inout_ PULONG pulLength,
349 _In_ ULONG ulFlags,
350 _In_opt_ HMACHINE hMachine)
351 {
352 RPC_BINDING_HANDLE BindingHandle = NULL;
353 ULONG ulTransferLength;
354 CONFIGRET ret;
355
356 TRACE("CMP_GetBlockedDriverInfo(%p %p %lx %p)\n",
357 pszNames, pulLength, ulFlags, hMachine);
358
359 if (hMachine != NULL)
360 {
361 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
362 if (BindingHandle == NULL)
363 return CR_FAILURE;
364 }
365 else
366 {
367 if (!PnpGetLocalHandles(&BindingHandle, NULL))
368 return CR_FAILURE;
369 }
370
371 ulTransferLength = *pulLength;
372
373 RpcTryExcept
374 {
375 ret = PNP_GetBlockedDriverInfo(BindingHandle,
376 (PBYTE)pszNames,
377 &ulTransferLength,
378 pulLength,
379 ulFlags);
380 }
381 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
382 {
383 ret = RpcStatusToCmStatus(RpcExceptionCode());
384 }
385 RpcEndExcept;
386
387 return ret;
388 }
389
390
391 /***********************************************************************
392 * CMP_GetServerSideDeviceInstallFlags [SETUPAPI.@]
393 */
394 CONFIGRET
395 WINAPI
396 CMP_GetServerSideDeviceInstallFlags(
397 _Out_ PULONG pulSSDIFlags,
398 _In_ ULONG ulFlags,
399 _In_opt_ HMACHINE hMachine)
400 {
401 RPC_BINDING_HANDLE BindingHandle = NULL;
402 CONFIGRET ret;
403
404 TRACE("CMP_GetServerSideDeviceInstallFlags(%p %lx %p)\n",
405 pulSSDIFlags, ulFlags, hMachine);
406
407 if (pulSSDIFlags == NULL)
408 return CR_INVALID_POINTER;
409
410 if (ulFlags != 0)
411 return CR_INVALID_FLAG;
412
413 if (hMachine != NULL)
414 {
415 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
416 if (BindingHandle == NULL)
417 return CR_FAILURE;
418 }
419 else
420 {
421 if (!PnpGetLocalHandles(&BindingHandle, NULL))
422 return CR_FAILURE;
423 }
424
425 RpcTryExcept
426 {
427 ret = PNP_GetServerSideDeviceInstallFlags(BindingHandle,
428 pulSSDIFlags,
429 ulFlags);
430 }
431 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
432 {
433 ret = RpcStatusToCmStatus(RpcExceptionCode());
434 }
435 RpcEndExcept;
436
437 return ret;
438 }
439
440
441 /***********************************************************************
442 * CMP_Init_Detection [SETUPAPI.@]
443 */
444 CONFIGRET
445 WINAPI
446 CMP_Init_Detection(
447 _In_ ULONG ulMagic)
448 {
449 RPC_BINDING_HANDLE BindingHandle = NULL;
450 CONFIGRET ret;
451
452 TRACE("CMP_Init_Detection(%lu)\n", ulMagic);
453
454 if (ulMagic != CMP_MAGIC)
455 return CR_INVALID_DATA;
456
457 if (!PnpGetLocalHandles(&BindingHandle, NULL))
458 return CR_FAILURE;
459
460 RpcTryExcept
461 {
462 ret = PNP_InitDetection(BindingHandle);
463 }
464 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
465 {
466 ret = RpcStatusToCmStatus(RpcExceptionCode());
467 }
468 RpcEndExcept;
469
470 return ret;
471 }
472
473
474 /***********************************************************************
475 * CMP_RegisterNotification [SETUPAPI.@]
476 */
477 CONFIGRET
478 WINAPI
479 CMP_RegisterNotification(
480 _In_ HANDLE hRecipient,
481 _In_ LPVOID lpvNotificationFilter,
482 _In_ ULONG ulFlags,
483 _Out_ PHDEVNOTIFY phDevNotify)
484 {
485 RPC_BINDING_HANDLE BindingHandle = NULL;
486 PNOTIFY_DATA pNotifyData = NULL;
487 CONFIGRET ret = CR_SUCCESS;
488
489 TRACE("CMP_RegisterNotification(%p %p %lu %p)\n",
490 hRecipient, lpvNotificationFilter, ulFlags, phDevNotify);
491
492 if ((hRecipient == NULL) ||
493 (lpvNotificationFilter == NULL) ||
494 (phDevNotify == NULL))
495 return CR_INVALID_POINTER;
496
497 if (ulFlags & ~0x7)
498 return CR_INVALID_FLAG;
499
500 if (((PDEV_BROADCAST_HDR)lpvNotificationFilter)->dbch_size < sizeof(DEV_BROADCAST_HDR))
501 return CR_INVALID_DATA;
502
503 if (!PnpGetLocalHandles(&BindingHandle, NULL))
504 return CR_FAILURE;
505
506 pNotifyData = HeapAlloc(GetProcessHeap(),
507 HEAP_ZERO_MEMORY,
508 sizeof(NOTIFY_DATA));
509 if (pNotifyData == NULL)
510 return CR_OUT_OF_MEMORY;
511
512 pNotifyData->ulMagic = NOTIFY_MAGIC;
513
514 /*
515 if (dwFlags & DEVICE_NOTIFY_SERVICE_HANDLE == DEVICE_NOTYFY_WINDOW_HANDLE)
516 {
517
518 }
519 else if (dwFlags & DEVICE_NOTIFY_SERVICE_HANDLE == DEVICE_NOTYFY_SERVICE_HANDLE)
520 {
521
522 }
523 */
524
525 RpcTryExcept
526 {
527 ret = PNP_RegisterNotification(BindingHandle,
528 ulFlags,
529 &pNotifyData->ulNotifyData);
530 }
531 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
532 {
533 ret = RpcStatusToCmStatus(RpcExceptionCode());
534 }
535 RpcEndExcept;
536
537 if (ret == CR_SUCCESS)
538 {
539 *phDevNotify = (HDEVNOTIFY)pNotifyData;
540 }
541 else
542 {
543 if (pNotifyData != NULL)
544 HeapFree(GetProcessHeap(), 0, pNotifyData);
545
546 *phDevNotify = (HDEVNOTIFY)NULL;
547 }
548
549 return ret;
550 }
551
552
553 /***********************************************************************
554 * CMP_Report_LogOn [SETUPAPI.@]
555 */
556 CONFIGRET
557 WINAPI
558 CMP_Report_LogOn(
559 _In_ DWORD dwMagic,
560 _In_ DWORD dwProcessId)
561 {
562 RPC_BINDING_HANDLE BindingHandle = NULL;
563 CONFIGRET ret = CR_SUCCESS;
564 BOOL bAdmin;
565 DWORD i;
566
567 TRACE("CMP_Report_LogOn(%lu %lu)\n", dwMagic, dwProcessId);
568
569 if (dwMagic != CMP_MAGIC)
570 return CR_INVALID_DATA;
571
572 if (!PnpGetLocalHandles(&BindingHandle, NULL))
573 return CR_FAILURE;
574
575 bAdmin = pSetupIsUserAdmin();
576
577 for (i = 0; i < 30; i++)
578 {
579 RpcTryExcept
580 {
581 ret = PNP_ReportLogOn(BindingHandle,
582 bAdmin,
583 dwProcessId);
584 }
585 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
586 {
587 ret = RpcStatusToCmStatus(RpcExceptionCode());
588 }
589 RpcEndExcept;
590
591 if (ret == CR_SUCCESS)
592 break;
593
594 Sleep(5000);
595 }
596
597 return ret;
598 }
599
600
601 /***********************************************************************
602 * CMP_UnregisterNotification [SETUPAPI.@]
603 */
604 CONFIGRET
605 WINAPI
606 CMP_UnregisterNotification(
607 _In_ HDEVNOTIFY hDevNotify)
608 {
609 RPC_BINDING_HANDLE BindingHandle = NULL;
610 PNOTIFY_DATA pNotifyData;
611 CONFIGRET ret = CR_SUCCESS;
612
613 TRACE("CMP_UnregisterNotification(%p)\n", hDevNotify);
614
615 pNotifyData = (PNOTIFY_DATA)hDevNotify;
616
617 if ((pNotifyData == NULL) ||
618 (pNotifyData->ulMagic != NOTIFY_MAGIC))
619 return CR_INVALID_POINTER;
620
621 if (!PnpGetLocalHandles(&BindingHandle, NULL))
622 return CR_FAILURE;
623
624 RpcTryExcept
625 {
626 ret = PNP_UnregisterNotification(BindingHandle,
627 pNotifyData->ulNotifyData);
628 }
629 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
630 {
631 ret = RpcStatusToCmStatus(RpcExceptionCode());
632 }
633 RpcEndExcept;
634
635 if (ret == CR_SUCCESS)
636 HeapFree(GetProcessHeap(), 0, pNotifyData);
637
638 return ret;
639 }
640
641
642 /***********************************************************************
643 * CMP_WaitNoPendingInstallEvents [SETUPAPI.@]
644 */
645 DWORD
646 WINAPI
647 CMP_WaitNoPendingInstallEvents(
648 _In_ DWORD dwTimeout)
649 {
650 HANDLE hEvent;
651 DWORD ret;
652
653 TRACE("CMP_WaitNoPendingInstallEvents(%lu)\n", dwTimeout);
654
655 hEvent = OpenEventW(SYNCHRONIZE, FALSE, L"Global\\PnP_No_Pending_Install_Events");
656 if (hEvent == NULL)
657 return WAIT_FAILED;
658
659 ret = WaitForSingleObject(hEvent, dwTimeout);
660 CloseHandle(hEvent);
661 return ret;
662 }
663
664
665 /***********************************************************************
666 * CMP_WaitServicesAvailable [SETUPAPI.@]
667 */
668 CONFIGRET
669 WINAPI
670 CMP_WaitServicesAvailable(
671 _In_opt_ HMACHINE hMachine)
672 {
673 RPC_BINDING_HANDLE BindingHandle = NULL;
674 CONFIGRET ret = CR_SUCCESS;
675 WORD Version;
676
677 TRACE("CMP_WaitServicesAvailable(%p)\n", hMachine);
678
679 if (hMachine != NULL)
680 {
681 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
682 if (BindingHandle == NULL)
683 return CR_FAILURE;
684 }
685 else
686 {
687 if (!PnpGetLocalHandles(&BindingHandle, NULL))
688 return CR_FAILURE;
689 }
690
691 RpcTryExcept
692 {
693 ret = PNP_GetVersion(BindingHandle, &Version);
694 }
695 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
696 {
697 ret = RpcStatusToCmStatus(RpcExceptionCode());
698 }
699 RpcEndExcept;
700
701 return ret;
702 }
703
704
705 /***********************************************************************
706 * CM_Add_Empty_Log_Conf [SETUPAPI.@]
707 */
708 CONFIGRET
709 WINAPI
710 CM_Add_Empty_Log_Conf(
711 _Out_ PLOG_CONF plcLogConf,
712 _In_ DEVINST dnDevInst,
713 _In_ PRIORITY Priority,
714 _In_ ULONG ulFlags)
715 {
716 TRACE("CM_Add_Empty_Log_Conf(%p %p %lu %lx)\n",
717 plcLogConf, dnDevInst, Priority, ulFlags);
718 return CM_Add_Empty_Log_Conf_Ex(plcLogConf, dnDevInst, Priority,
719 ulFlags, NULL);
720 }
721
722
723 /***********************************************************************
724 * CM_Add_Empty_Log_Conf_Ex [SETUPAPI.@]
725 */
726 CONFIGRET
727 WINAPI CM_Add_Empty_Log_Conf_Ex(
728 _Out_ PLOG_CONF plcLogConf,
729 _In_ DEVINST dnDevInst,
730 _In_ PRIORITY Priority,
731 _In_ ULONG ulFlags,
732 _In_opt_ HMACHINE hMachine)
733 {
734 RPC_BINDING_HANDLE BindingHandle = NULL;
735 HSTRING_TABLE StringTable = NULL;
736 ULONG ulLogConfTag = 0;
737 LPWSTR lpDevInst;
738 PLOG_CONF_INFO pLogConfInfo;
739 CONFIGRET ret = CR_SUCCESS;
740
741 FIXME("CM_Add_Empty_Log_Conf_Ex(%p %p %lu %lx %p)\n",
742 plcLogConf, dnDevInst, Priority, ulFlags, hMachine);
743
744 if (!pSetupIsUserAdmin())
745 return CR_ACCESS_DENIED;
746
747 if (plcLogConf == NULL)
748 return CR_INVALID_POINTER;
749
750 if (dnDevInst == 0)
751 return CR_INVALID_DEVINST;
752
753 if (Priority > 0xFFFF)
754 return CR_INVALID_PRIORITY;
755
756 if (ulFlags & ~(LOG_CONF_BITS | PRIORITY_BIT))
757 return CR_INVALID_FLAG;
758
759 if (hMachine != NULL)
760 {
761 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
762 if (BindingHandle == NULL)
763 return CR_FAILURE;
764
765 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
766 if (StringTable == 0)
767 return CR_FAILURE;
768 }
769 else
770 {
771 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
772 return CR_FAILURE;
773 }
774
775 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
776 if (lpDevInst == NULL)
777 return CR_INVALID_DEVNODE;
778
779 RpcTryExcept
780 {
781 ret = PNP_AddEmptyLogConf(BindingHandle, lpDevInst, Priority,
782 &ulLogConfTag, ulFlags);
783 }
784 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
785 {
786 ret = RpcStatusToCmStatus(RpcExceptionCode());
787 }
788 RpcEndExcept;
789
790 if (ret == CR_SUCCESS)
791 {
792 pLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
793 if (pLogConfInfo == NULL)
794 {
795 ret = CR_OUT_OF_MEMORY;
796 }
797 else
798 {
799 pLogConfInfo->ulMagic = LOG_CONF_MAGIC;
800 pLogConfInfo->dnDevInst = dnDevInst;
801 pLogConfInfo->ulFlags = ulFlags;
802 pLogConfInfo->ulTag = ulLogConfTag;
803
804 *plcLogConf = (LOG_CONF)pLogConfInfo;
805
806 ret = CR_SUCCESS;
807 }
808 }
809
810 return ret;
811 }
812
813
814 /***********************************************************************
815 * CM_Add_IDA [SETUPAPI.@]
816 */
817 CONFIGRET
818 WINAPI
819 CM_Add_IDA(
820 _In_ DEVINST dnDevInst,
821 _In_ PSTR pszID,
822 _In_ ULONG ulFlags)
823 {
824 TRACE("CM_Add_IDA(%p %s %lx)\n",
825 dnDevInst, pszID, ulFlags);
826 return CM_Add_ID_ExA(dnDevInst, pszID, ulFlags, NULL);
827 }
828
829
830 /***********************************************************************
831 * CM_Add_IDW [SETUPAPI.@]
832 */
833 CONFIGRET
834 WINAPI
835 CM_Add_IDW(
836 _In_ DEVINST dnDevInst,
837 _In_ PWSTR pszID,
838 _In_ ULONG ulFlags)
839 {
840 TRACE("CM_Add_IDW(%p %s %lx)\n",
841 dnDevInst, debugstr_w(pszID), ulFlags);
842 return CM_Add_ID_ExW(dnDevInst, pszID, ulFlags, NULL);
843 }
844
845
846 /***********************************************************************
847 * CM_Add_ID_ExA [SETUPAPI.@]
848 */
849 CONFIGRET
850 WINAPI
851 CM_Add_ID_ExA(
852 _In_ DEVINST dnDevInst,
853 _In_ PSTR pszID,
854 _In_ ULONG ulFlags,
855 _In_opt_ HMACHINE hMachine)
856 {
857 PWSTR pszIDW;
858 CONFIGRET ret;
859
860 TRACE("CM_Add_ID_ExA(%p %s %lx %p)\n",
861 dnDevInst, pszID, ulFlags, hMachine);
862
863 if (pSetupCaptureAndConvertAnsiArg(pszID, &pszIDW))
864 return CR_INVALID_DATA;
865
866 ret = CM_Add_ID_ExW(dnDevInst, pszIDW, ulFlags, hMachine);
867
868 MyFree(pszIDW);
869
870 return ret;
871 }
872
873
874 /***********************************************************************
875 * CM_Add_ID_ExW [SETUPAPI.@]
876 */
877 CONFIGRET
878 WINAPI
879 CM_Add_ID_ExW(
880 _In_ DEVINST dnDevInst,
881 _In_ PWSTR pszID,
882 _In_ ULONG ulFlags,
883 _In_opt_ HMACHINE hMachine)
884 {
885 RPC_BINDING_HANDLE BindingHandle = NULL;
886 HSTRING_TABLE StringTable = NULL;
887 LPWSTR lpDevInst;
888 CONFIGRET ret;
889
890 TRACE("CM_Add_ID_ExW(%p %s %lx %p)\n",
891 dnDevInst, debugstr_w(pszID), ulFlags, hMachine);
892
893 if (!pSetupIsUserAdmin())
894 return CR_ACCESS_DENIED;
895
896 if (dnDevInst == 0)
897 return CR_INVALID_DEVINST;
898
899 if (pszID == NULL)
900 return CR_INVALID_POINTER;
901
902 if (ulFlags & ~CM_ADD_ID_BITS)
903 return CR_INVALID_FLAG;
904
905 if (hMachine != NULL)
906 {
907 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
908 if (BindingHandle == NULL)
909 return CR_FAILURE;
910
911 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
912 if (StringTable == 0)
913 return CR_FAILURE;
914 }
915 else
916 {
917 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
918 return CR_FAILURE;
919 }
920
921 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
922 if (lpDevInst == NULL)
923 return CR_INVALID_DEVNODE;
924
925 RpcTryExcept
926 {
927 ret = PNP_AddID(BindingHandle,
928 lpDevInst,
929 pszID,
930 ulFlags);
931 }
932 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
933 {
934 ret = RpcStatusToCmStatus(RpcExceptionCode());
935 }
936 RpcEndExcept;
937
938 return ret;
939 }
940
941
942 /***********************************************************************
943 * CM_Add_Range [SETUPAPI.@]
944 */
945 CONFIGRET
946 WINAPI
947 CM_Add_Range(
948 _In_ DWORDLONG ullStartValue,
949 _In_ DWORDLONG ullEndValue,
950 _In_ RANGE_LIST rlh,
951 _In_ ULONG ulFlags)
952 {
953 FIXME("CM_Add_Range(%I64u %I64u %p %lx)\n",
954 ullStartValue, ullEndValue, rlh, ulFlags);
955 return CR_CALL_NOT_IMPLEMENTED;
956 }
957
958
959 /***********************************************************************
960 * CM_Add_Res_Des [SETUPAPI.@]
961 */
962 CONFIGRET
963 WINAPI
964 CM_Add_Res_Des(
965 _Out_opt_ PRES_DES prdResDes,
966 _In_ LOG_CONF lcLogConf,
967 _In_ RESOURCEID ResourceID,
968 _In_ PCVOID ResourceData,
969 _In_ ULONG ResourceLen,
970 _In_ ULONG ulFlags)
971 {
972 TRACE("CM_Add_Res_Des(%p %p %lu %p %lu %lx)\n",
973 prdResDes, lcLogConf, ResourceID, ResourceData, ResourceLen, ulFlags);
974 return CM_Add_Res_Des_Ex(prdResDes, lcLogConf, ResourceID, ResourceData,
975 ResourceLen, ulFlags, NULL);
976 }
977
978
979 /***********************************************************************
980 * CM_Add_Res_Des_Ex [SETUPAPI.@]
981 */
982 CONFIGRET
983 WINAPI
984 CM_Add_Res_Des_Ex(
985 _Out_opt_ PRES_DES prdResDes,
986 _In_ LOG_CONF lcLogConf,
987 _In_ RESOURCEID ResourceID,
988 _In_ PCVOID ResourceData,
989 _In_ ULONG ResourceLen,
990 _In_ ULONG ulFlags,
991 _In_opt_ HMACHINE hMachine)
992 {
993 FIXME("CM_Add_Res_Des_Ex(%p %p %lu %p %lu %lx %p)\n",
994 prdResDes, lcLogConf, ResourceID,
995 ResourceData, ResourceLen, ulFlags, hMachine);
996
997 return CR_CALL_NOT_IMPLEMENTED;
998 }
999
1000
1001 /***********************************************************************
1002 * CM_Connect_MachineA [SETUPAPI.@]
1003 */
1004 CONFIGRET
1005 WINAPI
1006 CM_Connect_MachineA(
1007 _In_opt_ PCSTR UNCServerName,
1008 _Out_ PHMACHINE phMachine)
1009 {
1010 PWSTR pServerNameW;
1011 CONFIGRET ret;
1012
1013 TRACE("CM_Connect_MachineA(%s %p)\n",
1014 UNCServerName, phMachine);
1015
1016 if (UNCServerName == NULL || *UNCServerName == 0)
1017 return CM_Connect_MachineW(NULL, phMachine);
1018
1019 if (pSetupCaptureAndConvertAnsiArg(UNCServerName, &pServerNameW))
1020 return CR_INVALID_DATA;
1021
1022 ret = CM_Connect_MachineW(pServerNameW, phMachine);
1023
1024 MyFree(pServerNameW);
1025
1026 return ret;
1027 }
1028
1029
1030 /***********************************************************************
1031 * CM_Connect_MachineW [SETUPAPI.@]
1032 */
1033 CONFIGRET
1034 WINAPI
1035 CM_Connect_MachineW(
1036 _In_opt_ PCWSTR UNCServerName,
1037 _Out_ PHMACHINE phMachine)
1038 {
1039 PMACHINE_INFO pMachine;
1040
1041 TRACE("CM_Connect_MachineW(%s %p)\n",
1042 debugstr_w(UNCServerName), phMachine);
1043
1044 if (phMachine == NULL)
1045 return CR_INVALID_POINTER;
1046
1047 *phMachine = NULL;
1048
1049 pMachine = HeapAlloc(GetProcessHeap(), 0, sizeof(MACHINE_INFO));
1050 if (pMachine == NULL)
1051 return CR_OUT_OF_MEMORY;
1052
1053 if (UNCServerName == NULL || *UNCServerName == 0)
1054 {
1055 pMachine->bLocal = TRUE;
1056
1057 /* FIXME: store the computers name in pMachine->szMachineName */
1058
1059 if (!PnpGetLocalHandles(&pMachine->BindingHandle,
1060 &pMachine->StringTable))
1061 {
1062 HeapFree(GetProcessHeap(), 0, pMachine);
1063 return CR_FAILURE;
1064 }
1065 }
1066 else
1067 {
1068 pMachine->bLocal = FALSE;
1069 if (wcslen(UNCServerName) >= SP_MAX_MACHINENAME_LENGTH - 1)
1070 {
1071 HeapFree(GetProcessHeap(), 0, pMachine);
1072 return CR_INVALID_MACHINENAME;
1073 }
1074 lstrcpyW(pMachine->szMachineName, UNCServerName);
1075
1076 pMachine->StringTable = pSetupStringTableInitialize();
1077 if (pMachine->StringTable == NULL)
1078 {
1079 HeapFree(GetProcessHeap(), 0, pMachine);
1080 return CR_FAILURE;
1081 }
1082
1083 pSetupStringTableAddString(pMachine->StringTable, L"PLT", 1);
1084
1085 if (!PnpBindRpc(UNCServerName, &pMachine->BindingHandle))
1086 {
1087 pSetupStringTableDestroy(pMachine->StringTable);
1088 HeapFree(GetProcessHeap(), 0, pMachine);
1089 return CR_INVALID_MACHINENAME;
1090 }
1091 }
1092
1093 *phMachine = (PHMACHINE)pMachine;
1094
1095 return CR_SUCCESS;
1096 }
1097
1098
1099 /***********************************************************************
1100 * CM_Create_DevNodeA [SETUPAPI.@]
1101 */
1102 CONFIGRET
1103 WINAPI
1104 CM_Create_DevNodeA(
1105 _Out_ PDEVINST pdnDevInst,
1106 _In_ DEVINSTID_A pDeviceID,
1107 _In_ DEVINST dnParent,
1108 _In_ ULONG ulFlags)
1109 {
1110 TRACE("CM_Create_DevNodeA(%p %s %p %lx)\n",
1111 pdnDevInst, debugstr_a(pDeviceID), dnParent, ulFlags);
1112 return CM_Create_DevNode_ExA(pdnDevInst, pDeviceID, dnParent,
1113 ulFlags, NULL);
1114 }
1115
1116
1117 /***********************************************************************
1118 * CM_Create_DevNodeW [SETUPAPI.@]
1119 */
1120 CONFIGRET
1121 WINAPI
1122 CM_Create_DevNodeW(
1123 _Out_ PDEVINST pdnDevInst,
1124 _In_ DEVINSTID_W pDeviceID,
1125 _In_ DEVINST dnParent,
1126 _In_ ULONG ulFlags)
1127 {
1128 TRACE("CM_Create_DevNodeW(%p %s %p %lx)\n",
1129 pdnDevInst, debugstr_w(pDeviceID), dnParent, ulFlags);
1130 return CM_Create_DevNode_ExW(pdnDevInst, pDeviceID, dnParent,
1131 ulFlags, NULL);
1132 }
1133
1134
1135 /***********************************************************************
1136 * CM_Create_DevNode_ExA [SETUPAPI.@]
1137 */
1138 CONFIGRET
1139 WINAPI
1140 CM_Create_DevNode_ExA(
1141 _Out_ PDEVINST pdnDevInst,
1142 _In_ DEVINSTID_A pDeviceID,
1143 _In_ DEVINST dnParent,
1144 _In_ ULONG ulFlags,
1145 _In_opt_ HANDLE hMachine)
1146 {
1147 DEVINSTID_W pDeviceIDW;
1148 CONFIGRET ret;
1149
1150 TRACE("CM_Create_DevNode_ExA(%p %s %p %lx %p)\n",
1151 pdnDevInst, debugstr_a(pDeviceID), dnParent, ulFlags, hMachine);
1152
1153 if (pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDeviceIDW))
1154 return CR_INVALID_DATA;
1155
1156 ret = CM_Create_DevNode_ExW(pdnDevInst, pDeviceIDW, dnParent, ulFlags,
1157 hMachine);
1158
1159 MyFree(pDeviceIDW);
1160
1161 return ret;
1162 }
1163
1164
1165 /***********************************************************************
1166 * CM_Create_DevNode_ExW [SETUPAPI.@]
1167 */
1168 CONFIGRET
1169 WINAPI
1170 CM_Create_DevNode_ExW(
1171 _Out_ PDEVINST pdnDevInst,
1172 _In_ DEVINSTID_W pDeviceID,
1173 _In_ DEVINST dnParent,
1174 _In_ ULONG ulFlags,
1175 _In_opt_ HANDLE hMachine)
1176 {
1177 RPC_BINDING_HANDLE BindingHandle = NULL;
1178 HSTRING_TABLE StringTable = NULL;
1179 LPWSTR lpParentDevInst;
1180 CONFIGRET ret = CR_SUCCESS;
1181 WCHAR szLocalDeviceID[MAX_DEVICE_ID_LEN];
1182
1183 TRACE("CM_Create_DevNode_ExW(%p %s %p %lx %p)\n",
1184 pdnDevInst, debugstr_w(pDeviceID), dnParent, ulFlags, hMachine);
1185
1186 if (!pSetupIsUserAdmin())
1187 return CR_ACCESS_DENIED;
1188
1189 if (pdnDevInst == NULL)
1190 return CR_INVALID_POINTER;
1191
1192 if (pDeviceID == NULL || wcslen(pDeviceID) == 0 || wcslen(pDeviceID) >= MAX_DEVICE_ID_LEN)
1193 return CR_INVALID_DEVICE_ID;
1194
1195 if (dnParent == 0)
1196 return CR_INVALID_DEVNODE;
1197
1198 if (ulFlags & ~CM_CREATE_DEVNODE_BITS)
1199 return CR_INVALID_FLAG;
1200
1201 if (hMachine != NULL)
1202 {
1203 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1204 if (BindingHandle == NULL)
1205 return CR_FAILURE;
1206
1207 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1208 if (StringTable == 0)
1209 return CR_FAILURE;
1210 }
1211 else
1212 {
1213 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1214 return CR_FAILURE;
1215 }
1216
1217 lpParentDevInst = pSetupStringTableStringFromId(StringTable, dnParent);
1218 if (lpParentDevInst == NULL)
1219 return CR_INVALID_DEVNODE;
1220
1221 wcscpy(szLocalDeviceID, pDeviceID);
1222
1223 RpcTryExcept
1224 {
1225 ret = PNP_CreateDevInst(BindingHandle,
1226 szLocalDeviceID,
1227 lpParentDevInst,
1228 MAX_DEVICE_ID_LEN,
1229 ulFlags);
1230 }
1231 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1232 {
1233 ret = RpcStatusToCmStatus(RpcExceptionCode());
1234 }
1235 RpcEndExcept;
1236
1237 if (ret == CR_SUCCESS)
1238 {
1239 /* If CM_CREATE_DEVINST_GENERATE_ID was passed in, PNP_CreateDevInst
1240 * will return the generated device ID in szLocalDeviceID */
1241 *pdnDevInst = pSetupStringTableAddString(StringTable, szLocalDeviceID, 1);
1242 if (*pdnDevInst == 0)
1243 ret = CR_NO_SUCH_DEVNODE;
1244 }
1245
1246 return ret;
1247 }
1248
1249
1250 /***********************************************************************
1251 * CM_Create_Range_List [SETUPAPI.@]
1252 */
1253 CONFIGRET
1254 WINAPI
1255 CM_Create_Range_List(
1256 _Out_ PRANGE_LIST prlh,
1257 _In_ ULONG ulFlags)
1258 {
1259 PINTERNAL_RANGE_LIST pRangeList = NULL;
1260
1261 FIXME("CM_Create_Range_List(%p %lx)\n", prlh, ulFlags);
1262
1263 if (ulFlags != 0)
1264 return CR_INVALID_FLAG;
1265
1266 if (prlh == NULL)
1267 return CR_INVALID_POINTER;
1268
1269 pRangeList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(INTERNAL_RANGE_LIST));
1270 if (pRangeList == NULL)
1271 return CR_OUT_OF_MEMORY;
1272
1273 pRangeList->ulMagic = RANGE_LIST_MAGIC;
1274
1275 // TODO: More initialization
1276
1277 *prlh = (RANGE_LIST)pRangeList;
1278
1279 return CR_SUCCESS;
1280 }
1281
1282
1283 /***********************************************************************
1284 * CM_Delete_Class_Key [SETUPAPI.@]
1285 */
1286 CONFIGRET
1287 WINAPI
1288 CM_Delete_Class_Key(
1289 _In_ LPGUID ClassGuid,
1290 _In_ ULONG ulFlags)
1291 {
1292 TRACE("CM_Delete_Class_Key(%p %lx)\n",
1293 ClassGuid, ulFlags);
1294 return CM_Delete_Class_Key_Ex(ClassGuid, ulFlags, NULL);
1295 }
1296
1297
1298 /***********************************************************************
1299 * CM_Delete_Class_Key_Ex [SETUPAPI.@]
1300 */
1301 CONFIGRET
1302 WINAPI
1303 CM_Delete_Class_Key_Ex(
1304 _In_ LPGUID ClassGuid,
1305 _In_ ULONG ulFlags,
1306 _In_opt_ HANDLE hMachine)
1307 {
1308 WCHAR szGuidString[MAX_GUID_STRING_LEN];
1309 RPC_BINDING_HANDLE BindingHandle = NULL;
1310 CONFIGRET ret;
1311
1312 TRACE("CM_Delete_Class_Key_Ex(%p %lx %lx)\n",
1313 ClassGuid, ulFlags, hMachine);
1314
1315 if (ClassGuid == NULL)
1316 return CR_INVALID_POINTER;
1317
1318 if (ulFlags & ~CM_DELETE_CLASS_BITS)
1319 return CR_INVALID_FLAG;
1320
1321 if (!GuidToString(ClassGuid, szGuidString))
1322 return CR_INVALID_DATA;
1323
1324 if (hMachine != NULL)
1325 {
1326 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1327 if (BindingHandle == NULL)
1328 return CR_FAILURE;
1329 }
1330 else
1331 {
1332 if (!PnpGetLocalHandles(&BindingHandle, NULL))
1333 return CR_FAILURE;
1334 }
1335
1336 RpcTryExcept
1337 {
1338 ret = PNP_DeleteClassKey(BindingHandle,
1339 szGuidString,
1340 ulFlags);
1341 }
1342 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1343 {
1344 ret = RpcStatusToCmStatus(RpcExceptionCode());
1345 }
1346 RpcEndExcept;
1347
1348 return ret;
1349 }
1350
1351
1352 /***********************************************************************
1353 * CM_Delete_DevNode_Key [SETUPAPI.@]
1354 */
1355 CONFIGRET
1356 WINAPI
1357 CM_Delete_DevNode_Key(
1358 _In_ DEVNODE dnDevNode,
1359 _In_ ULONG ulHardwareProfile,
1360 _In_ ULONG ulFlags)
1361 {
1362 TRACE("CM_Delete_DevNode_Key(%p %lu %lx)\n",
1363 dnDevNode, ulHardwareProfile, ulFlags);
1364 return CM_Delete_DevNode_Key_Ex(dnDevNode, ulHardwareProfile, ulFlags,
1365 NULL);
1366 }
1367
1368
1369 /***********************************************************************
1370 * CM_Delete_DevNode_Key_Ex [SETUPAPI.@]
1371 */
1372 CONFIGRET
1373 WINAPI
1374 CM_Delete_DevNode_Key_Ex(
1375 _In_ DEVNODE dnDevNode,
1376 _In_ ULONG ulHardwareProfile,
1377 _In_ ULONG ulFlags,
1378 _In_opt_ HANDLE hMachine)
1379 {
1380 FIXME("CM_Delete_DevNode_Key_Ex(%p %lu %lx %p)\n",
1381 dnDevNode, ulHardwareProfile, ulFlags, hMachine);
1382
1383 return CR_CALL_NOT_IMPLEMENTED;
1384 }
1385
1386
1387 /***********************************************************************
1388 * CM_Delete_Range [SETUPAPI.@]
1389 */
1390 CONFIGRET
1391 WINAPI
1392 CM_Delete_Range(
1393 _In_ DWORDLONG ullStartValue,
1394 _In_ DWORDLONG ullEndValue,
1395 _In_ RANGE_LIST rlh,
1396 _In_ ULONG ulFlags)
1397 {
1398 FIXME("CM_Delete_Range(%I64u %I64u %p %lx)\n",
1399 ullStartValue, ullEndValue, rlh, ulFlags);
1400 return CR_CALL_NOT_IMPLEMENTED;
1401 }
1402
1403
1404 /***********************************************************************
1405 * CM_Disable_DevNode [SETUPAPI.@]
1406 */
1407 CONFIGRET WINAPI CM_Disable_DevNode(
1408 DEVINST dnDevInst, ULONG ulFlags)
1409 {
1410 TRACE("%p %lx\n", dnDevInst, ulFlags);
1411 return CM_Disable_DevNode_Ex(dnDevInst, ulFlags, NULL);
1412 }
1413
1414
1415 /***********************************************************************
1416 * CM_Disable_DevNode_Ex [SETUPAPI.@]
1417 */
1418 CONFIGRET WINAPI CM_Disable_DevNode_Ex(
1419 DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
1420 {
1421 RPC_BINDING_HANDLE BindingHandle = NULL;
1422 HSTRING_TABLE StringTable = NULL;
1423 LPWSTR lpDevInst;
1424 CONFIGRET ret;
1425
1426 FIXME("%p %lx %p\n", dnDevInst, ulFlags, hMachine);
1427
1428 if (!pSetupIsUserAdmin())
1429 return CR_ACCESS_DENIED;
1430
1431 if (dnDevInst == 0)
1432 return CR_INVALID_DEVINST;
1433
1434 if (ulFlags != 0)
1435 return CR_INVALID_FLAG;
1436
1437 if (hMachine != NULL)
1438 {
1439 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1440 if (BindingHandle == NULL)
1441 return CR_FAILURE;
1442
1443 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1444 if (StringTable == 0)
1445 return CR_FAILURE;
1446 }
1447 else
1448 {
1449 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1450 return CR_FAILURE;
1451 }
1452
1453 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1454 if (lpDevInst == NULL)
1455 return CR_INVALID_DEVNODE;
1456
1457 RpcTryExcept
1458 {
1459 ret = PNP_DeviceInstanceAction(BindingHandle,
1460 PNP_DEVINST_DISABLE,
1461 ulFlags,
1462 lpDevInst,
1463 NULL);
1464 }
1465 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1466 {
1467 ret = RpcStatusToCmStatus(RpcExceptionCode());
1468 }
1469 RpcEndExcept;
1470
1471 return ret;
1472 }
1473
1474
1475 /***********************************************************************
1476 * CM_Disconnect_Machine [SETUPAPI.@]
1477 */
1478 CONFIGRET WINAPI CM_Disconnect_Machine(HMACHINE hMachine)
1479 {
1480 PMACHINE_INFO pMachine;
1481
1482 TRACE("%lx\n", hMachine);
1483
1484 pMachine = (PMACHINE_INFO)hMachine;
1485 if (pMachine == NULL)
1486 return CR_SUCCESS;
1487
1488 if (pMachine->bLocal == FALSE)
1489 {
1490 if (pMachine->StringTable != NULL)
1491 pSetupStringTableDestroy(pMachine->StringTable);
1492
1493 if (!PnpUnbindRpc(pMachine->BindingHandle))
1494 return CR_ACCESS_DENIED;
1495 }
1496
1497 HeapFree(GetProcessHeap(), 0, pMachine);
1498
1499 return CR_SUCCESS;
1500 }
1501
1502
1503 /***********************************************************************
1504 * CM_Dup_Range_List [SETUPAPI.@]
1505 */
1506 CONFIGRET
1507 WINAPI
1508 CM_Dup_Range_List(
1509 _In_ RANGE_LIST rlhOld,
1510 _In_ RANGE_LIST rlhNew,
1511 _In_ ULONG ulFlags)
1512 {
1513 FIXME("CM_Dup_Range_List(%p %p %lx)\n",
1514 rlhOld, rlhNew, ulFlags);
1515 return CR_CALL_NOT_IMPLEMENTED;
1516 }
1517
1518
1519 /***********************************************************************
1520 * CM_Enable_DevNode [SETUPAPI.@]
1521 */
1522 CONFIGRET WINAPI CM_Enable_DevNode(
1523 DEVINST dnDevInst, ULONG ulFlags)
1524 {
1525 TRACE("%p %lx\n", dnDevInst, ulFlags);
1526 return CM_Enable_DevNode_Ex(dnDevInst, ulFlags, NULL);
1527 }
1528
1529
1530 /***********************************************************************
1531 * CM_Enable_DevNode_Ex [SETUPAPI.@]
1532 */
1533 CONFIGRET WINAPI CM_Enable_DevNode_Ex(
1534 DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
1535 {
1536 RPC_BINDING_HANDLE BindingHandle = NULL;
1537 HSTRING_TABLE StringTable = NULL;
1538 LPWSTR lpDevInst;
1539 CONFIGRET ret;
1540
1541 TRACE("%p %lx %p\n", dnDevInst, ulFlags, hMachine);
1542
1543 if (!pSetupIsUserAdmin())
1544 return CR_ACCESS_DENIED;
1545
1546 if (dnDevInst == 0)
1547 return CR_INVALID_DEVINST;
1548
1549 if (ulFlags != 0)
1550 return CR_INVALID_FLAG;
1551
1552 if (hMachine != NULL)
1553 {
1554 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1555 if (BindingHandle == NULL)
1556 return CR_FAILURE;
1557
1558 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1559 if (StringTable == 0)
1560 return CR_FAILURE;
1561 }
1562 else
1563 {
1564 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1565 return CR_FAILURE;
1566 }
1567
1568 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1569 if (lpDevInst == NULL)
1570 return CR_INVALID_DEVNODE;
1571
1572 RpcTryExcept
1573 {
1574 ret = PNP_DeviceInstanceAction(BindingHandle,
1575 PNP_DEVINST_ENABLE,
1576 ulFlags,
1577 lpDevInst,
1578 NULL);
1579 }
1580 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1581 {
1582 ret = RpcStatusToCmStatus(RpcExceptionCode());
1583 }
1584 RpcEndExcept;
1585
1586 return ret;
1587 }
1588
1589
1590 /***********************************************************************
1591 * CM_Enumerate_Classes [SETUPAPI.@]
1592 */
1593 CONFIGRET WINAPI CM_Enumerate_Classes(
1594 ULONG ulClassIndex, LPGUID ClassGuid, ULONG ulFlags)
1595 {
1596 TRACE("%lx %p %lx\n", ulClassIndex, ClassGuid, ulFlags);
1597 return CM_Enumerate_Classes_Ex(ulClassIndex, ClassGuid, ulFlags, NULL);
1598 }
1599
1600
1601 /***********************************************************************
1602 * CM_Enumerate_Classes_Ex [SETUPAPI.@]
1603 */
1604 CONFIGRET WINAPI CM_Enumerate_Classes_Ex(
1605 ULONG ulClassIndex, LPGUID ClassGuid, ULONG ulFlags, HMACHINE hMachine)
1606 {
1607 WCHAR szBuffer[MAX_GUID_STRING_LEN];
1608 RPC_BINDING_HANDLE BindingHandle = NULL;
1609 CONFIGRET ret = CR_SUCCESS;
1610 ULONG ulLength = MAX_GUID_STRING_LEN;
1611
1612 TRACE("%lx %p %lx %p\n", ulClassIndex, ClassGuid, ulFlags, hMachine);
1613
1614 if (ClassGuid == NULL)
1615 return CR_INVALID_POINTER;
1616
1617 if (ulFlags != 0)
1618 return CR_INVALID_FLAG;
1619
1620 if (hMachine != NULL)
1621 {
1622 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1623 if (BindingHandle == NULL)
1624 return CR_FAILURE;
1625 }
1626 else
1627 {
1628 if (!PnpGetLocalHandles(&BindingHandle, NULL))
1629 return CR_FAILURE;
1630 }
1631
1632 RpcTryExcept
1633 {
1634 ret = PNP_EnumerateSubKeys(BindingHandle,
1635 PNP_CLASS_SUBKEYS,
1636 ulClassIndex,
1637 szBuffer,
1638 MAX_GUID_STRING_LEN,
1639 &ulLength,
1640 ulFlags);
1641 }
1642 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1643 {
1644 ret = RpcStatusToCmStatus(RpcExceptionCode());
1645 }
1646 RpcEndExcept;
1647
1648 if (ret == CR_SUCCESS)
1649 {
1650 /* Remove the {} */
1651 szBuffer[MAX_GUID_STRING_LEN - 2] = UNICODE_NULL;
1652
1653 /* Convert the buffer to a GUID */
1654 if (UuidFromStringW(&szBuffer[1], ClassGuid) != RPC_S_OK)
1655 return CR_FAILURE;
1656 }
1657
1658 return ret;
1659 }
1660
1661
1662 /***********************************************************************
1663 * CM_Enumerate_EnumeratorsA [SETUPAPI.@]
1664 */
1665 CONFIGRET WINAPI CM_Enumerate_EnumeratorsA(
1666 ULONG ulEnumIndex, PCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1667 {
1668 TRACE("%lu %p %p %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags);
1669 return CM_Enumerate_Enumerators_ExA(ulEnumIndex, Buffer, pulLength,
1670 ulFlags, NULL);
1671 }
1672
1673
1674 /***********************************************************************
1675 * CM_Enumerate_EnumeratorsW [SETUPAPI.@]
1676 */
1677 CONFIGRET WINAPI CM_Enumerate_EnumeratorsW(
1678 ULONG ulEnumIndex, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1679 {
1680 TRACE("%lu %p %p %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags);
1681 return CM_Enumerate_Enumerators_ExW(ulEnumIndex, Buffer, pulLength,
1682 ulFlags, NULL);
1683 }
1684
1685
1686 /***********************************************************************
1687 * CM_Enumerate_Enumerators_ExA [SETUPAPI.@]
1688 */
1689 CONFIGRET WINAPI CM_Enumerate_Enumerators_ExA(
1690 ULONG ulEnumIndex, PCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1691 HMACHINE hMachine)
1692 {
1693 WCHAR szBuffer[MAX_DEVICE_ID_LEN];
1694 ULONG ulOrigLength;
1695 ULONG ulLength;
1696 CONFIGRET ret = CR_SUCCESS;
1697
1698 TRACE("%lu %p %p %lx %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags,
1699 hMachine);
1700
1701 if (Buffer == NULL || pulLength == NULL)
1702 return CR_INVALID_POINTER;
1703
1704 if (ulFlags != 0)
1705 return CR_INVALID_FLAG;
1706
1707 ulOrigLength = *pulLength;
1708 *pulLength = 0;
1709
1710 ulLength = MAX_DEVICE_ID_LEN;
1711 ret = CM_Enumerate_Enumerators_ExW(ulEnumIndex, szBuffer, &ulLength,
1712 ulFlags, hMachine);
1713 if (ret == CR_SUCCESS)
1714 {
1715 if (WideCharToMultiByte(CP_ACP,
1716 0,
1717 szBuffer,
1718 ulLength,
1719 Buffer,
1720 ulOrigLength,
1721 NULL,
1722 NULL) == 0)
1723 ret = CR_FAILURE;
1724 else
1725 *pulLength = lstrlenA(Buffer) + 1;
1726 }
1727
1728 return ret;
1729 }
1730
1731
1732 /***********************************************************************
1733 * CM_Enumerate_Enumerators_ExW [SETUPAPI.@]
1734 */
1735 CONFIGRET WINAPI CM_Enumerate_Enumerators_ExW(
1736 ULONG ulEnumIndex, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1737 HMACHINE hMachine)
1738 {
1739 RPC_BINDING_HANDLE BindingHandle = NULL;
1740 CONFIGRET ret;
1741
1742 TRACE("%lu %p %p %lx %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags,
1743 hMachine);
1744
1745 if (Buffer == NULL || pulLength == NULL)
1746 return CR_INVALID_POINTER;
1747
1748 if (ulFlags != 0)
1749 return CR_INVALID_FLAG;
1750
1751 *Buffer = UNICODE_NULL;
1752
1753 if (hMachine != NULL)
1754 {
1755 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1756 if (BindingHandle == NULL)
1757 return CR_FAILURE;
1758 }
1759 else
1760 {
1761 if (!PnpGetLocalHandles(&BindingHandle, NULL))
1762 return CR_FAILURE;
1763 }
1764
1765 RpcTryExcept
1766 {
1767 ret = PNP_EnumerateSubKeys(BindingHandle,
1768 PNP_ENUMERATOR_SUBKEYS,
1769 ulEnumIndex,
1770 Buffer,
1771 *pulLength,
1772 pulLength,
1773 ulFlags);
1774 }
1775 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1776 {
1777 ret = RpcStatusToCmStatus(RpcExceptionCode());
1778 }
1779 RpcEndExcept;
1780
1781 return ret;
1782 }
1783
1784
1785 /***********************************************************************
1786 * CM_Find_Range [SETUPAPI.@]
1787 */
1788 CONFIGRET
1789 WINAPI
1790 CM_Find_Range(
1791 _Out_ PDWORDLONG pullStart,
1792 _In_ DWORDLONG ullStart,
1793 _In_ ULONG ulLength,
1794 _In_ DWORDLONG ullAlignment,
1795 _In_ DWORDLONG ullEnd,
1796 _In_ RANGE_LIST rlh,
1797 _In_ ULONG ulFlags)
1798 {
1799 FIXME("CM_Find_Range(%p %I64u %lu %I64u %I64u %p %lx)\n",
1800 pullStart, ullStart, ulLength, ullAlignment, ullEnd, rlh, ulFlags);
1801 return CR_CALL_NOT_IMPLEMENTED;
1802 }
1803
1804
1805 /***********************************************************************
1806 * CM_First_Range [SETUPAPI.@]
1807 */
1808 CONFIGRET
1809 WINAPI
1810 CM_First_Range(
1811 _In_ RANGE_LIST rlh,
1812 _Out_ PDWORDLONG pullStart,
1813 _Out_ PDWORDLONG pullEnd,
1814 _Out_ PRANGE_ELEMENT preElement,
1815 _In_ ULONG ulFlags)
1816 {
1817 FIXME("CM_First_Range(%p %p %p %p %lx)\n",
1818 rlh, pullStart, pullEnd, preElement, ulFlags);
1819 return CR_CALL_NOT_IMPLEMENTED;
1820 }
1821
1822
1823 /***********************************************************************
1824 * CM_Free_Log_Conf [SETUPAPI.@]
1825 */
1826 CONFIGRET WINAPI CM_Free_Log_Conf(
1827 LOG_CONF lcLogConfToBeFreed, ULONG ulFlags)
1828 {
1829 TRACE("%lx %lx\n", lcLogConfToBeFreed, ulFlags);
1830 return CM_Free_Log_Conf_Ex(lcLogConfToBeFreed, ulFlags, NULL);
1831 }
1832
1833
1834 /***********************************************************************
1835 * CM_Free_Log_Conf_Ex [SETUPAPI.@]
1836 */
1837 CONFIGRET WINAPI CM_Free_Log_Conf_Ex(
1838 LOG_CONF lcLogConfToBeFreed, ULONG ulFlags, HMACHINE hMachine)
1839 {
1840 RPC_BINDING_HANDLE BindingHandle = NULL;
1841 HSTRING_TABLE StringTable = NULL;
1842 LPWSTR lpDevInst;
1843 PLOG_CONF_INFO pLogConfInfo;
1844 CONFIGRET ret;
1845
1846 TRACE("%lx %lx %lx\n", lcLogConfToBeFreed, ulFlags, hMachine);
1847
1848 if (!pSetupIsUserAdmin())
1849 return CR_ACCESS_DENIED;
1850
1851 pLogConfInfo = (PLOG_CONF_INFO)lcLogConfToBeFreed;
1852 if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
1853 return CR_INVALID_LOG_CONF;
1854
1855 if (ulFlags != 0)
1856 return CR_INVALID_FLAG;
1857
1858 if (hMachine != NULL)
1859 {
1860 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1861 if (BindingHandle == NULL)
1862 return CR_FAILURE;
1863
1864 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1865 if (StringTable == 0)
1866 return CR_FAILURE;
1867 }
1868 else
1869 {
1870 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1871 return CR_FAILURE;
1872 }
1873
1874 lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
1875 if (lpDevInst == NULL)
1876 return CR_INVALID_DEVNODE;
1877
1878 RpcTryExcept
1879 {
1880 ret = PNP_FreeLogConf(BindingHandle, lpDevInst, pLogConfInfo->ulFlags,
1881 pLogConfInfo->ulTag, 0);
1882 }
1883 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1884 {
1885 ret = RpcStatusToCmStatus(RpcExceptionCode());
1886 }
1887 RpcEndExcept;
1888
1889 return ret;
1890 }
1891
1892
1893 /***********************************************************************
1894 * CM_Free_Log_Conf_Handle [SETUPAPI.@]
1895 */
1896 CONFIGRET WINAPI CM_Free_Log_Conf_Handle(
1897 LOG_CONF lcLogConf)
1898 {
1899 PLOG_CONF_INFO pLogConfInfo;
1900
1901 TRACE("%lx\n", lcLogConf);
1902
1903 pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
1904 if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
1905 return CR_INVALID_LOG_CONF;
1906
1907 HeapFree(GetProcessHeap(), 0, pLogConfInfo);
1908
1909 return CR_SUCCESS;
1910 }
1911
1912
1913 /***********************************************************************
1914 * CM_Free_Range_List [SETUPAPI.@]
1915 */
1916 CONFIGRET
1917 WINAPI
1918 CM_Free_Range_List(
1919 _In_ RANGE_LIST RangeList,
1920 _In_ ULONG ulFlags)
1921 {
1922 PINTERNAL_RANGE_LIST pRangeList;
1923
1924 FIXME("CM_Free_Range_List(%p %lx)\n", RangeList, ulFlags);
1925
1926 pRangeList = (PINTERNAL_RANGE_LIST)RangeList;
1927
1928 if (pRangeList == NULL || pRangeList->ulMagic != RANGE_LIST_MAGIC)
1929 return CR_INVALID_RANGE_LIST;
1930
1931 if (ulFlags != 0)
1932 return CR_INVALID_FLAG;
1933
1934 // TODO: Free the list of ranges
1935
1936 HeapFree(GetProcessHeap(), 0, pRangeList);
1937
1938 return CR_SUCCESS;
1939 }
1940
1941
1942 /***********************************************************************
1943 * CM_Free_Res_Des [SETUPAPI.@]
1944 */
1945 CONFIGRET WINAPI CM_Free_Res_Des(
1946 PRES_DES prdResDes, RES_DES rdResDes, ULONG ulFlags)
1947 {
1948 TRACE("%p %p %lx\n", prdResDes, rdResDes, ulFlags);
1949 return CM_Free_Res_Des_Ex(prdResDes, rdResDes, ulFlags, NULL);
1950 }
1951
1952
1953 /***********************************************************************
1954 * CM_Free_Res_Des_Ex [SETUPAPI.@]
1955 */
1956 CONFIGRET WINAPI CM_Free_Res_Des_Ex(
1957 PRES_DES prdResDes, RES_DES rdResDes, ULONG ulFlags,
1958 HMACHINE hMachine)
1959 {
1960 FIXME("%p %p %lx %lx\n", prdResDes, rdResDes, ulFlags, hMachine);
1961
1962 return CR_CALL_NOT_IMPLEMENTED;
1963 }
1964
1965
1966 /***********************************************************************
1967 * CM_Free_Res_Des_Handle [SETUPAPI.@]
1968 */
1969 CONFIGRET WINAPI CM_Free_Res_Des_Handle(
1970 RES_DES rdResDes)
1971 {
1972 FIXME("%p\n", rdResDes);
1973
1974 return CR_CALL_NOT_IMPLEMENTED;
1975 }
1976
1977
1978 /***********************************************************************
1979 * CM_Get_Child [SETUPAPI.@]
1980 */
1981 CONFIGRET WINAPI CM_Get_Child(
1982 PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags)
1983 {
1984 TRACE("%p %p %lx\n", pdnDevInst, dnDevInst, ulFlags);
1985 return CM_Get_Child_Ex(pdnDevInst, dnDevInst, ulFlags, NULL);
1986 }
1987
1988
1989 /***********************************************************************
1990 * CM_Get_Child_Ex [SETUPAPI.@]
1991 */
1992 CONFIGRET WINAPI CM_Get_Child_Ex(
1993 PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
1994 {
1995 WCHAR szRelatedDevInst[MAX_DEVICE_ID_LEN];
1996 RPC_BINDING_HANDLE BindingHandle = NULL;
1997 HSTRING_TABLE StringTable = NULL;
1998 LPWSTR lpDevInst;
1999 DWORD dwIndex, dwLength = MAX_DEVICE_ID_LEN;
2000 CONFIGRET ret;
2001
2002 TRACE("%p %lx %lx %lx\n", pdnDevInst, dnDevInst, ulFlags, hMachine);
2003
2004 if (pdnDevInst == NULL)
2005 return CR_INVALID_POINTER;
2006
2007 if (dnDevInst == 0)
2008 return CR_INVALID_DEVINST;
2009
2010 if (ulFlags != 0)
2011 return CR_INVALID_FLAG;
2012
2013 *pdnDevInst = -1;
2014
2015 if (hMachine != NULL)
2016 {
2017 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2018 if (BindingHandle == NULL)
2019 return CR_FAILURE;
2020
2021 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2022 if (StringTable == 0)
2023 return CR_FAILURE;
2024 }
2025 else
2026 {
2027 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2028 return CR_FAILURE;
2029 }
2030
2031 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2032 if (lpDevInst == NULL)
2033 return CR_INVALID_DEVNODE;
2034
2035 RpcTryExcept
2036 {
2037 ret = PNP_GetRelatedDeviceInstance(BindingHandle,
2038 PNP_GET_CHILD_DEVICE_INSTANCE,
2039 lpDevInst,
2040 szRelatedDevInst,
2041 &dwLength,
2042 0);
2043 }
2044 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2045 {
2046 ret = RpcStatusToCmStatus(RpcExceptionCode());
2047 }
2048 RpcEndExcept;
2049
2050 if (ret != CR_SUCCESS)
2051 return ret;
2052
2053 TRACE("szRelatedDevInst: %s\n", debugstr_w(szRelatedDevInst));
2054
2055 dwIndex = pSetupStringTableAddString(StringTable, szRelatedDevInst, 1);
2056 if (dwIndex == -1)
2057 return CR_FAILURE;
2058
2059 *pdnDevInst = dwIndex;
2060
2061 return CR_SUCCESS;
2062 }
2063
2064
2065 /***********************************************************************
2066 * CM_Get_Class_Key_NameA [SETUPAPI.@]
2067 */
2068 CONFIGRET WINAPI CM_Get_Class_Key_NameA(
2069 LPGUID ClassGuid, LPSTR pszKeyName, PULONG pulLength, ULONG ulFlags)
2070 {
2071 TRACE("%p %p %p %lx\n",
2072 ClassGuid, pszKeyName, pulLength, ulFlags);
2073 return CM_Get_Class_Key_Name_ExA(ClassGuid, pszKeyName, pulLength,
2074 ulFlags, NULL);
2075 }
2076
2077
2078 /***********************************************************************
2079 * CM_Get_Class_Key_NameW [SETUPAPI.@]
2080 */
2081 CONFIGRET WINAPI CM_Get_Class_Key_NameW(
2082 LPGUID ClassGuid, LPWSTR pszKeyName, PULONG pulLength, ULONG ulFlags)
2083 {
2084 TRACE("%p %p %p %lx\n",
2085 ClassGuid, pszKeyName, pulLength, ulFlags);
2086 return CM_Get_Class_Key_Name_ExW(ClassGuid, pszKeyName, pulLength,
2087 ulFlags, NULL);
2088 }
2089
2090
2091 /***********************************************************************
2092 * CM_Get_Class_Key_Name_ExA [SETUPAPI.@]
2093 */
2094 CONFIGRET WINAPI CM_Get_Class_Key_Name_ExA(
2095 LPGUID ClassGuid, LPSTR pszKeyName, PULONG pulLength, ULONG ulFlags,
2096 HMACHINE hMachine)
2097 {
2098 WCHAR szBuffer[MAX_GUID_STRING_LEN];
2099 CONFIGRET ret = CR_SUCCESS;
2100 ULONG ulLength;
2101 ULONG ulOrigLength;
2102
2103 TRACE("%p %p %p %lx %lx\n",
2104 ClassGuid, pszKeyName, pulLength, ulFlags, hMachine);
2105
2106 if (ClassGuid == NULL || pszKeyName == NULL || pulLength == NULL)
2107 return CR_INVALID_POINTER;
2108
2109 ulOrigLength = *pulLength;
2110 *pulLength = 0;
2111
2112 ulLength = MAX_GUID_STRING_LEN;
2113 ret = CM_Get_Class_Key_Name_ExW(ClassGuid, szBuffer, &ulLength,
2114 ulFlags, hMachine);
2115 if (ret == CR_SUCCESS)
2116 {
2117 if (WideCharToMultiByte(CP_ACP,
2118 0,
2119 szBuffer,
2120 ulLength,
2121 pszKeyName,
2122 ulOrigLength,
2123 NULL,
2124 NULL) == 0)
2125 ret = CR_FAILURE;
2126 else
2127 *pulLength = lstrlenA(pszKeyName) + 1;
2128 }
2129
2130 return CR_SUCCESS;
2131 }
2132
2133
2134 /***********************************************************************
2135 * CM_Get_Class_Key_Name_ExW [SETUPAPI.@]
2136 */
2137 CONFIGRET WINAPI CM_Get_Class_Key_Name_ExW(
2138 LPGUID ClassGuid, LPWSTR pszKeyName, PULONG pulLength, ULONG ulFlags,
2139 HMACHINE hMachine)
2140 {
2141 TRACE("%p %p %p %lx %lx\n",
2142 ClassGuid, pszKeyName, pulLength, ulFlags, hMachine);
2143
2144 if (ClassGuid == NULL || pszKeyName == NULL || pulLength == NULL)
2145 return CR_INVALID_POINTER;
2146
2147 if (ulFlags != 0)
2148 return CR_INVALID_FLAG;
2149
2150 if (*pulLength < MAX_GUID_STRING_LEN)
2151 {
2152 *pulLength = 0;
2153 return CR_BUFFER_SMALL;
2154 }
2155
2156 if (!GuidToString(ClassGuid, pszKeyName))
2157 return CR_INVALID_DATA;
2158
2159 *pulLength = MAX_GUID_STRING_LEN;
2160
2161 return CR_SUCCESS;
2162 }
2163
2164
2165 /***********************************************************************
2166 * CM_Get_Class_NameA [SETUPAPI.@]
2167 */
2168 CONFIGRET WINAPI CM_Get_Class_NameA(
2169 LPGUID ClassGuid, PCHAR Buffer, PULONG pulLength, ULONG ulFlags)
2170 {
2171 TRACE("%p %p %p %lx\n", ClassGuid, Buffer, pulLength, ulFlags);
2172 return CM_Get_Class_Name_ExA(ClassGuid, Buffer, pulLength, ulFlags,
2173 NULL);
2174 }
2175
2176
2177 /***********************************************************************
2178 * CM_Get_Class_NameW [SETUPAPI.@]
2179 */
2180 CONFIGRET WINAPI CM_Get_Class_NameW(
2181 LPGUID ClassGuid, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags)
2182 {
2183 TRACE("%p %p %p %lx\n", ClassGuid, Buffer, pulLength, ulFlags);
2184 return CM_Get_Class_Name_ExW(ClassGuid, Buffer, pulLength, ulFlags,
2185 NULL);
2186 }
2187
2188
2189 /***********************************************************************
2190 * CM_Get_Class_Name_ExA [SETUPAPI.@]
2191 */
2192 CONFIGRET WINAPI CM_Get_Class_Name_ExA(
2193 LPGUID ClassGuid, PCHAR Buffer, PULONG pulLength, ULONG ulFlags,
2194 HMACHINE hMachine)
2195 {
2196 WCHAR szBuffer[MAX_CLASS_NAME_LEN];
2197 CONFIGRET ret = CR_SUCCESS;
2198 ULONG ulLength;
2199 ULONG ulOrigLength;
2200
2201 TRACE("%p %p %p %lx %lx\n",
2202 ClassGuid, Buffer, pulLength, ulFlags, hMachine);
2203
2204 if (ClassGuid == NULL || Buffer == NULL || pulLength == NULL)
2205 return CR_INVALID_POINTER;
2206
2207 ulOrigLength = *pulLength;
2208 *pulLength = 0;
2209
2210 ulLength = MAX_CLASS_NAME_LEN;
2211 ret = CM_Get_Class_Name_ExW(ClassGuid, szBuffer, &ulLength,
2212 ulFlags, hMachine);
2213 if (ret == CR_SUCCESS)
2214 {
2215 if (WideCharToMultiByte(CP_ACP,
2216 0,
2217 szBuffer,
2218 ulLength,
2219 Buffer,
2220 ulOrigLength,
2221 NULL,
2222 NULL) == 0)
2223 ret = CR_FAILURE;
2224 else
2225 *pulLength = lstrlenA(Buffer) + 1;
2226 }
2227
2228 return ret;
2229 }
2230
2231
2232 /***********************************************************************
2233 * CM_Get_Class_Name_ExW [SETUPAPI.@]
2234 */
2235 CONFIGRET WINAPI
2236 CM_Get_Class_Name_ExW(
2237 LPGUID ClassGuid, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags,
2238 HMACHINE hMachine)
2239 {
2240 WCHAR szGuidString[MAX_GUID_STRING_LEN];
2241 RPC_BINDING_HANDLE BindingHandle = NULL;
2242 CONFIGRET ret;
2243
2244 TRACE("%p %p %p %lx %lx\n",
2245 ClassGuid, Buffer, pulLength, ulFlags, hMachine);
2246
2247 if (ClassGuid == NULL || Buffer == NULL || pulLength == NULL)
2248 return CR_INVALID_POINTER;
2249
2250 if (ulFlags != 0)
2251 return CR_INVALID_FLAG;
2252
2253 if (!GuidToString(ClassGuid, szGuidString))
2254 return CR_INVALID_DATA;
2255
2256 TRACE("Guid %s\n", debugstr_w(szGuidString));
2257
2258 if (hMachine != NULL)
2259 {
2260 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2261 if (BindingHandle == NULL)
2262 return CR_FAILURE;
2263 }
2264 else
2265 {
2266 if (!PnpGetLocalHandles(&BindingHandle, NULL))
2267 return CR_FAILURE;
2268 }
2269
2270 RpcTryExcept
2271 {
2272 ret = PNP_GetClassName(BindingHandle,
2273 szGuidString,
2274 Buffer,
2275 pulLength,
2276 ulFlags);
2277 }
2278 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2279 {
2280 ret = RpcStatusToCmStatus(RpcExceptionCode());
2281 }
2282 RpcEndExcept;
2283
2284 return ret;
2285 }
2286
2287
2288 /***********************************************************************
2289 * CM_Get_Class_Registry_PropertyA [SETUPAPI.@]
2290 */
2291 CONFIGRET WINAPI CM_Get_Class_Registry_PropertyA(
2292 LPGUID ClassGuid, ULONG ulProperty, PULONG pulRegDataType,
2293 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2294 {
2295 PWSTR BufferW = NULL;
2296 ULONG ulLength = 0;
2297 ULONG ulType;
2298 CONFIGRET ret;
2299
2300 TRACE("%p %lu %p %p %p %lx %lx\n",
2301 ClassGuid, ulProperty, pulRegDataType, Buffer, pulLength,
2302 ulFlags, hMachine);
2303
2304 if (pulLength == NULL)
2305 return CR_INVALID_POINTER;
2306
2307 if (ulProperty < CM_CRP_MIN || ulProperty > CM_CRP_MAX)
2308 return CR_INVALID_PROPERTY;
2309
2310 ulType = GetRegistryPropertyType(ulProperty);
2311 if (ulType == REG_SZ || ulType == REG_MULTI_SZ)
2312 {
2313 /* Get the required buffer size */
2314 ret = CM_Get_Class_Registry_PropertyW(ClassGuid, ulProperty, pulRegDataType,
2315 NULL, &ulLength, ulFlags, hMachine);
2316 if (ret != CR_BUFFER_SMALL)
2317 return ret;
2318
2319 /* Allocate the unicode buffer */
2320 BufferW = HeapAlloc(GetProcessHeap(), 0, ulLength);
2321 if (BufferW == NULL)
2322 return CR_OUT_OF_MEMORY;
2323
2324 /* Get the property */
2325 ret = CM_Get_Class_Registry_PropertyW(ClassGuid, ulProperty, pulRegDataType,
2326 BufferW, &ulLength, ulFlags, hMachine);
2327 if (ret != CR_SUCCESS)
2328 {
2329 HeapFree(GetProcessHeap(), 0, BufferW);
2330 return ret;
2331 }
2332
2333 /* Do W->A conversion */
2334 *pulLength = WideCharToMultiByte(CP_ACP,
2335 0,
2336 BufferW,
2337 lstrlenW(BufferW) + 1,
2338 Buffer,
2339 *pulLength,
2340 NULL,
2341 NULL);
2342
2343 /* Release the unicode buffer */
2344 HeapFree(GetProcessHeap(), 0, BufferW);
2345
2346 if (*pulLength == 0)
2347 ret = CR_FAILURE;
2348 }
2349 else
2350 {
2351 /* Get the property */
2352 ret = CM_Get_Class_Registry_PropertyW(ClassGuid, ulProperty, pulRegDataType,
2353 Buffer, pulLength, ulFlags, hMachine);
2354 }
2355
2356 return ret;
2357 }
2358
2359
2360 /***********************************************************************
2361 * CM_Get_Class_Registry_PropertyW [SETUPAPI.@]
2362 */
2363 CONFIGRET WINAPI CM_Get_Class_Registry_PropertyW(
2364 LPGUID ClassGuid, ULONG ulProperty, PULONG pulRegDataType,
2365 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2366 {
2367 RPC_BINDING_HANDLE BindingHandle = NULL;
2368 WCHAR szGuidString[PNP_MAX_GUID_STRING_LEN + 1];
2369 ULONG ulType = 0;
2370 ULONG ulTransferLength = 0;
2371 CONFIGRET ret;
2372
2373 TRACE("%p %lu %p %p %p %lx %lx\n",
2374 ClassGuid, ulProperty, pulRegDataType, Buffer, pulLength,
2375 ulFlags, hMachine);
2376
2377 if (ClassGuid == NULL || pulLength == NULL)
2378 return CR_INVALID_POINTER;
2379
2380 if (ulFlags != 0)
2381 return CR_INVALID_FLAG;
2382
2383 if (pSetupStringFromGuid(ClassGuid,
2384 szGuidString,
2385 PNP_MAX_GUID_STRING_LEN) != 0)
2386 return CR_INVALID_DATA;
2387
2388 if (ulProperty < CM_CRP_MIN || ulProperty > CM_CRP_MAX)
2389 return CR_INVALID_PROPERTY;
2390
2391 if (hMachine != NULL)
2392 {
2393 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2394 if (BindingHandle == NULL)
2395 return CR_FAILURE;
2396 }
2397 else
2398 {
2399 if (!PnpGetLocalHandles(&BindingHandle, NULL))
2400 return CR_FAILURE;
2401 }
2402
2403 ulTransferLength = *pulLength;
2404
2405 RpcTryExcept
2406 {
2407 ret = PNP_GetClassRegProp(BindingHandle,
2408 szGuidString,
2409 ulProperty,
2410 &ulType,
2411 Buffer,
2412 &ulTransferLength,
2413 pulLength,
2414 ulFlags);
2415 }
2416 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2417 {
2418 ret = RpcStatusToCmStatus(RpcExceptionCode());
2419 }
2420 RpcEndExcept;
2421
2422 if (ret == CR_SUCCESS)
2423 {
2424 if (pulRegDataType != NULL)
2425 *pulRegDataType = ulType;
2426 }
2427
2428 return ret;
2429 }
2430
2431
2432 /***********************************************************************
2433 * CM_Get_Depth [SETUPAPI.@]
2434 */
2435 CONFIGRET WINAPI CM_Get_Depth(
2436 PULONG pulDepth, DEVINST dnDevInst, ULONG ulFlags)
2437 {
2438 TRACE("%p %lx %lx\n", pulDepth, dnDevInst, ulFlags);
2439 return CM_Get_Depth_Ex(pulDepth, dnDevInst, ulFlags, NULL);
2440 }
2441
2442
2443 /***********************************************************************
2444 * CM_Get_Depth_Ex [SETUPAPI.@]
2445 */
2446 CONFIGRET WINAPI CM_Get_Depth_Ex(
2447 PULONG pulDepth, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
2448 {
2449 RPC_BINDING_HANDLE BindingHandle = NULL;
2450 HSTRING_TABLE StringTable = NULL;
2451 LPWSTR lpDevInst;
2452 CONFIGRET ret;
2453
2454 TRACE("%p %lx %lx %lx\n",
2455 pulDepth, dnDevInst, ulFlags, hMachine);
2456
2457 if (pulDepth == NULL)
2458 return CR_INVALID_POINTER;
2459
2460 if (dnDevInst == 0)
2461 return CR_INVALID_DEVINST;
2462
2463 if (ulFlags != 0)
2464 return CR_INVALID_FLAG;
2465
2466 if (hMachine != NULL)
2467 {
2468 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2469 if (BindingHandle == NULL)
2470 return CR_FAILURE;
2471
2472 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2473 if (StringTable == 0)
2474 return CR_FAILURE;
2475 }
2476 else
2477 {
2478 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2479 return CR_FAILURE;
2480 }
2481
2482 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2483 if (lpDevInst == NULL)
2484 return CR_INVALID_DEVNODE;
2485
2486 RpcTryExcept
2487 {
2488 ret = PNP_GetDepth(BindingHandle,
2489 lpDevInst,
2490 pulDepth,
2491 ulFlags);
2492 }
2493 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2494 {
2495 ret = RpcStatusToCmStatus(RpcExceptionCode());
2496 }
2497 RpcEndExcept;
2498
2499 return ret;
2500 }
2501
2502
2503 /***********************************************************************
2504 * CM_Get_DevNode_Custom_PropertyA [SETUPAPI.@]
2505 */
2506 CONFIGRET WINAPI CM_Get_DevNode_Custom_PropertyA(
2507 DEVINST dnDevInst, PCSTR pszCustomPropertyName, PULONG pulRegDataType,
2508 PVOID Buffer, PULONG pulLength, ULONG ulFlags)
2509 {
2510 TRACE("%lx %s %p %p %p %lx\n", dnDevInst, pszCustomPropertyName,
2511 pulRegDataType, Buffer, pulLength, ulFlags);
2512 return CM_Get_DevNode_Custom_Property_ExA(dnDevInst, pszCustomPropertyName,
2513 pulRegDataType, Buffer,
2514 pulLength, ulFlags, NULL);
2515 }
2516
2517
2518 /***********************************************************************
2519 * CM_Get_DevNode_Custom_PropertyW [SETUPAPI.@]
2520 */
2521 CONFIGRET WINAPI CM_Get_DevNode_Custom_PropertyW(
2522 DEVINST dnDevInst, PCWSTR pszCustomPropertyName, PULONG pulRegDataType,
2523 PVOID Buffer, PULONG pulLength, ULONG ulFlags)
2524 {
2525 TRACE("%lx %s %p %p %p %lx\n", dnDevInst, debugstr_w(pszCustomPropertyName),
2526 pulRegDataType, Buffer, pulLength, ulFlags);
2527 return CM_Get_DevNode_Custom_Property_ExW(dnDevInst, pszCustomPropertyName,
2528 pulRegDataType, Buffer,
2529 pulLength, ulFlags, NULL);
2530 }
2531
2532
2533 /***********************************************************************
2534 * CM_Get_DevNode_Custom_Property_ExA [SETUPAPI.@]
2535 */
2536 CONFIGRET WINAPI CM_Get_DevNode_Custom_Property_ExA(
2537 DEVINST dnDevInst, PCSTR pszCustomPropertyName, PULONG pulRegDataType,
2538 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2539 {
2540 LPWSTR pszPropertyNameW = NULL;
2541 PVOID BufferW;
2542 ULONG ulLengthW;
2543 ULONG ulDataType = REG_NONE;
2544 CONFIGRET ret;
2545
2546 TRACE("%lx %s %p %p %p %lx %p\n", dnDevInst, pszCustomPropertyName,
2547 pulRegDataType, Buffer, pulLength, ulFlags, hMachine);
2548
2549 if (!pulLength)
2550 return CR_INVALID_POINTER;
2551
2552 ulLengthW = *pulLength * sizeof(WCHAR);
2553 BufferW = HeapAlloc(GetProcessHeap(), 0, ulLengthW);
2554 if (!BufferW)
2555 return CR_OUT_OF_MEMORY;
2556
2557 pszPropertyNameW = pSetupMultiByteToUnicode(pszCustomPropertyName,
2558 CP_ACP);
2559 if (pszPropertyNameW == NULL)
2560 {
2561 HeapFree(GetProcessHeap(), 0, BufferW);
2562 return CR_OUT_OF_MEMORY;
2563 }
2564
2565 ret = CM_Get_DevNode_Custom_Property_ExW(dnDevInst,
2566 pszPropertyNameW,
2567 &ulDataType,
2568 BufferW,
2569 &ulLengthW,
2570 ulFlags,
2571 hMachine);
2572 if (ret == CR_SUCCESS)
2573 {
2574 if (ulDataType == REG_SZ ||
2575 ulDataType == REG_EXPAND_SZ ||
2576 ulDataType == REG_MULTI_SZ)
2577 {
2578 /* Do W->A conversion */
2579 *pulLength = WideCharToMultiByte(CP_ACP,
2580 0,
2581 BufferW,
2582 lstrlenW(BufferW) + 1,
2583 Buffer,
2584 *pulLength,
2585 NULL,
2586 NULL);
2587 if (*pulLength == 0)
2588 ret = CR_FAILURE;
2589 }
2590 else
2591 {
2592 /* Directly copy the value */
2593 if (ulLengthW <= *pulLength)
2594 memcpy(Buffer, BufferW, ulLengthW);
2595 else
2596 {
2597 *pulLength = ulLengthW;
2598 ret = CR_BUFFER_SMALL;
2599 }
2600 }
2601 }
2602
2603 if (pulRegDataType)
2604 *pulRegDataType = ulDataType;
2605
2606 HeapFree(GetProcessHeap(), 0, BufferW);
2607 MyFree(pszPropertyNameW);
2608
2609 return ret;
2610 }
2611
2612
2613 /***********************************************************************
2614 * CM_Get_DevNode_Custom_Property_ExW [SETUPAPI.@]
2615 */
2616 CONFIGRET WINAPI CM_Get_DevNode_Custom_Property_ExW(
2617 DEVINST dnDevInst, PCWSTR pszCustomPropertyName, PULONG pulRegDataType,
2618 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2619 {
2620 RPC_BINDING_HANDLE BindingHandle = NULL;
2621 HSTRING_TABLE StringTable = NULL;
2622 LPWSTR lpDevInst;
2623 ULONG ulDataType = REG_NONE;
2624 ULONG ulTransferLength;
2625 CONFIGRET ret = CR_SUCCESS;
2626
2627 TRACE("%lx %s %p %p %p %lx %p\n", dnDevInst,
2628 debugstr_w(pszCustomPropertyName), pulRegDataType, Buffer,
2629 pulLength, ulFlags, hMachine);
2630
2631 if (dnDevInst == 0)
2632 return CR_INVALID_DEVNODE;
2633
2634 if (pszCustomPropertyName == NULL ||
2635 pulLength == NULL ||
2636 *pulLength == 0)
2637 return CR_INVALID_POINTER;
2638
2639 if (ulFlags & ~CM_CUSTOMDEVPROP_BITS)
2640 return CR_INVALID_FLAG;
2641
2642 if (hMachine != NULL)
2643 {
2644 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2645 if (BindingHandle == NULL)
2646 return CR_FAILURE;
2647
2648 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2649 if (StringTable == 0)
2650 return CR_FAILURE;
2651 }
2652 else
2653 {
2654 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2655 return CR_FAILURE;
2656 }
2657
2658 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2659 if (lpDevInst == NULL)
2660 return CR_INVALID_DEVNODE;
2661
2662 ulTransferLength = *pulLength;
2663
2664 RpcTryExcept
2665 {
2666 ret = PNP_GetCustomDevProp(BindingHandle,
2667 lpDevInst,
2668 (LPWSTR)pszCustomPropertyName,
2669 &ulDataType,
2670 Buffer,
2671 &ulTransferLength,
2672 pulLength,
2673 ulFlags);
2674 }
2675 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2676 {
2677 ret = RpcStatusToCmStatus(RpcExceptionCode());
2678 }
2679 RpcEndExcept;
2680
2681 if (ret == CR_SUCCESS)
2682 {
2683 if (pulRegDataType != NULL)
2684 *pulRegDataType = ulDataType;
2685 }
2686
2687 return ret;
2688 }
2689
2690
2691 /***********************************************************************
2692 * CM_Get_DevNode_Registry_PropertyA [SETUPAPI.@]
2693 */
2694 CONFIGRET WINAPI CM_Get_DevNode_Registry_PropertyA(
2695 DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
2696 PVOID Buffer, PULONG pulLength, ULONG ulFlags)
2697 {
2698 TRACE("%lx %lu %p %p %p %lx\n",
2699 dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength, ulFlags);
2700
2701 return CM_Get_DevNode_Registry_Property_ExA(dnDevInst, ulProperty,
2702 pulRegDataType, Buffer,
2703 pulLength, ulFlags, NULL);
2704 }
2705
2706
2707 /***********************************************************************
2708 * CM_Get_DevNode_Registry_PropertyW [SETUPAPI.@]
2709 */
2710 CONFIGRET WINAPI CM_Get_DevNode_Registry_PropertyW(
2711 DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
2712 PVOID Buffer, PULONG pulLength, ULONG ulFlags)
2713 {
2714 TRACE("%lx %lu %p %p %p %lx\n",
2715 dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength, ulFlags);
2716
2717 return CM_Get_DevNode_Registry_Property_ExW(dnDevInst, ulProperty,
2718 pulRegDataType, Buffer,
2719 pulLength, ulFlags, NULL);
2720 }
2721
2722
2723 /***********************************************************************
2724 * CM_Get_DevNode_Registry_Property_ExA [SETUPAPI.@]
2725 */
2726 CONFIGRET WINAPI CM_Get_DevNode_Registry_Property_ExA(
2727 DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
2728 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2729 {
2730 PVOID BufferW;
2731 ULONG LengthW;
2732 ULONG ulDataType = REG_NONE;
2733 CONFIGRET ret;
2734
2735 TRACE("%lx %lu %p %p %p %lx %lx\n",
2736 dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength,
2737 ulFlags, hMachine);
2738
2739 if (!pulLength)
2740 return CR_INVALID_POINTER;
2741
2742 LengthW = *pulLength * sizeof(WCHAR);
2743 BufferW = HeapAlloc(GetProcessHeap(), 0, LengthW);
2744
2745 if (!BufferW)
2746 return CR_OUT_OF_MEMORY;
2747
2748 ret = CM_Get_DevNode_Registry_Property_ExW(dnDevInst,
2749 ulProperty,
2750 &ulDataType,
2751 BufferW,
2752 &LengthW,
2753 ulFlags,
2754 hMachine);
2755
2756 if (ret == CR_SUCCESS)
2757 {
2758 if (ulDataType == REG_SZ ||
2759 ulDataType == REG_EXPAND_SZ ||
2760 ulDataType == REG_MULTI_SZ)
2761 {
2762 /* Do W->A conversion */
2763 *pulLength = WideCharToMultiByte(CP_ACP,
2764 0,
2765 BufferW,
2766 lstrlenW(BufferW) + 1,
2767 Buffer,
2768 *pulLength,
2769 NULL,
2770 NULL);
2771 if (*pulLength == 0)
2772 ret = CR_FAILURE;
2773 }
2774 else
2775 {
2776 /* Directly copy the value */
2777 if (LengthW <= *pulLength)
2778 memcpy(Buffer, BufferW, LengthW);
2779 else
2780 {
2781 *pulLength = LengthW;
2782 ret = CR_BUFFER_SMALL;
2783 }
2784 }
2785 }
2786
2787 if (pulRegDataType)
2788 *pulRegDataType = ulDataType;
2789
2790 HeapFree(GetProcessHeap(), 0, BufferW);
2791
2792 return ret;
2793 }
2794
2795
2796 /***********************************************************************
2797 * CM_Get_DevNode_Registry_Property_ExW [SETUPAPI.@]
2798 */
2799 CONFIGRET WINAPI CM_Get_DevNode_Registry_Property_ExW(
2800 DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
2801 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2802 {
2803 RPC_BINDING_HANDLE BindingHandle = NULL;
2804 HSTRING_TABLE StringTable = NULL;
2805 CONFIGRET ret = CR_SUCCESS;
2806 LPWSTR lpDevInst;
2807 ULONG ulDataType = REG_NONE;
2808 ULONG ulTransferLength = 0;
2809
2810 TRACE("%lx %lu %p %p %p %lx %lx\n",
2811 dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength,
2812 ulFlags, hMachine);
2813
2814 if (dnDevInst == 0)
2815 return CR_INVALID_DEVNODE;
2816
2817 if (ulProperty < CM_DRP_MIN || ulProperty > CM_DRP_MAX)
2818 return CR_INVALID_PROPERTY;
2819
2820 /* pulRegDataType is optional */
2821
2822 /* Buffer is optional */
2823
2824 if (pulLength == NULL)
2825 return CR_INVALID_POINTER;
2826
2827 if (*pulLength == 0)
2828 return CR_INVALID_POINTER;
2829
2830 if (ulFlags != 0)
2831 return CR_INVALID_FLAG;
2832
2833 if (hMachine != NULL)
2834 {
2835 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2836 if (BindingHandle == NULL)
2837 return CR_FAILURE;
2838
2839 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2840 if (StringTable == 0)
2841 return CR_FAILURE;
2842 }
2843 else
2844 {
2845 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2846 return CR_FAILURE;
2847 }
2848
2849 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2850 if (lpDevInst == NULL)
2851 return CR_INVALID_DEVNODE;
2852
2853 ulTransferLength = *pulLength;
2854
2855 RpcTryExcept
2856 {
2857 ret = PNP_GetDeviceRegProp(BindingHandle,
2858 lpDevInst,
2859 ulProperty,
2860 &ulDataType,
2861 Buffer,
2862 &ulTransferLength,
2863 pulLength,
2864 ulFlags);
2865 }
2866 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2867 {
2868 ret = RpcStatusToCmStatus(RpcExceptionCode());
2869 }
2870 RpcEndExcept;
2871
2872 if (ret == CR_SUCCESS)
2873 {
2874 if (pulRegDataType != NULL)
2875 *pulRegDataType = ulDataType;
2876 }
2877
2878 return ret;
2879 }
2880
2881
2882 /***********************************************************************
2883 * CM_Get_DevNode_Status [SETUPAPI.@]
2884 */
2885 CONFIGRET WINAPI CM_Get_DevNode_Status(
2886 PULONG pulStatus, PULONG pulProblemNumber, DEVINST dnDevInst,
2887 ULONG ulFlags)
2888 {
2889 TRACE("%p %p %lx %lx\n",
2890 pulStatus, pulProblemNumber, dnDevInst, ulFlags);
2891 return CM_Get_DevNode_Status_Ex(pulStatus, pulProblemNumber, dnDevInst,
2892 ulFlags, NULL);
2893 }
2894
2895
2896 /***********************************************************************
2897 * CM_Get_DevNode_Status_Ex [SETUPAPI.@]
2898 */
2899 CONFIGRET WINAPI
2900 CM_Get_DevNode_Status_Ex(
2901 PULONG pulStatus, PULONG pulProblemNumber, DEVINST dnDevInst,
2902 ULONG ulFlags, HMACHINE hMachine)
2903 {
2904 RPC_BINDING_HANDLE BindingHandle = NULL;
2905 HSTRING_TABLE StringTable = NULL;
2906 LPWSTR lpDevInst;
2907 CONFIGRET ret;
2908
2909 TRACE("%p %p %lx %lx %lx\n",
2910 pulStatus, pulProblemNumber, dnDevInst, ulFlags, hMachine);
2911
2912 if (pulStatus == NULL || pulProblemNumber == NULL)
2913 return CR_INVALID_POINTER;
2914
2915 if (dnDevInst == 0)
2916 return CR_INVALID_DEVINST;
2917
2918 if (ulFlags != 0)
2919 return CR_INVALID_FLAG;
2920
2921 if (hMachine != NULL)
2922 {
2923 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2924 if (BindingHandle == NULL)
2925 return CR_FAILURE;
2926
2927 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2928 if (StringTable == 0)
2929 return CR_FAILURE;
2930 }
2931 else
2932 {
2933 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2934 return CR_FAILURE;
2935 }
2936
2937 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2938 if (lpDevInst == NULL)
2939 return CR_INVALID_DEVNODE;
2940
2941 RpcTryExcept
2942 {
2943 ret = PNP_GetDeviceStatus(BindingHandle,
2944 lpDevInst,
2945 pulStatus,
2946 pulProblemNumber,
2947 ulFlags);
2948 }
2949 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2950 {
2951 ret = RpcStatusToCmStatus(RpcExceptionCode());
2952 }
2953 RpcEndExcept;
2954
2955 return ret;
2956 }
2957
2958
2959 /***********************************************************************
2960 * CM_Get_Device_IDA [SETUPAPI.@]
2961 */
2962 CONFIGRET WINAPI CM_Get_Device_IDA(
2963 DEVINST dnDevInst, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
2964 {
2965 TRACE("%lx %p %ld %ld\n",
2966 dnDevInst, Buffer, BufferLen, ulFlags);
2967 return CM_Get_Device_ID_ExA(dnDevInst, Buffer, BufferLen, ulFlags, NULL);
2968 }
2969
2970
2971 /***********************************************************************
2972 * CM_Get_Device_IDW [SETUPAPI.@]
2973 */
2974 CONFIGRET WINAPI CM_Get_Device_IDW(
2975 DEVINST dnDevInst, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
2976 {
2977 TRACE("%lx %p %ld %ld\n",
2978 dnDevInst, Buffer, BufferLen, ulFlags);
2979 return CM_Get_Device_ID_ExW(dnDevInst, Buffer, BufferLen, ulFlags, NULL);
2980 }
2981
2982
2983 /***********************************************************************
2984 * CM_Get_Device_ID_ExA [SETUPAPI.@]
2985 */
2986 CONFIGRET WINAPI CM_Get_Device_ID_ExA(
2987 DEVINST dnDevInst, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
2988 HMACHINE hMachine)
2989 {
2990 WCHAR szBufferW[MAX_DEVICE_ID_LEN];
2991 CONFIGRET ret = CR_SUCCESS;
2992
2993 TRACE("%lx %p %ld %ld %lx\n",
2994 dnDevInst, Buffer, BufferLen, ulFlags, hMachine);
2995
2996 if (Buffer == NULL)
2997 return CR_INVALID_POINTER;
2998
2999 ret = CM_Get_Device_ID_ExW(dnDevInst,
3000 szBufferW,
3001 MAX_DEVICE_ID_LEN,
3002 ulFlags,
3003 hMachine);
3004 if (ret == CR_SUCCESS)
3005 {
3006 if (WideCharToMultiByte(CP_ACP,
3007 0,
3008 szBufferW,
3009 lstrlenW(szBufferW) + 1,
3010 Buffer,
3011 BufferLen,
3012 NULL,
3013 NULL) == 0)
3014 ret = CR_FAILURE;
3015 }
3016
3017 return ret;
3018 }
3019
3020
3021 /***********************************************************************
3022 * CM_Get_Device_ID_ExW [SETUPAPI.@]
3023 */
3024 CONFIGRET WINAPI CM_Get_Device_ID_ExW(
3025 DEVINST dnDevInst, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
3026 HMACHINE hMachine)
3027 {
3028 HSTRING_TABLE StringTable = NULL;
3029
3030 TRACE("%lx %p %ld %ld %lx\n",
3031 dnDevInst, Buffer, BufferLen, ulFlags, hMachine);
3032
3033 if (dnDevInst == 0)
3034 return CR_INVALID_DEVINST;
3035
3036 if (Buffer == NULL)
3037 return CR_INVALID_POINTER;
3038
3039 if (ulFlags != 0)
3040 return CR_INVALID_FLAG;
3041
3042 if (hMachine != NULL)
3043 {
3044 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3045 if (StringTable == NULL)
3046 return CR_FAILURE;
3047 }
3048 else
3049 {
3050 if (!PnpGetLocalHandles(NULL, &StringTable))
3051 return CR_FAILURE;
3052 }
3053
3054 if (!pSetupStringTableStringFromIdEx(StringTable,
3055 dnDevInst,
3056 Buffer,
3057 &BufferLen))
3058 return CR_FAILURE;
3059
3060 return CR_SUCCESS;
3061 }
3062
3063
3064 /***********************************************************************
3065 * CM_Get_Device_ID_ListA [SETUPAPI.@]
3066 */
3067 CONFIGRET WINAPI CM_Get_Device_ID_ListA(
3068 PCSTR pszFilter, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
3069 {
3070 TRACE("%p %p %ld %ld\n", pszFilter, Buffer, BufferLen, ulFlags);
3071 return CM_Get_Device_ID_List_ExA(pszFilter, Buffer, BufferLen,
3072 ulFlags, NULL);
3073 }
3074
3075
3076 /***********************************************************************
3077 * CM_Get_Device_ID_ListW [SETUPAPI.@]
3078 */
3079 CONFIGRET WINAPI CM_Get_Device_ID_ListW(
3080 PCWSTR pszFilter, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
3081 {
3082 TRACE("%p %p %ld %ld\n", pszFilter, Buffer, BufferLen, ulFlags);
3083 return CM_Get_Device_ID_List_ExW(pszFilter, Buffer, BufferLen,
3084 ulFlags, NULL);
3085 }
3086
3087
3088 /***********************************************************************
3089 * CM_Get_Device_ID_List_ExA [SETUPAPI.@]
3090 */
3091 CONFIGRET WINAPI CM_Get_Device_ID_List_ExA(
3092 PCSTR pszFilter, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
3093 HMACHINE hMachine)
3094 {
3095 LPWSTR BufferW = NULL;
3096 LPWSTR pszFilterW = NULL;
3097 CONFIGRET ret = CR_SUCCESS;
3098
3099 TRACE("%p %p %ld %ld %lx\n",
3100 pszFilter, Buffer, BufferLen, ulFlags, hMachine);
3101
3102 BufferW = MyMalloc(BufferLen * sizeof(WCHAR));
3103 if (BufferW == NULL)
3104 return CR_OUT_OF_MEMORY;
3105
3106 if (pszFilter == NULL)
3107 {
3108 ret = CM_Get_Device_ID_List_ExW(NULL,
3109 BufferW,
3110 BufferLen,
3111 ulFlags,
3112 hMachine);
3113 }
3114 else
3115 {
3116 if (pSetupCaptureAndConvertAnsiArg(pszFilter, &pszFilterW))
3117 {
3118 ret = CR_INVALID_DEVICE_ID;
3119 goto Done;
3120 }
3121
3122 ret = CM_Get_Device_ID_List_ExW(pszFilterW,
3123 BufferW,
3124 BufferLen,
3125 ulFlags,
3126 hMachine);
3127
3128 MyFree(pszFilterW);
3129 }
3130
3131 if (WideCharToMultiByte(CP_ACP,
3132 0,
3133 BufferW,
3134 lstrlenW(BufferW) + 1,
3135 Buffer,
3136 BufferLen,
3137 NULL,
3138 NULL) == 0)
3139 ret = CR_FAILURE;
3140
3141 Done:
3142 MyFree(BufferW);
3143
3144 return ret;
3145 }
3146
3147
3148 /***********************************************************************
3149 * CM_Get_Device_ID_List_ExW [SETUPAPI.@]
3150 */
3151 CONFIGRET WINAPI CM_Get_Device_ID_List_ExW(
3152 PCWSTR pszFilter, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
3153 HMACHINE hMachine)
3154 {
3155 RPC_BINDING_HANDLE BindingHandle = NULL;
3156 CONFIGRET ret;
3157
3158 TRACE("%p %p %ld %ld %lx\n",
3159 pszFilter, Buffer, BufferLen, ulFlags, hMachine);
3160
3161 if (Buffer == NULL || BufferLen == 0)
3162 return CR_INVALID_POINTER;
3163
3164 if (ulFlags & ~CM_GETIDLIST_FILTER_BITS)
3165 return CR_INVALID_FLAG;
3166
3167 if (hMachine != NULL)
3168 {
3169 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3170 if (BindingHandle == NULL)
3171 return CR_FAILURE;
3172 }
3173 else
3174 {
3175 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3176 return CR_FAILURE;
3177 }
3178
3179 *Buffer = 0;
3180
3181 RpcTryExcept
3182 {
3183 ret = PNP_GetDeviceList(BindingHandle,
3184 (LPWSTR)pszFilter,
3185 Buffer,
3186 &BufferLen,
3187 ulFlags);
3188 }
3189 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3190 {
3191 ret = RpcStatusToCmStatus(RpcExceptionCode());
3192 }
3193 RpcEndExcept;
3194
3195 return ret;
3196 }
3197
3198
3199 /***********************************************************************
3200 * CM_Get_Device_ID_List_SizeA [SETUPAPI.@]
3201 */
3202 CONFIGRET WINAPI CM_Get_Device_ID_List_SizeA(
3203 PULONG pulLen, PCSTR pszFilter, ULONG ulFlags)
3204 {
3205 TRACE("%p %s %ld\n", pulLen, pszFilter, ulFlags);
3206 return CM_Get_Device_ID_List_Size_ExA(pulLen, pszFilter, ulFlags, NULL);
3207 }
3208
3209
3210 /***********************************************************************
3211 * CM_Get_Device_ID_List_SizeW [SETUPAPI.@]
3212 */
3213 CONFIGRET WINAPI CM_Get_Device_ID_List_SizeW(
3214 PULONG pulLen, PCWSTR pszFilter, ULONG ulFlags)
3215 {
3216 TRACE("%p %s %ld\n", pulLen, debugstr_w(pszFilter), ulFlags);
3217 return CM_Get_Device_ID_List_Size_ExW(pulLen, pszFilter, ulFlags, NULL);
3218 }
3219
3220
3221 /***********************************************************************
3222 * CM_Get_Device_ID_List_Size_ExA [SETUPAPI.@]
3223 */
3224 CONFIGRET WINAPI CM_Get_Device_ID_List_Size_ExA(
3225 PULONG pulLen, PCSTR pszFilter, ULONG ulFlags, HMACHINE hMachine)
3226 {
3227 LPWSTR pszFilterW = NULL;
3228 CONFIGRET ret = CR_SUCCESS;
3229
3230 FIXME("%p %s %lx %lx\n", pulLen, pszFilter, ulFlags, hMachine);
3231
3232 if (pszFilter == NULL)
3233 {
3234 ret = CM_Get_Device_ID_List_Size_ExW(pulLen,
3235 NULL,
3236 ulFlags,
3237 hMachine);
3238 }
3239 else
3240 {
3241 if (pSetupCaptureAndConvertAnsiArg(pszFilter, &pszFilterW))
3242 return CR_INVALID_DEVICE_ID;
3243
3244 ret = CM_Get_Device_ID_List_Size_ExW(pulLen,
3245 pszFilterW,
3246 ulFlags,
3247 hMachine);
3248
3249 MyFree(pszFilterW);
3250 }
3251
3252 return ret;
3253 }
3254
3255
3256 /***********************************************************************
3257 * CM_Get_Device_ID_List_Size_ExW [SETUPAPI.@]
3258 */
3259 CONFIGRET WINAPI CM_Get_Device_ID_List_Size_ExW(
3260 PULONG pulLen, PCWSTR pszFilter, ULONG ulFlags, HMACHINE hMachine)
3261 {
3262 RPC_BINDING_HANDLE BindingHandle = NULL;
3263 CONFIGRET ret;
3264
3265 FIXME("%p %s %ld %lx\n", pulLen, debugstr_w(pszFilter), ulFlags, hMachine);
3266
3267 if (pulLen == NULL)
3268 return CR_INVALID_POINTER;
3269
3270 if (ulFlags & ~CM_GETIDLIST_FILTER_BITS)
3271 return CR_INVALID_FLAG;
3272
3273 if (hMachine != NULL)
3274 {
3275 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3276 if (BindingHandle == NULL)
3277 return CR_FAILURE;
3278 }
3279 else
3280 {
3281 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3282 return CR_FAILURE;
3283 }
3284
3285 *pulLen = 0;
3286
3287 RpcTryExcept
3288 {
3289 ret = PNP_GetDeviceListSize(BindingHandle,
3290 (LPWSTR)pszFilter,
3291 pulLen,
3292 ulFlags);
3293 }
3294 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3295 {
3296 ret = RpcStatusToCmStatus(RpcExceptionCode());
3297 }
3298 RpcEndExcept;
3299
3300 return ret;
3301 }
3302
3303
3304 /***********************************************************************
3305 * CM_Get_Device_ID_Size [SETUPAPI.@]
3306 */
3307 CONFIGRET WINAPI CM_Get_Device_ID_Size(
3308 PULONG pulLen, DEVINST dnDevInst, ULONG ulFlags)
3309 {
3310 TRACE("%p %lx %lx\n", pulLen, dnDevInst, ulFlags);
3311 return CM_Get_Device_ID_Size_Ex(pulLen, dnDevInst, ulFlags, NULL);
3312 }
3313
3314
3315 /***********************************************************************
3316 * CM_Get_Device_ID_Size_Ex [SETUPAPI.@]
3317 */
3318 CONFIGRET WINAPI CM_Get_Device_ID_Size_Ex(
3319 PULONG pulLen, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
3320 {
3321 HSTRING_TABLE StringTable = NULL;
3322 LPWSTR DeviceId;
3323
3324 TRACE("%p %lx %lx %lx\n", pulLen, dnDevInst, ulFlags, hMachine);
3325
3326 if (pulLen == NULL)
3327 return CR_INVALID_POINTER;
3328
3329 if (dnDevInst == 0)
3330 return CR_INVALID_DEVINST;
3331
3332 if (ulFlags != 0)
3333 return CR_INVALID_FLAG;
3334
3335 if (hMachine != NULL)
3336 {
3337 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3338 if (StringTable == NULL)
3339 return CR_FAILURE;
3340 }
3341 else
3342 {
3343 if (!PnpGetLocalHandles(NULL, &StringTable))
3344 return CR_FAILURE;
3345 }
3346
3347 DeviceId = pSetupStringTableStringFromId(StringTable, dnDevInst);
3348 if (DeviceId == NULL)
3349 {
3350 *pulLen = 0;
3351 return CR_SUCCESS;
3352 }
3353
3354 *pulLen = lstrlenW(DeviceId);
3355
3356 return CR_SUCCESS;
3357 }
3358
3359
3360 /***********************************************************************
3361 * CM_Get_Device_Interface_AliasA [SETUPAPI.@]
3362 */
3363 CONFIGRET WINAPI CM_Get_Device_Interface_AliasA(
3364 LPCSTR pszDeviceInterface, LPGUID AliasInterfaceGuid,
3365 LPSTR pszAliasDeviceInterface, PULONG pulLength, ULONG ulFlags)
3366 {
3367 TRACE("%p %p %p %p %lu\n", pszDeviceInterface, AliasInterfaceGuid,
3368 pszAliasDeviceInterface, pulLength, ulFlags);
3369
3370 return CM_Get_Device_Interface_Alias_ExA(pszDeviceInterface,
3371 AliasInterfaceGuid, pszAliasDeviceInterface, pulLength,
3372 ulFlags, NULL);
3373 }
3374
3375
3376 /***********************************************************************
3377 * CM_Get_Device_Interface_AliasW [SETUPAPI.@]
3378 */
3379 CONFIGRET WINAPI CM_Get_Device_Interface_AliasW(
3380 LPCWSTR pszDeviceInterface, LPGUID AliasInterfaceGuid,
3381 LPWSTR pszAliasDeviceInterface, PULONG pulLength, ULONG ulFlags)
3382 {
3383 TRACE("%p %p %p %p %lu\n", pszDeviceInterface, AliasInterfaceGuid,
3384 pszAliasDeviceInterface, pulLength, ulFlags);
3385
3386 return CM_Get_Device_Interface_Alias_ExW(pszDeviceInterface,
3387 AliasInterfaceGuid, pszAliasDeviceInterface, pulLength,
3388 ulFlags, NULL);
3389 }
3390
3391
3392 /***********************************************************************
3393 * CM_Get_Device_Interface_Alias_ExA [SETUPAPI.@]
3394 */
3395 CONFIGRET WINAPI CM_Get_Device_Interface_Alias_ExA(
3396 LPCSTR pszDeviceInterface, LPGUID AliasInterfaceGuid, LPSTR pszAliasDeviceInterface,
3397 PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
3398 {
3399 FIXME("%p %p %p %p %lu %lx\n", pszDeviceInterface, AliasInterfaceGuid,
3400 pszAliasDeviceInterface, pulLength, ulFlags, hMachine);
3401
3402 return CR_CALL_NOT_IMPLEMENTED;
3403 }
3404
3405
3406 /***********************************************************************
3407 * CM_Get_Device_Interface_Alias_ExW [SETUPAPI.@]
3408 */
3409 CONFIGRET WINAPI CM_Get_Device_Interface_Alias_ExW(
3410 LPCWSTR pszDeviceInterface, LPGUID AliasInterfaceGuid, LPWSTR pszAliasDeviceInterface,
3411 PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
3412 {
3413 RPC_BINDING_HANDLE BindingHandle = NULL;
3414 ULONG ulTransferLength;
3415 CONFIGRET ret = CR_SUCCESS;
3416
3417 TRACE("%p %p %p %p %lu %lx\n", pszDeviceInterface, AliasInterfaceGuid,
3418 pszAliasDeviceInterface, pulLength, ulFlags, hMachine);
3419
3420 if (pszDeviceInterface == NULL ||
3421 AliasInterfaceGuid == NULL ||
3422 pszAliasDeviceInterface == NULL ||
3423 pulLength == NULL)
3424 return CR_INVALID_POINTER;
3425
3426 if (ulFlags != 0)
3427 return CR_INVALID_FLAG;
3428
3429 if (hMachine != NULL)
3430 {
3431 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3432 if (BindingHandle == NULL)
3433 return CR_FAILURE;
3434 }
3435 else
3436 {
3437 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3438 return CR_FAILURE;
3439 }
3440
3441 ulTransferLength = *pulLength;
3442
3443 RpcTryExcept
3444 {
3445 ret = PNP_GetInterfaceDeviceAlias(BindingHandle,
3446 (LPWSTR)pszDeviceInterface,
3447 AliasInterfaceGuid,
3448 pszAliasDeviceInterface,
3449 pulLength,
3450 &ulTransferLength,
3451 0);
3452 }
3453 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3454 {
3455 ret = RpcStatusToCmStatus(RpcExceptionCode());
3456 }
3457 RpcEndExcept;
3458
3459 return ret;
3460 }
3461
3462
3463 /***********************************************************************
3464 * CM_Get_Device_Interface_ListA (SETUPAPI.@)
3465 */
3466 CONFIGRET WINAPI CM_Get_Device_Interface_ListA(
3467 LPGUID InterfaceClassGuid, DEVINSTID_A pDeviceID, PCHAR Buffer,
3468 ULONG BufferLen, ULONG ulFlags)
3469 {
3470 TRACE("%s %s %p %lu 0x%08lx\n", debugstr_guid(InterfaceClassGuid),
3471 pDeviceID, Buffer, BufferLen, ulFlags);
3472
3473 return CM_Get_Device_Interface_List_ExA(InterfaceClassGuid, pDeviceID,
3474 Buffer, BufferLen, ulFlags, NULL);
3475 }
3476
3477
3478 /***********************************************************************
3479 * CM_Get_Device_Interface_ListW (SETUPAPI.@)
3480 */
3481 CONFIGRET WINAPI CM_Get_Device_Interface_ListW(
3482 LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceID, PWCHAR Buffer,
3483 ULONG BufferLen, ULONG ulFlags)
3484 {
3485 TRACE("%s %s %p %lu 0x%08lx\n", debugstr_guid(InterfaceClassGuid),
3486 debugstr_w(pDeviceID), Buffer, BufferLen, ulFlags);
3487
3488 return CM_Get_Device_Interface_List_ExW(InterfaceClassGuid, pDeviceID,
3489 Buffer, BufferLen, ulFlags, NULL);
3490 }
3491
3492
3493 /***********************************************************************
3494 * CM_Get_Device_Interface_List_ExA (SETUPAPI.@)
3495 */
3496 CONFIGRET WINAPI CM_Get_Device_Interface_List_ExA(
3497 LPGUID InterfaceClassGuid, DEVINSTID_A pDeviceID, PCHAR Buffer,
3498 ULONG BufferLen, ULONG ulFlags, HMACHINE hMachine)
3499 {
3500 DEVINSTID_W pDeviceIdW = NULL;
3501 PWCHAR BufferW = NULL;
3502 CONFIGRET ret = CR_SUCCESS;
3503
3504 TRACE("%s %s %p %lu 0x%08lx %p\n", debugstr_guid(InterfaceClassGuid),
3505 pDeviceID, Buffer, BufferLen, ulFlags, hMachine);
3506
3507 if (Buffer == NULL ||
3508 BufferLen == 0)
3509 return CR_INVALID_POINTER;
3510
3511 if (pDeviceID != NULL)
3512 {
3513 if (!pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDeviceIdW))
3514 return CR_INVALID_DEVICE_ID;
3515 }
3516
3517 BufferW = MyMalloc(BufferLen * sizeof(WCHAR));
3518 if (BufferW == NULL)
3519 {
3520 ret = CR_OUT_OF_MEMORY;
3521 goto Done;
3522 }
3523
3524 ret = CM_Get_Device_Interface_List_ExW(InterfaceClassGuid, pDeviceIdW,
3525 BufferW, BufferLen, ulFlags,
3526 hMachine);
3527 if (ret != CR_SUCCESS)
3528 goto Done;
3529
3530 if (WideCharToMultiByte(CP_ACP,
3531 0,
3532 BufferW,
3533 lstrlenW(BufferW) + 1,
3534 Buffer,
3535 BufferLen,
3536 NULL,
3537 NULL) == 0)
3538 ret = CR_FAILURE;
3539
3540 Done:
3541 if (BufferW != NULL)
3542 MyFree(BufferW);
3543
3544 if (pDeviceIdW != NULL)
3545 MyFree(pDeviceIdW);
3546
3547 return ret;
3548 }
3549
3550
3551 /***********************************************************************
3552 * CM_Get_Device_Interface_List_ExW (SETUPAPI.@)
3553 */
3554 CONFIGRET WINAPI CM_Get_Device_Interface_List_ExW(
3555 LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceID, PWCHAR Buffer,
3556 ULONG BufferLen, ULONG ulFlags, HMACHINE hMachine)
3557 {
3558 RPC_BINDING_HANDLE BindingHandle = NULL;
3559 PNP_RPC_BUFFER_SIZE BufferSize = 0;
3560 CONFIGRET ret = CR_SUCCESS;
3561
3562 TRACE("%s %s %p %lu 0x%08lx %p\n", debugstr_guid(InterfaceClassGuid),
3563 debugstr_w(pDeviceID), Buffer, BufferLen, ulFlags, hMachine);
3564
3565 if (Buffer == NULL ||
3566 BufferLen == 0)
3567 return CR_INVALID_POINTER;
3568
3569 if (ulFlags & ~CM_GET_DEVICE_INTERFACE_LIST_BITS)
3570 return CR_INVALID_FLAG;
3571
3572 if (hMachine != NULL)
3573 {
3574 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3575 if (BindingHandle == NULL)
3576 return CR_FAILURE;
3577 }
3578 else
3579 {
3580 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3581 return CR_FAILURE;
3582 }
3583
3584 *Buffer = 0;
3585 BufferSize = BufferLen;
3586
3587 RpcTryExcept
3588 {
3589 ret = PNP_GetInterfaceDeviceList(BindingHandle,
3590 InterfaceClassGuid,
3591 pDeviceID,
3592 (LPBYTE)Buffer,
3593 &BufferSize,
3594 ulFlags);
3595 }
3596 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3597 {
3598 ret = RpcStatusToCmStatus(RpcExceptionCode());
3599 }
3600 RpcEndExcept;
3601
3602 return ret;
3603 }
3604
3605
3606 /***********************************************************************
3607 * CM_Get_Device_Interface_List_SizeA (SETUPAPI.@)
3608 */
3609 CONFIGRET WINAPI CM_Get_Device_Interface_List_SizeA(
3610 PULONG pulLen, LPGUID InterfaceClassGuid, DEVINSTID_A pDeviceId,
3611 ULONG ulFlags)
3612 {
3613 TRACE("%p %p %s 0x%08lx\n", pulLen, InterfaceClassGuid,
3614 pDeviceId, ulFlags);
3615
3616 return CM_Get_Device_Interface_List_Size_ExA(pulLen, InterfaceClassGuid,
3617 pDeviceId, ulFlags, NULL);
3618 }
3619
3620
3621 /***********************************************************************
3622 * CM_Get_Device_Interface_List_SizeW (SETUPAPI.@)
3623 */
3624 CONFIGRET WINAPI CM_Get_Device_Interface_List_SizeW(
3625 PULONG pulLen, LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceId,
3626 ULONG ulFlags)
3627 {
3628 TRACE("%p %p %s 0x%08lx\n", pulLen, InterfaceClassGuid,
3629 debugstr_w(pDeviceId), ulFlags);
3630
3631 return CM_Get_Device_Interface_List_Size_ExW(pulLen, InterfaceClassGuid,
3632 pDeviceId, ulFlags, NULL);
3633 }
3634
3635
3636 /***********************************************************************
3637 * CM_Get_Device_Interface_List_Size_ExA (SETUPAPI.@)
3638 */
3639 CONFIGRET WINAPI CM_Get_Device_Interface_List_Size_ExA(
3640 PULONG pulLen, LPGUID InterfaceClassGuid, DEVINSTID_A pDeviceId,
3641 ULONG ulFlags, HMACHINE hMachine)
3642 {
3643 DEVINSTID_W pDeviceIdW = NULL;
3644 CONFIGRET ret = CR_SUCCESS;
3645
3646 TRACE("%p %p %s 0x%08lx %p\n", pulLen, InterfaceClassGuid,
3647 pDeviceId, ulFlags, hMachine);
3648
3649 if (pulLen == NULL)
3650 return CR_INVALID_POINTER;
3651
3652 if (pDeviceId != NULL)
3653 {
3654 if (!pSetupCaptureAndConvertAnsiArg(pDeviceId, &pDeviceIdW))
3655 return CR_INVALID_DEVICE_ID;
3656 }
3657
3658 *pulLen = 0;
3659
3660 ret = CM_Get_Device_Interface_List_Size_ExW(pulLen, InterfaceClassGuid,
3661 pDeviceIdW, ulFlags, hMachine);
3662
3663 if (pDeviceIdW != NULL)
3664 MyFree(pDeviceIdW);
3665
3666 return ret;
3667 }
3668
3669
3670 /***********************************************************************
3671 * CM_Get_Device_Interface_List_Size_ExW (SETUPAPI.@)
3672 */
3673 CONFIGRET WINAPI CM_Get_Device_Interface_List_Size_ExW(
3674 PULONG pulLen, LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceId,
3675 ULONG ulFlags, HMACHINE hMachine)
3676 {
3677 RPC_BINDING_HANDLE BindingHandle = NULL;
3678 CONFIGRET ret = CR_SUCCESS;
3679
3680 TRACE("%p %p %s 0x%08lx %p\n", pulLen, InterfaceClassGuid,
3681 debugstr_w(pDeviceId), ulFlags, hMachine);
3682
3683 if (pulLen == NULL)
3684 return CR_INVALID_POINTER;
3685
3686 if (ulFlags & ~CM_GET_DEVICE_INTERFACE_LIST_BITS)
3687 return CR_INVALID_FLAG;
3688
3689 if (hMachine != NULL)
3690 {
3691 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3692 if (BindingHandle == NULL)
3693 return CR_FAILURE;
3694 }
3695 else
3696 {
3697 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3698 return CR_FAILURE;
3699 }
3700
3701 *pulLen = 0;
3702
3703 RpcTryExcept
3704 {
3705 ret = PNP_GetInterfaceDeviceListSize(BindingHandle,
3706 pulLen,
3707 InterfaceClassGuid,
3708 pDeviceId,
3709 ulFlags);
3710 }
3711 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3712 {
3713 ret = RpcStatusToCmStatus(RpcExceptionCode());
3714 }
3715 RpcEndExcept;
3716
3717 return ret;
3718 }
3719
3720
3721 /***********************************************************************
3722 * CM_Get_First_Log_Conf [SETUPAPI.@]
3723 */
3724 CONFIGRET WINAPI CM_Get_First_Log_Conf(
3725 PLOG_CONF plcLogConf, DEVINST dnDevInst, ULONG ulFlags)
3726 {
3727 TRACE("%p %lx %lx\n", plcLogConf, dnDevInst, ulFlags);
3728 return CM_Get_First_Log_Conf_Ex(plcLogConf, dnDevInst, ulFlags, NULL);
3729 }
3730
3731
3732 /***********************************************************************
3733 * CM_Get_First_Log_Conf_Ex [SETUPAPI.@]
3734 */
3735 CONFIGRET WINAPI CM_Get_First_Log_Conf_Ex(
3736 PLOG_CONF plcLogConf, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
3737 {
3738 RPC_BINDING_HANDLE BindingHandle = NULL;
3739 HSTRING_TABLE StringTable = NULL;
3740 LPWSTR lpDevInst = NULL;
3741 CONFIGRET ret = CR_SUCCESS;
3742 ULONG ulTag;
3743 PLOG_CONF_INFO pLogConfInfo;
3744
3745 FIXME("%p %lx %lx %lx\n", plcLogConf, dnDevInst, ulFlags, hMachine);
3746
3747 if (dnDevInst == 0)
3748 return CR_INVALID_DEVINST;
3749
3750 if (ulFlags & ~LOG_CONF_BITS)
3751 return CR_INVALID_FLAG;
3752
3753 if (plcLogConf)
3754 *plcLogConf = 0;
3755
3756 if (hMachine != NULL)
3757 {
3758 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3759 if (BindingHandle == NULL)
3760 return CR_FAILURE;
3761
3762 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3763 if (StringTable == 0)
3764 return CR_FAILURE;
3765 }
3766 else
3767 {
3768 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
3769 return CR_FAILURE;
3770 }
3771
3772 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
3773 if (lpDevInst == NULL)
3774 return CR_INVALID_DEVNODE;
3775
3776 RpcTryExcept
3777 {
3778 ret = PNP_GetFirstLogConf(BindingHandle,
3779 lpDevInst,
3780 ulFlags,
3781 &ulTag,
3782 ulFlags);
3783 }
3784 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3785 {
3786 ret = RpcStatusToCmStatus(RpcExceptionCode());
3787 }
3788 RpcEndExcept;
3789
3790 if (ret != CR_SUCCESS)
3791 return ret;
3792
3793 if (plcLogConf)
3794 {
3795 pLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
3796 if (pLogConfInfo == NULL)
3797 return CR_OUT_OF_MEMORY;
3798
3799 pLogConfInfo->ulMagic = LOG_CONF_MAGIC;
3800 pLogConfInfo->dnDevInst = dnDevInst;
3801 pLogConfInfo->ulFlags = ulFlags;
3802 pLogConfInfo->ulTag = ulTag;
3803
3804 *plcLogConf = (LOG_CONF)pLogConfInfo;
3805 }
3806
3807 return CR_SUCCESS;
3808 }
3809
3810
3811 /***********************************************************************
3812 * CM_Get_Global_State [SETUPAPI.@]
3813 */
3814 CONFIGRET WINAPI CM_Get_Global_State(
3815 PULONG pulState, ULONG ulFlags)
3816 {
3817 TRACE("%p %lx\n", pulState, ulFlags);
3818 return CM_Get_Global_State_Ex(pulState, ulFlags, NULL);
3819 }
3820
3821
3822 /***********************************************************************
3823 * CM_Get_Global_State_Ex [SETUPAPI.@]
3824 */
3825 CONFIGRET WINAPI CM_Get_Global_State_Ex(
3826 PULONG pulState, ULONG ulFlags, HMACHINE hMachine)
3827 {
3828 RPC_BINDING_HANDLE BindingHandle = NULL;
3829 CONFIGRET ret;
3830
3831 TRACE("%p %lx %lx\n", pulState, ulFlags, hMachine);
3832
3833 if (pulState == NULL)
3834 return CR_INVALID_POINTER;
3835
3836 if (ulFlags != 0)
3837 return CR_INVALID_FLAG;
3838
3839 if (hMachine != NULL)
3840 {
3841 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3842 if (BindingHandle == NULL)
3843 return CR_FAILURE;
3844 }
3845 else
3846 {
3847 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3848 return CR_FAILURE;
3849 }
3850
3851 RpcTryExcept
3852 {
3853 ret = PNP_GetGlobalState(BindingHandle, pulState, ulFlags);
3854 }
3855 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3856 {
3857 ret = RpcStatusToCmStatus(RpcExceptionCode());
3858 }
3859 RpcEndExcept;
3860
3861 return ret;
3862 }
3863
3864
3865 /***********************************************************************
3866 * CM_Get_HW_Prof_FlagsA [SETUPAPI.@]
3867 */
3868 CONFIGRET WINAPI CM_Get_HW_Prof_FlagsA(
3869 DEVINSTID_A szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
3870 ULONG ulFlags)
3871 {
3872 TRACE("%s %lu %p %lx\n", szDevInstName,
3873 ulHardwareProfile, pulValue, ulFlags);
3874
3875 return CM_Get_HW_Prof_Flags_ExA(szDevInstName, ulHardwareProfile,
3876 pulValue, ulFlags, NULL);
3877 }
3878
3879
3880 /***********************************************************************
3881 * CM_Get_HW_Prof_FlagsW [SETUPAPI.@]
3882 */
3883 CONFIGRET WINAPI CM_Get_HW_Prof_FlagsW(
3884 DEVINSTID_W szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
3885 ULONG ulFlags)
3886 {
3887 TRACE("%s %lu %p %lx\n", debugstr_w(szDevInstName),
3888 ulHardwareProfile, pulValue, ulFlags);
3889
3890 return CM_Get_HW_Prof_Flags_ExW(szDevInstName, ulHardwareProfile,
3891 pulValue, ulFlags, NULL);
3892 }
3893
3894
3895 /***********************************************************************
3896 * CM_Get_HW_Prof_Flags_ExA [SETUPAPI.@]
3897 */
3898 CONFIGRET WINAPI CM_Get_HW_Prof_Flags_ExA(
3899 DEVINSTID_A szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
3900 ULONG ulFlags, HMACHINE hMachine)
3901 {
3902 DEVINSTID_W pszDevIdW = NULL;
3903 CONFIGRET ret = CR_SUCCESS;
3904
3905 TRACE("%s %lu %p %lx %lx\n", szDevInstName,
3906 ulHardwareProfile, pulValue, ulFlags, hMachine);
3907
3908 if (szDevInstName != NULL)
3909 {
3910 if (pSetupCaptureAndConvertAnsiArg(szDevInstName, &pszDevIdW))
3911 return CR_INVALID_DEVICE_ID;
3912 }
3913
3914 ret = CM_Get_HW_Prof_Flags_ExW(pszDevIdW, ulHardwareProfile,
3915 pulValue, ulFlags, hMachine);
3916
3917 if (pszDevIdW != NULL)
3918 MyFree(pszDevIdW);
3919
3920 return ret;
3921 }
3922
3923
3924 /***********************************************************************
3925 * CM_Get_HW_Prof_Flags_ExW [SETUPAPI.@]
3926 */
3927 CONFIGRET WINAPI CM_Get_HW_Prof_Flags_ExW(
3928 DEVINSTID_W szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
3929 ULONG ulFlags, HMACHINE hMachine)
3930 {
3931 RPC_BINDING_HANDLE BindingHandle = NULL;
3932 CONFIGRET ret;
3933
3934 FIXME("%s %lu %p %lx %lx\n", debugstr_w(szDevInstName),
3935 ulHardwareProfile, pulValue, ulFlags, hMachine);
3936
3937 if ((szDevInstName == NULL) || (pulValue == NULL))
3938 return CR_INVALID_POINTER;
3939
3940 if (ulFlags != 0)
3941 return CR_INVALID_FLAG;
3942
3943 /* FIXME: Check whether szDevInstName is valid */
3944
3945 if (hMachine != NULL)
3946 {
3947 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3948 if (BindingHandle == NULL)
3949 return CR_FAILURE;
3950 }
3951 else
3952 {
3953 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3954 return CR_FAILURE;
3955 }
3956
3957 RpcTryExcept
3958 {
3959 ret = PNP_HwProfFlags(BindingHandle, PNP_GET_HWPROFFLAGS, szDevInstName,
3960 ulHardwareProfile, pulValue, NULL, NULL, 0, 0);
3961 }
3962 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3963 {
3964 ret = RpcStatusToCmStatus(RpcExceptionCode());
3965 }
3966 RpcEndExcept;
3967
3968 return ret;
3969 }
3970
3971
3972 /***********************************************************************
3973 * CM_Get_Hardware_Profile_InfoA [SETUPAPI.@]
3974 */
3975 CONFIGRET WINAPI CM_Get_Hardware_Profile_InfoA(
3976 ULONG ulIndex, PHWPROFILEINFO_A pHWProfileInfo, ULONG ulFlags)
3977 {
3978 TRACE("%lu %p %lx\n", ulIndex, pHWProfileInfo, ulFlags);
3979
3980 return CM_Get_Hardware_Profile_Info_ExA(ulIndex, pHWProfileInfo,
3981 ulFlags, NULL);
3982 }
3983
3984
3985 /***********************************************************************
3986 * CM_Get_Hardware_Profile_InfoW [SETUPAPI.@]
3987 */
3988 CONFIGRET WINAPI CM_Get_Hardware_Profile_InfoW(
3989 ULONG ulIndex, PHWPROFILEINFO_W pHWProfileInfo, ULONG ulFlags)
3990 {
3991 TRACE("%lu %p %lx\n", ulIndex, pHWProfileInfo, ulFlags);
3992
3993 return CM_Get_Hardware_Profile_Info_ExW(ulIndex, pHWProfileInfo,
3994 ulFlags, NULL);
3995 }
3996
3997
3998 /***********************************************************************
3999 * CM_Get_Hardware_Profile_Info_ExA [SETUPAPI.@]
4000 */
4001 CONFIGRET WINAPI CM_Get_Hardware_Profile_Info_ExA(
4002 ULONG ulIndex, PHWPROFILEINFO_A pHWProfileInfo, ULONG ulFlags,
4003 HMACHINE hMachine)
4004 {
4005 HWPROFILEINFO_W LocalProfileInfo;
4006 CONFIGRET ret;
4007
4008 TRACE("%lu %p %lx %lx\n", ulIndex, pHWProfileInfo, ulFlags, hMachine);
4009
4010 if (pHWProfileInfo == NULL)
4011 return CR_INVALID_POINTER;
4012
4013 ret = CM_Get_Hardware_Profile_Info_ExW(ulIndex, &LocalProfileInfo,
4014 ulFlags, hMachine);
4015 if (ret == CR_SUCCESS)
4016 {
4017 pHWProfileInfo->HWPI_ulHWProfile = LocalProfileInfo.HWPI_ulHWProfile;
4018 pHWProfileInfo->HWPI_dwFlags = LocalProfileInfo.HWPI_dwFlags;
4019
4020 if (WideCharToMultiByte(CP_ACP,
4021 0,
4022 LocalProfileInfo.HWPI_szFriendlyName,
4023 lstrlenW(LocalProfileInfo.HWPI_szFriendlyName) + 1,
4024 pHWProfileInfo->HWPI_szFriendlyName,
4025 MAX_PROFILE_LEN,
4026 NULL,
4027 NULL) == 0)
4028 ret = CR_FAILURE;
4029 }
4030
4031 return ret;
4032 }
4033
4034
4035 /***********************************************************************
4036 * CM_Get_Hardware_Profile_Info_ExW [SETUPAPI.@]
4037 */
4038 CONFIGRET WINAPI CM_Get_Hardware_Profile_Info_ExW(
4039 ULONG ulIndex, PHWPROFILEINFO_W pHWProfileInfo, ULONG ulFlags,
4040 HMACHINE hMachine)
4041 {
4042 RPC_BINDING_HANDLE BindingHandle = NULL;
4043 CONFIGRET ret;
4044
4045 TRACE("%lu %p %lx %lx\n", ulIndex, pHWProfileInfo, ulFlags, hMachine);
4046
4047 if (pHWProfileInfo == NULL)
4048 return CR_INVALID_POINTER;
4049
4050 if (ulFlags != 0)
4051 return CR_INVALID_FLAG;
4052
4053 if (hMachine != NULL)
4054 {
4055 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4056 if (BindingHandle == NULL)
4057 return CR_FAILURE;
4058 }
4059 else
4060 {
4061 if (!PnpGetLocalHandles(&BindingHandle, NULL))
4062 return CR_FAILURE;
4063 }
4064
4065 RpcTryExcept
4066 {
4067 ret = PNP_GetHwProfInfo(BindingHandle, ulIndex, pHWProfileInfo,
4068 sizeof(HWPROFILEINFO_W), 0);
4069 }
4070 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4071 {
4072 ret = RpcStatusToCmStatus(RpcExceptionCode());
4073 }
4074 RpcEndExcept;
4075
4076 return ret;
4077 }
4078
4079
4080 /***********************************************************************
4081 * CM_Get_Log_Conf_Priority [SETUPAPI.@]
4082 */
4083 CONFIGRET WINAPI CM_Get_Log_Conf_Priority(
4084 LOG_CONF lcLogConf, PPRIORITY pPriority, ULONG ulFlags)
4085 {
4086 TRACE("%p %p %lx\n", lcLogConf, pPriority, ulFlags);
4087 return CM_Get_Log_Conf_Priority_Ex(lcLogConf, pPriority, ulFlags, NULL);
4088 }
4089
4090
4091 /***********************************************************************
4092 * CM_Get_Log_Conf_Priority_Ex [SETUPAPI.@]
4093 */
4094 CONFIGRET WINAPI CM_Get_Log_Conf_Priority_Ex(
4095 LOG_CONF lcLogConf, PPRIORITY pPriority, ULONG ulFlags,
4096 HMACHINE hMachine)
4097 {
4098 RPC_BINDING_HANDLE BindingHandle = NULL;
4099 HSTRING_TABLE StringTable = NULL;
4100 PLOG_CONF_INFO pLogConfInfo;
4101 LPWSTR lpDevInst;
4102 CONFIGRET ret;
4103
4104 FIXME("%p %p %lx %lx\n", lcLogConf, pPriority, ulFlags, hMachine);
4105
4106 pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
4107 if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
4108 return CR_INVALID_LOG_CONF;
4109
4110 if (pPriority == NULL)
4111 return CR_INVALID_POINTER;
4112
4113 if (ulFlags != 0)
4114 return CR_INVALID_FLAG;
4115
4116 if (hMachine != NULL)
4117 {
4118 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4119 if (BindingHandle == NULL)
4120 return CR_FAILURE;
4121
4122 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;