[SETUPAPI]
[reactos.git] / reactos / 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 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
25
26 /* Registry key and value names */
27 static const WCHAR Backslash[] = {'\\', 0};
28 static const WCHAR Class[] = {'C','l','a','s','s',0};
29
30 static const WCHAR ControlClass[] = {'S','y','s','t','e','m','\\',
31 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
32 'C','o','n','t','r','o','l','\\',
33 'C','l','a','s','s',0};
34
35 static const WCHAR DeviceClasses[] = {'S','y','s','t','e','m','\\',
36 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
37 'C','o','n','t','r','o','l','\\',
38 'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
39
40 typedef struct _MACHINE_INFO
41 {
42 WCHAR szMachineName[SP_MAX_MACHINENAME_LENGTH];
43 RPC_BINDING_HANDLE BindingHandle;
44 HSTRING_TABLE StringTable;
45 BOOL bLocal;
46 } MACHINE_INFO, *PMACHINE_INFO;
47
48
49 typedef struct _LOG_CONF_INFO
50 {
51 ULONG ulMagic;
52 DEVINST dnDevInst;
53 ULONG ulFlags;
54 ULONG ulTag;
55 } LOG_CONF_INFO, *PLOG_CONF_INFO;
56
57 #define LOG_CONF_MAGIC 0x464E434C /* "LCNF" */
58
59
60 static BOOL GuidToString(LPGUID Guid, LPWSTR String)
61 {
62 LPWSTR lpString;
63
64 if (UuidToStringW(Guid, &lpString) != RPC_S_OK)
65 return FALSE;
66
67 lstrcpyW(&String[1], lpString);
68
69 String[0] = '{';
70 String[MAX_GUID_STRING_LEN - 2] = '}';
71 String[MAX_GUID_STRING_LEN - 1] = UNICODE_NULL;
72
73 RpcStringFreeW(&lpString);
74
75 return TRUE;
76 }
77
78
79 static CONFIGRET
80 RpcStatusToCmStatus(RPC_STATUS Status)
81 {
82 return CR_FAILURE;
83 }
84
85
86 /***********************************************************************
87 * CMP_WaitNoPendingInstallEvents [SETUPAPI.@]
88 */
89 DWORD WINAPI CMP_WaitNoPendingInstallEvents(
90 DWORD dwTimeout)
91 {
92 HANDLE hEvent;
93 DWORD ret;
94
95 hEvent = OpenEventW(SYNCHRONIZE, FALSE, L"Global\\PnP_No_Pending_Install_Events");
96 if (hEvent == NULL)
97 return WAIT_FAILED;
98
99 ret = WaitForSingleObject(hEvent, dwTimeout);
100 CloseHandle(hEvent);
101 return ret;
102 }
103
104
105 /***********************************************************************
106 * CMP_Init_Detection [SETUPAPI.@]
107 */
108 CONFIGRET WINAPI CMP_Init_Detection(
109 DWORD dwMagic)
110 {
111 RPC_BINDING_HANDLE BindingHandle = NULL;
112 CONFIGRET ret;
113
114 TRACE("%lu\n", dwMagic);
115
116 if (dwMagic != CMP_MAGIC)
117 return CR_INVALID_DATA;
118
119 if (!PnpGetLocalHandles(&BindingHandle, NULL))
120 return CR_FAILURE;
121
122 RpcTryExcept
123 {
124 ret = PNP_InitDetection(BindingHandle);
125 }
126 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
127 {
128 ret = RpcStatusToCmStatus(RpcExceptionCode());
129 }
130 RpcEndExcept;
131
132 return ret;
133 }
134
135
136 /***********************************************************************
137 * CMP_Report_LogOn [SETUPAPI.@]
138 */
139 CONFIGRET WINAPI CMP_Report_LogOn(
140 DWORD dwMagic,
141 DWORD dwProcessId)
142 {
143 RPC_BINDING_HANDLE BindingHandle = NULL;
144 CONFIGRET ret = CR_SUCCESS;
145 BOOL bAdmin;
146 DWORD i;
147
148 TRACE("%lu\n", dwMagic);
149
150 if (dwMagic != CMP_MAGIC)
151 return CR_INVALID_DATA;
152
153 if (!PnpGetLocalHandles(&BindingHandle, NULL))
154 return CR_FAILURE;
155
156 bAdmin = pSetupIsUserAdmin();
157
158 for (i = 0; i < 30; i++)
159 {
160 RpcTryExcept
161 {
162 ret = PNP_ReportLogOn(BindingHandle,
163 bAdmin,
164 dwProcessId);
165 }
166 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
167 {
168 ret = RpcStatusToCmStatus(RpcExceptionCode());
169 }
170 RpcEndExcept;
171
172 if (ret == CR_SUCCESS)
173 break;
174
175 Sleep(5000);
176 }
177
178 return ret;
179 }
180
181
182 /***********************************************************************
183 * CMP_WaitServicesAvailable [SETUPAPI.@]
184 */
185 CONFIGRET
186 WINAPI
187 CMP_WaitServicesAvailable(HMACHINE hMachine)
188 {
189 RPC_BINDING_HANDLE BindingHandle = NULL;
190 CONFIGRET ret = CR_SUCCESS;
191 WORD Version;
192
193 if (!PnpGetLocalHandles(&BindingHandle, NULL))
194 return CR_FAILURE;
195
196 RpcTryExcept
197 {
198 ret = PNP_GetVersion(BindingHandle, &Version);
199 }
200 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
201 {
202 ret = RpcStatusToCmStatus(RpcExceptionCode());
203 }
204 RpcEndExcept;
205
206 return ret;
207 }
208
209
210 /***********************************************************************
211 * CM_Add_Empty_Log_Conf [SETUPAPI.@]
212 */
213 CONFIGRET WINAPI CM_Add_Empty_Log_Conf(
214 PLOG_CONF plcLogConf, DEVINST dnDevInst, PRIORITY Priority,
215 ULONG ulFlags)
216 {
217 TRACE("%p %p %lu %lx\n", plcLogConf, dnDevInst, Priority, ulFlags);
218 return CM_Add_Empty_Log_Conf_Ex(plcLogConf, dnDevInst, Priority,
219 ulFlags, NULL);
220 }
221
222
223 /***********************************************************************
224 * CM_Add_Empty_Log_Conf_Ex [SETUPAPI.@]
225 */
226 CONFIGRET WINAPI CM_Add_Empty_Log_Conf_Ex(
227 PLOG_CONF plcLogConf, DEVINST dnDevInst, PRIORITY Priority,
228 ULONG ulFlags, HMACHINE hMachine)
229 {
230 RPC_BINDING_HANDLE BindingHandle = NULL;
231 HSTRING_TABLE StringTable = NULL;
232 ULONG ulLogConfTag = 0;
233 LPWSTR lpDevInst;
234 PLOG_CONF_INFO pLogConfInfo;
235 CONFIGRET ret = CR_SUCCESS;
236
237 FIXME("%p %p %lu %lx %p\n",
238 plcLogConf, dnDevInst, Priority, ulFlags, hMachine);
239
240 if (!pSetupIsUserAdmin())
241 return CR_ACCESS_DENIED;
242
243 if (plcLogConf == NULL)
244 return CR_INVALID_POINTER;
245
246 if (dnDevInst == 0)
247 return CR_INVALID_DEVINST;
248
249 if (Priority > 0xFFFF)
250 return CR_INVALID_PRIORITY;
251
252 if (ulFlags & ~(LOG_CONF_BITS | PRIORITY_BIT))
253 return CR_INVALID_FLAG;
254
255 if (hMachine != NULL)
256 {
257 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
258 if (BindingHandle == NULL)
259 return CR_FAILURE;
260
261 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
262 if (StringTable == 0)
263 return CR_FAILURE;
264 }
265 else
266 {
267 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
268 return CR_FAILURE;
269 }
270
271 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
272 if (lpDevInst == NULL)
273 return CR_INVALID_DEVNODE;
274
275 RpcTryExcept
276 {
277 ret = PNP_AddEmptyLogConf(BindingHandle, lpDevInst, Priority,
278 &ulLogConfTag, ulFlags);
279 }
280 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
281 {
282 ret = RpcStatusToCmStatus(RpcExceptionCode());
283 }
284 RpcEndExcept;
285
286 if (ret == CR_SUCCESS)
287 {
288 pLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
289 if (pLogConfInfo == NULL)
290 {
291 ret = CR_OUT_OF_MEMORY;
292 }
293 else
294 {
295 pLogConfInfo->ulMagic = LOG_CONF_MAGIC;
296 pLogConfInfo->dnDevInst = dnDevInst;
297 pLogConfInfo->ulFlags = ulFlags;
298 pLogConfInfo->ulTag = ulLogConfTag;
299
300 *plcLogConf = (LOG_CONF)pLogConfInfo;
301
302 ret = CR_SUCCESS;
303 }
304 }
305
306 return ret;
307 }
308
309
310 /***********************************************************************
311 * CM_Add_IDA [SETUPAPI.@]
312 */
313 CONFIGRET WINAPI CM_Add_IDA(
314 DEVINST dnDevInst, PSTR pszID, ULONG ulFlags)
315 {
316 TRACE("%p %s %lx\n", dnDevInst, pszID, ulFlags);
317 return CM_Add_ID_ExA(dnDevInst, pszID, ulFlags, NULL);
318 }
319
320
321 /***********************************************************************
322 * CM_Add_IDW [SETUPAPI.@]
323 */
324 CONFIGRET WINAPI CM_Add_IDW(
325 DEVINST dnDevInst, PWSTR pszID, ULONG ulFlags)
326 {
327 TRACE("%p %s %lx\n", dnDevInst, debugstr_w(pszID), ulFlags);
328 return CM_Add_ID_ExW(dnDevInst, pszID, ulFlags, NULL);
329 }
330
331
332 /***********************************************************************
333 * CM_Add_ID_ExA [SETUPAPI.@]
334 */
335 CONFIGRET WINAPI CM_Add_ID_ExA(
336 DEVINST dnDevInst, PSTR pszID, ULONG ulFlags, HMACHINE hMachine)
337 {
338 PWSTR pszIDW;
339 CONFIGRET ret;
340
341 TRACE("%p %s %lx %p\n", dnDevInst, pszID, ulFlags, hMachine);
342
343 if (pSetupCaptureAndConvertAnsiArg(pszID, &pszIDW))
344 return CR_INVALID_DATA;
345
346 ret = CM_Add_ID_ExW(dnDevInst, pszIDW, ulFlags, hMachine);
347
348 MyFree(pszIDW);
349
350 return ret;
351 }
352
353
354 /***********************************************************************
355 * CM_Add_ID_ExW [SETUPAPI.@]
356 */
357 CONFIGRET WINAPI CM_Add_ID_ExW(
358 DEVINST dnDevInst, PWSTR pszID, ULONG ulFlags, HMACHINE hMachine)
359 {
360 RPC_BINDING_HANDLE BindingHandle = NULL;
361 HSTRING_TABLE StringTable = NULL;
362 LPWSTR lpDevInst;
363 CONFIGRET ret;
364
365 TRACE("%p %s %lx %p\n", dnDevInst, debugstr_w(pszID), ulFlags, hMachine);
366
367 if (!pSetupIsUserAdmin())
368 return CR_ACCESS_DENIED;
369
370 if (dnDevInst == 0)
371 return CR_INVALID_DEVINST;
372
373 if (pszID == NULL)
374 return CR_INVALID_POINTER;
375
376 if (ulFlags & ~CM_ADD_ID_BITS)
377 return CR_INVALID_FLAG;
378
379 if (hMachine != NULL)
380 {
381 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
382 if (BindingHandle == NULL)
383 return CR_FAILURE;
384
385 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
386 if (StringTable == 0)
387 return CR_FAILURE;
388 }
389 else
390 {
391 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
392 return CR_FAILURE;
393 }
394
395 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
396 if (lpDevInst == NULL)
397 return CR_INVALID_DEVNODE;
398
399 RpcTryExcept
400 {
401 ret = PNP_AddID(BindingHandle,
402 lpDevInst,
403 pszID,
404 ulFlags);
405 }
406 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
407 {
408 ret = RpcStatusToCmStatus(RpcExceptionCode());
409 }
410 RpcEndExcept;
411
412 return ret;
413 }
414
415
416 /***********************************************************************
417 * CM_Add_Res_Des [SETUPAPI.@]
418 */
419 CONFIGRET WINAPI CM_Add_Res_Des(
420 PRES_DES prdResDes, LOG_CONF lcLogConf, RESOURCEID ResourceID,
421 PCVOID ResourceData, ULONG ResourceLen, ULONG ulFlags)
422 {
423 TRACE("%p %p %lu %p %lu %lx\n", prdResDes, lcLogConf, ResourceID,
424 ResourceData, ResourceLen, ulFlags);
425 return CM_Add_Res_Des_Ex(prdResDes, lcLogConf, ResourceID, ResourceData,
426 ResourceLen, ulFlags, NULL);
427 }
428
429
430 /***********************************************************************
431 * CM_Add_Res_Des_Ex [SETUPAPI.@]
432 */
433 CONFIGRET WINAPI CM_Add_Res_Des_Ex(
434 PRES_DES prdResDes, LOG_CONF lcLogConf, RESOURCEID ResourceID,
435 PCVOID ResourceData, ULONG ResourceLen, ULONG ulFlags, HMACHINE hMachine)
436 {
437 FIXME("%p %p %lu %p %lu %lx %p\n", prdResDes, lcLogConf, ResourceID,
438 ResourceData, ResourceLen, ulFlags, hMachine);
439
440 return CR_CALL_NOT_IMPLEMENTED;
441 }
442
443
444 /***********************************************************************
445 * CM_Connect_MachineA [SETUPAPI.@]
446 */
447 CONFIGRET WINAPI CM_Connect_MachineA(
448 PCSTR UNCServerName, PHMACHINE phMachine)
449 {
450 PWSTR pServerNameW;
451 CONFIGRET ret;
452
453 TRACE("%s %p\n", UNCServerName, phMachine);
454
455 if (UNCServerName == NULL || *UNCServerName == 0)
456 return CM_Connect_MachineW(NULL, phMachine);
457
458 if (pSetupCaptureAndConvertAnsiArg(UNCServerName, &pServerNameW))
459 return CR_INVALID_DATA;
460
461 ret = CM_Connect_MachineW(pServerNameW, phMachine);
462
463 MyFree(pServerNameW);
464
465 return ret;
466 }
467
468
469 /***********************************************************************
470 * CM_Connect_MachineW [SETUPAPI.@]
471 */
472 CONFIGRET WINAPI CM_Connect_MachineW(
473 PCWSTR UNCServerName, PHMACHINE phMachine)
474 {
475 PMACHINE_INFO pMachine;
476
477 TRACE("%s %p\n", debugstr_w(UNCServerName), phMachine);
478
479 if (phMachine == NULL)
480 return CR_INVALID_POINTER;
481
482 *phMachine = NULL;
483
484 pMachine = HeapAlloc(GetProcessHeap(), 0, sizeof(MACHINE_INFO));
485 if (pMachine == NULL)
486 return CR_OUT_OF_MEMORY;
487
488 if (UNCServerName == NULL || *UNCServerName == 0)
489 {
490 pMachine->bLocal = TRUE;
491
492 /* FIXME: store the computers name in pMachine->szMachineName */
493
494 if (!PnpGetLocalHandles(&pMachine->BindingHandle,
495 &pMachine->StringTable))
496 {
497 HeapFree(GetProcessHeap(), 0, pMachine);
498 return CR_FAILURE;
499 }
500 }
501 else
502 {
503 pMachine->bLocal = FALSE;
504 if (wcslen(UNCServerName) >= SP_MAX_MACHINENAME_LENGTH - 1)
505 {
506 HeapFree(GetProcessHeap(), 0, pMachine);
507 return CR_INVALID_MACHINENAME;
508 }
509 lstrcpyW(pMachine->szMachineName, UNCServerName);
510
511 pMachine->StringTable = pSetupStringTableInitialize();
512 if (pMachine->StringTable == NULL)
513 {
514 HeapFree(GetProcessHeap(), 0, pMachine);
515 return CR_FAILURE;
516 }
517
518 pSetupStringTableAddString(pMachine->StringTable, L"PLT", 1);
519
520 if (!PnpBindRpc(UNCServerName, &pMachine->BindingHandle))
521 {
522 pSetupStringTableDestroy(pMachine->StringTable);
523 HeapFree(GetProcessHeap(), 0, pMachine);
524 return CR_INVALID_MACHINENAME;
525 }
526 }
527
528 phMachine = (PHMACHINE)pMachine;
529
530 return CR_SUCCESS;
531 }
532
533
534 /***********************************************************************
535 * CM_Create_DevNodeA [SETUPAPI.@]
536 */
537 CONFIGRET WINAPI CM_Create_DevNodeA(
538 PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, DEVINST dnParent,
539 ULONG ulFlags)
540 {
541 TRACE("%p %s %p %lx\n",
542 pdnDevInst, debugstr_a(pDeviceID), dnParent, ulFlags);
543 return CM_Create_DevNode_ExA(pdnDevInst, pDeviceID, dnParent,
544 ulFlags, NULL);
545 }
546
547
548 /***********************************************************************
549 * CM_Create_DevNodeW [SETUPAPI.@]
550 */
551 CONFIGRET WINAPI CM_Create_DevNodeW(
552 PDEVINST pdnDevInst, DEVINSTID_W pDeviceID, DEVINST dnParent,
553 ULONG ulFlags)
554 {
555 TRACE("%p %s %p %lx\n",
556 pdnDevInst, debugstr_w(pDeviceID), dnParent, ulFlags);
557 return CM_Create_DevNode_ExW(pdnDevInst, pDeviceID, dnParent,
558 ulFlags, NULL);
559 }
560
561
562 /***********************************************************************
563 * CM_Create_DevNode_ExA [SETUPAPI.@]
564 */
565 CONFIGRET WINAPI CM_Create_DevNode_ExA(
566 PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, DEVINST dnParent,
567 ULONG ulFlags, HANDLE hMachine)
568 {
569 DEVINSTID_W pDeviceIDW;
570 CONFIGRET ret;
571
572 TRACE("%p %s %p %lx %p\n",
573 pdnDevInst, debugstr_a(pDeviceID), dnParent, ulFlags, hMachine);
574
575 if (pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDeviceIDW))
576 return CR_INVALID_DATA;
577
578 ret = CM_Create_DevNode_ExW(pdnDevInst, pDeviceIDW, dnParent, ulFlags,
579 hMachine);
580
581 MyFree(pDeviceIDW);
582
583 return ret;
584 }
585
586
587 /***********************************************************************
588 * CM_Create_DevNode_ExW [SETUPAPI.@]
589 */
590 CONFIGRET WINAPI CM_Create_DevNode_ExW(
591 PDEVINST pdnDevInst, DEVINSTID_W pDeviceID, DEVINST dnParent,
592 ULONG ulFlags, HANDLE hMachine)
593 {
594 RPC_BINDING_HANDLE BindingHandle = NULL;
595 HSTRING_TABLE StringTable = NULL;
596 LPWSTR lpParentDevInst;
597 CONFIGRET ret = CR_SUCCESS;
598
599 FIXME("%p %s %p %lx %p\n",
600 pdnDevInst, debugstr_w(pDeviceID), dnParent, ulFlags, hMachine);
601
602 if (!pSetupIsUserAdmin())
603 return CR_ACCESS_DENIED;
604
605 if (pdnDevInst == NULL)
606 return CR_INVALID_POINTER;
607
608 if (pDeviceID == NULL || wcslen(pDeviceID) == 0)
609 return CR_INVALID_DEVICE_ID;
610
611 if (dnParent == 0)
612 return CR_INVALID_DEVNODE;
613
614 if (ulFlags & ~CM_CREATE_DEVNODE_BITS)
615 return CR_INVALID_FLAG;
616
617 if (hMachine != NULL)
618 {
619 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
620 if (BindingHandle == NULL)
621 return CR_FAILURE;
622
623 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
624 if (StringTable == 0)
625 return CR_FAILURE;
626 }
627 else
628 {
629 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
630 return CR_FAILURE;
631 }
632
633 lpParentDevInst = pSetupStringTableStringFromId(StringTable, dnParent);
634 if (lpParentDevInst == NULL)
635 return CR_INVALID_DEVNODE;
636
637 RpcTryExcept
638 {
639 ret = PNP_CreateDevInst(BindingHandle,
640 pDeviceID,
641 lpParentDevInst,
642 MAX_DEVICE_ID_LEN,
643 ulFlags);
644 }
645 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
646 {
647 ret = RpcStatusToCmStatus(RpcExceptionCode());
648 }
649 RpcEndExcept;
650
651 if (ret == CR_SUCCESS)
652 {
653 *pdnDevInst = pSetupStringTableAddString(StringTable, pDeviceID, 1);
654 if (*pdnDevInst == 0)
655 ret = CR_NO_SUCH_DEVNODE;
656 }
657
658 return ret;
659 }
660
661
662 /***********************************************************************
663 * CM_Delete_Class_Key [SETUPAPI.@]
664 */
665 CONFIGRET WINAPI CM_Delete_Class_Key(
666 LPGUID ClassGuid, ULONG ulFlags)
667 {
668 TRACE("%p %lx\n", ClassGuid, ulFlags);
669 return CM_Delete_Class_Key_Ex(ClassGuid, ulFlags, NULL);
670 }
671
672
673 /***********************************************************************
674 * CM_Delete_Class_Key_Ex [SETUPAPI.@]
675 */
676 CONFIGRET WINAPI CM_Delete_Class_Key_Ex(
677 LPGUID ClassGuid, ULONG ulFlags, HANDLE hMachine)
678 {
679 WCHAR szGuidString[MAX_GUID_STRING_LEN];
680 RPC_BINDING_HANDLE BindingHandle = NULL;
681 CONFIGRET ret;
682
683 TRACE("%p %lx %lx\n", ClassGuid, ulFlags, hMachine);
684
685 if (ClassGuid == NULL)
686 return CR_INVALID_POINTER;
687
688 if (ulFlags & ~CM_DELETE_CLASS_BITS)
689 return CR_INVALID_FLAG;
690
691 if (!GuidToString(ClassGuid, szGuidString))
692 return CR_INVALID_DATA;
693
694 if (hMachine != NULL)
695 {
696 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
697 if (BindingHandle == NULL)
698 return CR_FAILURE;
699 }
700 else
701 {
702 if (!PnpGetLocalHandles(&BindingHandle, NULL))
703 return CR_FAILURE;
704 }
705
706 RpcTryExcept
707 {
708 ret = PNP_DeleteClassKey(BindingHandle,
709 szGuidString,
710 ulFlags);
711 }
712 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
713 {
714 ret = RpcStatusToCmStatus(RpcExceptionCode());
715 }
716 RpcEndExcept;
717
718 return ret;
719 }
720
721
722 /***********************************************************************
723 * CM_Delete_DevNode_Key [SETUPAPI.@]
724 */
725 CONFIGRET WINAPI CM_Delete_DevNode_Key(
726 DEVNODE dnDevNode, ULONG ulHardwareProfile, ULONG ulFlags)
727 {
728 TRACE("%p %lu %lx\n", dnDevNode, ulHardwareProfile, ulFlags);
729 return CM_Delete_DevNode_Key_Ex(dnDevNode, ulHardwareProfile, ulFlags,
730 NULL);
731 }
732
733
734 /***********************************************************************
735 * CM_Delete_DevNode_Key_Ex [SETUPAPI.@]
736 */
737 CONFIGRET WINAPI CM_Delete_DevNode_Key_Ex(
738 DEVNODE dnDevNode, ULONG ulHardwareProfile, ULONG ulFlags,
739 HANDLE hMachine)
740 {
741 FIXME("%p %lu %lx %p\n",
742 dnDevNode, ulHardwareProfile, ulFlags, hMachine);
743
744 return CR_CALL_NOT_IMPLEMENTED;
745 }
746
747
748 /***********************************************************************
749 * CM_Disable_DevNode [SETUPAPI.@]
750 */
751 CONFIGRET WINAPI CM_Disable_DevNode(
752 DEVINST dnDevInst, ULONG ulFlags)
753 {
754 TRACE("%p %lx\n", dnDevInst, ulFlags);
755 return CM_Disable_DevNode_Ex(dnDevInst, ulFlags, NULL);
756 }
757
758
759 /***********************************************************************
760 * CM_Disable_DevNode_Ex [SETUPAPI.@]
761 */
762 CONFIGRET WINAPI CM_Disable_DevNode_Ex(
763 DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
764 {
765 RPC_BINDING_HANDLE BindingHandle = NULL;
766 HSTRING_TABLE StringTable = NULL;
767 LPWSTR lpDevInst;
768 CONFIGRET ret;
769
770 FIXME("%p %lx %p\n", dnDevInst, ulFlags, hMachine);
771
772 if (!pSetupIsUserAdmin())
773 return CR_ACCESS_DENIED;
774
775 if (dnDevInst == 0)
776 return CR_INVALID_DEVINST;
777
778 if (ulFlags != 0)
779 return CR_INVALID_FLAG;
780
781 if (hMachine != NULL)
782 {
783 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
784 if (BindingHandle == NULL)
785 return CR_FAILURE;
786
787 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
788 if (StringTable == 0)
789 return CR_FAILURE;
790 }
791 else
792 {
793 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
794 return CR_FAILURE;
795 }
796
797 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
798 if (lpDevInst == NULL)
799 return CR_INVALID_DEVNODE;
800
801 RpcTryExcept
802 {
803 ret = PNP_DeviceInstanceAction(BindingHandle,
804 PNP_DEVINST_DISABLE,
805 ulFlags,
806 lpDevInst,
807 NULL);
808 }
809 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
810 {
811 ret = RpcStatusToCmStatus(RpcExceptionCode());
812 }
813 RpcEndExcept;
814
815 return ret;
816 }
817
818
819 /***********************************************************************
820 * CM_Disconnect_Machine [SETUPAPI.@]
821 */
822 CONFIGRET WINAPI CM_Disconnect_Machine(HMACHINE hMachine)
823 {
824 PMACHINE_INFO pMachine;
825
826 TRACE("%lx\n", hMachine);
827
828 pMachine = (PMACHINE_INFO)hMachine;
829 if (pMachine == NULL)
830 return CR_SUCCESS;
831
832 if (pMachine->bLocal == FALSE)
833 {
834 if (pMachine->StringTable != NULL)
835 pSetupStringTableDestroy(pMachine->StringTable);
836
837 if (!PnpUnbindRpc(pMachine->BindingHandle))
838 return CR_ACCESS_DENIED;
839 }
840
841 HeapFree(GetProcessHeap(), 0, pMachine);
842
843 return CR_SUCCESS;
844 }
845
846
847 /***********************************************************************
848 * CM_Enable_DevNode [SETUPAPI.@]
849 */
850 CONFIGRET WINAPI CM_Enable_DevNode(
851 DEVINST dnDevInst, ULONG ulFlags)
852 {
853 TRACE("%p %lx\n", dnDevInst, ulFlags);
854 return CM_Enable_DevNode_Ex(dnDevInst, ulFlags, NULL);
855 }
856
857
858 /***********************************************************************
859 * CM_Enable_DevNode_Ex [SETUPAPI.@]
860 */
861 CONFIGRET WINAPI CM_Enable_DevNode_Ex(
862 DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
863 {
864 RPC_BINDING_HANDLE BindingHandle = NULL;
865 HSTRING_TABLE StringTable = NULL;
866 LPWSTR lpDevInst;
867 CONFIGRET ret;
868
869 TRACE("%p %lx %p\n", dnDevInst, ulFlags, hMachine);
870
871 if (!pSetupIsUserAdmin())
872 return CR_ACCESS_DENIED;
873
874 if (dnDevInst == 0)
875 return CR_INVALID_DEVINST;
876
877 if (ulFlags != 0)
878 return CR_INVALID_FLAG;
879
880 if (hMachine != NULL)
881 {
882 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
883 if (BindingHandle == NULL)
884 return CR_FAILURE;
885
886 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
887 if (StringTable == 0)
888 return CR_FAILURE;
889 }
890 else
891 {
892 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
893 return CR_FAILURE;
894 }
895
896 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
897 if (lpDevInst == NULL)
898 return CR_INVALID_DEVNODE;
899
900 RpcTryExcept
901 {
902 ret = PNP_DeviceInstanceAction(BindingHandle,
903 PNP_DEVINST_ENABLE,
904 ulFlags,
905 lpDevInst,
906 NULL);
907 }
908 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
909 {
910 ret = RpcStatusToCmStatus(RpcExceptionCode());
911 }
912 RpcEndExcept;
913
914 return ret;
915 }
916
917
918 /***********************************************************************
919 * CM_Enumerate_Classes [SETUPAPI.@]
920 */
921 CONFIGRET WINAPI CM_Enumerate_Classes(
922 ULONG ulClassIndex, LPGUID ClassGuid, ULONG ulFlags)
923 {
924 TRACE("%lx %p %lx\n", ulClassIndex, ClassGuid, ulFlags);
925 return CM_Enumerate_Classes_Ex(ulClassIndex, ClassGuid, ulFlags, NULL);
926 }
927
928
929 /***********************************************************************
930 * CM_Enumerate_Classes_Ex [SETUPAPI.@]
931 */
932 CONFIGRET WINAPI CM_Enumerate_Classes_Ex(
933 ULONG ulClassIndex, LPGUID ClassGuid, ULONG ulFlags, HMACHINE hMachine)
934 {
935 WCHAR szBuffer[MAX_GUID_STRING_LEN];
936 RPC_BINDING_HANDLE BindingHandle = NULL;
937 CONFIGRET ret = CR_SUCCESS;
938 ULONG ulLength = MAX_GUID_STRING_LEN;
939
940 TRACE("%lx %p %lx %p\n", ulClassIndex, ClassGuid, ulFlags, hMachine);
941
942 if (ClassGuid == NULL)
943 return CR_INVALID_POINTER;
944
945 if (ulFlags != 0)
946 return CR_INVALID_FLAG;
947
948 if (hMachine != NULL)
949 {
950 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
951 if (BindingHandle == NULL)
952 return CR_FAILURE;
953 }
954 else
955 {
956 if (!PnpGetLocalHandles(&BindingHandle, NULL))
957 return CR_FAILURE;
958 }
959
960 RpcTryExcept
961 {
962 ret = PNP_EnumerateSubKeys(BindingHandle,
963 PNP_CLASS_SUBKEYS,
964 ulClassIndex,
965 szBuffer,
966 MAX_GUID_STRING_LEN,
967 &ulLength,
968 ulFlags);
969 }
970 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
971 {
972 ret = RpcStatusToCmStatus(RpcExceptionCode());
973 }
974 RpcEndExcept;
975
976 if (ret == CR_SUCCESS)
977 {
978 /* Remove the {} */
979 szBuffer[MAX_GUID_STRING_LEN - 2] = UNICODE_NULL;
980
981 /* Convert the buffer to a GUID */
982 if (UuidFromStringW(&szBuffer[1], ClassGuid) != RPC_S_OK)
983 return CR_FAILURE;
984 }
985
986 return ret;
987 }
988
989
990 /***********************************************************************
991 * CM_Enumerate_EnumeratorsA [SETUPAPI.@]
992 */
993 CONFIGRET WINAPI CM_Enumerate_EnumeratorsA(
994 ULONG ulEnumIndex, PCHAR Buffer, PULONG pulLength, ULONG ulFlags)
995 {
996 TRACE("%lu %p %p %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags);
997 return CM_Enumerate_Enumerators_ExA(ulEnumIndex, Buffer, pulLength,
998 ulFlags, NULL);
999 }
1000
1001
1002 /***********************************************************************
1003 * CM_Enumerate_EnumeratorsW [SETUPAPI.@]
1004 */
1005 CONFIGRET WINAPI CM_Enumerate_EnumeratorsW(
1006 ULONG ulEnumIndex, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1007 {
1008 TRACE("%lu %p %p %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags);
1009 return CM_Enumerate_Enumerators_ExW(ulEnumIndex, Buffer, pulLength,
1010 ulFlags, NULL);
1011 }
1012
1013
1014 /***********************************************************************
1015 * CM_Enumerate_Enumerators_ExA [SETUPAPI.@]
1016 */
1017 CONFIGRET WINAPI CM_Enumerate_Enumerators_ExA(
1018 ULONG ulEnumIndex, PCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1019 HMACHINE hMachine)
1020 {
1021 WCHAR szBuffer[MAX_DEVICE_ID_LEN];
1022 ULONG ulOrigLength;
1023 ULONG ulLength;
1024 CONFIGRET ret = CR_SUCCESS;
1025
1026 TRACE("%lu %p %p %lx %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags,
1027 hMachine);
1028
1029 if (Buffer == NULL || pulLength == NULL)
1030 return CR_INVALID_POINTER;
1031
1032 if (ulFlags != 0)
1033 return CR_INVALID_FLAG;
1034
1035 ulOrigLength = *pulLength;
1036 *pulLength = 0;
1037
1038 ulLength = MAX_DEVICE_ID_LEN;
1039 ret = CM_Enumerate_Enumerators_ExW(ulEnumIndex, szBuffer, &ulLength,
1040 ulFlags, hMachine);
1041 if (ret == CR_SUCCESS)
1042 {
1043 if (WideCharToMultiByte(CP_ACP,
1044 0,
1045 szBuffer,
1046 ulLength,
1047 Buffer,
1048 ulOrigLength,
1049 NULL,
1050 NULL) == 0)
1051 ret = CR_FAILURE;
1052 else
1053 *pulLength = lstrlenA(Buffer) + 1;
1054 }
1055
1056 return ret;
1057 }
1058
1059
1060 /***********************************************************************
1061 * CM_Enumerate_Enumerators_ExW [SETUPAPI.@]
1062 */
1063 CONFIGRET WINAPI CM_Enumerate_Enumerators_ExW(
1064 ULONG ulEnumIndex, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1065 HMACHINE hMachine)
1066 {
1067 RPC_BINDING_HANDLE BindingHandle = NULL;
1068 CONFIGRET ret;
1069
1070 TRACE("%lu %p %p %lx %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags,
1071 hMachine);
1072
1073 if (Buffer == NULL || pulLength == NULL)
1074 return CR_INVALID_POINTER;
1075
1076 if (ulFlags != 0)
1077 return CR_INVALID_FLAG;
1078
1079 *Buffer = UNICODE_NULL;
1080
1081 if (hMachine != NULL)
1082 {
1083 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1084 if (BindingHandle == NULL)
1085 return CR_FAILURE;
1086 }
1087 else
1088 {
1089 if (!PnpGetLocalHandles(&BindingHandle, NULL))
1090 return CR_FAILURE;
1091 }
1092
1093 RpcTryExcept
1094 {
1095 ret = PNP_EnumerateSubKeys(BindingHandle,
1096 PNP_ENUMERATOR_SUBKEYS,
1097 ulEnumIndex,
1098 Buffer,
1099 *pulLength,
1100 pulLength,
1101 ulFlags);
1102 }
1103 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1104 {
1105 ret = RpcStatusToCmStatus(RpcExceptionCode());
1106 }
1107 RpcEndExcept;
1108
1109 return ret;
1110 }
1111
1112
1113 /***********************************************************************
1114 * CM_Free_Log_Conf [SETUPAPI.@]
1115 */
1116 CONFIGRET WINAPI CM_Free_Log_Conf(
1117 LOG_CONF lcLogConfToBeFreed, ULONG ulFlags)
1118 {
1119 TRACE("%lx %lx\n", lcLogConfToBeFreed, ulFlags);
1120 return CM_Free_Log_Conf_Ex(lcLogConfToBeFreed, ulFlags, NULL);
1121 }
1122
1123
1124 /***********************************************************************
1125 * CM_Free_Log_Conf_Ex [SETUPAPI.@]
1126 */
1127 CONFIGRET WINAPI CM_Free_Log_Conf_Ex(
1128 LOG_CONF lcLogConfToBeFreed, ULONG ulFlags, HMACHINE hMachine)
1129 {
1130 RPC_BINDING_HANDLE BindingHandle = NULL;
1131 HSTRING_TABLE StringTable = NULL;
1132 LPWSTR lpDevInst;
1133 PLOG_CONF_INFO pLogConfInfo;
1134 CONFIGRET ret;
1135
1136 TRACE("%lx %lx %lx\n", lcLogConfToBeFreed, ulFlags, hMachine);
1137
1138 if (!pSetupIsUserAdmin())
1139 return CR_ACCESS_DENIED;
1140
1141 pLogConfInfo = (PLOG_CONF_INFO)lcLogConfToBeFreed;
1142 if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
1143 return CR_INVALID_LOG_CONF;
1144
1145 if (ulFlags != 0)
1146 return CR_INVALID_FLAG;
1147
1148 if (hMachine != NULL)
1149 {
1150 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1151 if (BindingHandle == NULL)
1152 return CR_FAILURE;
1153
1154 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1155 if (StringTable == 0)
1156 return CR_FAILURE;
1157 }
1158 else
1159 {
1160 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1161 return CR_FAILURE;
1162 }
1163
1164 lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
1165 if (lpDevInst == NULL)
1166 return CR_INVALID_DEVNODE;
1167
1168 RpcTryExcept
1169 {
1170 ret = PNP_FreeLogConf(BindingHandle, lpDevInst, pLogConfInfo->ulFlags,
1171 pLogConfInfo->ulTag, 0);
1172 }
1173 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1174 {
1175 ret = RpcStatusToCmStatus(RpcExceptionCode());
1176 }
1177 RpcEndExcept;
1178
1179 return ret;
1180 }
1181
1182
1183 /***********************************************************************
1184 * CM_Free_Log_Conf_Handle [SETUPAPI.@]
1185 */
1186 CONFIGRET WINAPI CM_Free_Log_Conf_Handle(
1187 LOG_CONF lcLogConf)
1188 {
1189 PLOG_CONF_INFO pLogConfInfo;
1190
1191 TRACE("%lx\n", lcLogConf);
1192
1193 pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
1194 if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
1195 return CR_INVALID_LOG_CONF;
1196
1197 HeapFree(GetProcessHeap(), 0, pLogConfInfo);
1198
1199 return CR_SUCCESS;
1200 }
1201
1202
1203 /***********************************************************************
1204 * CM_Free_Res_Des [SETUPAPI.@]
1205 */
1206 CONFIGRET WINAPI CM_Free_Res_Des(
1207 PRES_DES prdResDes, RES_DES rdResDes, ULONG ulFlags)
1208 {
1209 TRACE("%p %p %lx\n", prdResDes, rdResDes, ulFlags);
1210 return CM_Free_Res_Des_Ex(prdResDes, rdResDes, ulFlags, NULL);
1211 }
1212
1213
1214 /***********************************************************************
1215 * CM_Free_Res_Des_Ex [SETUPAPI.@]
1216 */
1217 CONFIGRET WINAPI CM_Free_Res_Des_Ex(
1218 PRES_DES prdResDes, RES_DES rdResDes, ULONG ulFlags,
1219 HMACHINE hMachine)
1220 {
1221 FIXME("%p %p %lx %lx\n", prdResDes, rdResDes, ulFlags, hMachine);
1222
1223 return CR_CALL_NOT_IMPLEMENTED;
1224 }
1225
1226
1227 /***********************************************************************
1228 * CM_Free_Res_Des_Handle [SETUPAPI.@]
1229 */
1230 CONFIGRET WINAPI CM_Free_Res_Des_Handle(
1231 RES_DES rdResDes)
1232 {
1233 FIXME("%p\n", rdResDes);
1234
1235 return CR_CALL_NOT_IMPLEMENTED;
1236 }
1237
1238
1239 /***********************************************************************
1240 * CM_Get_Child [SETUPAPI.@]
1241 */
1242 CONFIGRET WINAPI CM_Get_Child(
1243 PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags)
1244 {
1245 TRACE("%p %p %lx\n", pdnDevInst, dnDevInst, ulFlags);
1246 return CM_Get_Child_Ex(pdnDevInst, dnDevInst, ulFlags, NULL);
1247 }
1248
1249
1250 /***********************************************************************
1251 * CM_Get_Child_Ex [SETUPAPI.@]
1252 */
1253 CONFIGRET WINAPI CM_Get_Child_Ex(
1254 PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
1255 {
1256 WCHAR szRelatedDevInst[MAX_DEVICE_ID_LEN];
1257 RPC_BINDING_HANDLE BindingHandle = NULL;
1258 HSTRING_TABLE StringTable = NULL;
1259 LPWSTR lpDevInst;
1260 DWORD dwIndex, dwLength = MAX_DEVICE_ID_LEN;
1261 CONFIGRET ret;
1262
1263 TRACE("%p %lx %lx %lx\n", pdnDevInst, dnDevInst, ulFlags, hMachine);
1264
1265 if (pdnDevInst == NULL)
1266 return CR_INVALID_POINTER;
1267
1268 if (dnDevInst == 0)
1269 return CR_INVALID_DEVINST;
1270
1271 if (ulFlags != 0)
1272 return CR_INVALID_FLAG;
1273
1274 *pdnDevInst = -1;
1275
1276 if (hMachine != NULL)
1277 {
1278 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1279 if (BindingHandle == NULL)
1280 return CR_FAILURE;
1281
1282 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1283 if (StringTable == 0)
1284 return CR_FAILURE;
1285 }
1286 else
1287 {
1288 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1289 return CR_FAILURE;
1290 }
1291
1292 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1293 if (lpDevInst == NULL)
1294 return CR_INVALID_DEVNODE;
1295
1296 RpcTryExcept
1297 {
1298 ret = PNP_GetRelatedDeviceInstance(BindingHandle,
1299 PNP_GET_CHILD_DEVICE_INSTANCE,
1300 lpDevInst,
1301 szRelatedDevInst,
1302 &dwLength,
1303 0);
1304 }
1305 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1306 {
1307 ret = RpcStatusToCmStatus(RpcExceptionCode());
1308 }
1309 RpcEndExcept;
1310
1311 if (ret != CR_SUCCESS)
1312 return ret;
1313
1314 TRACE("szRelatedDevInst: %s\n", debugstr_w(szRelatedDevInst));
1315
1316 dwIndex = pSetupStringTableAddString(StringTable, szRelatedDevInst, 1);
1317 if (dwIndex == -1)
1318 return CR_FAILURE;
1319
1320 *pdnDevInst = dwIndex;
1321
1322 return CR_SUCCESS;
1323 }
1324
1325
1326 /***********************************************************************
1327 * CM_Get_Class_Key_NameA [SETUPAPI.@]
1328 */
1329 CONFIGRET WINAPI CM_Get_Class_Key_NameA(
1330 LPGUID ClassGuid, LPSTR pszKeyName, PULONG pulLength, ULONG ulFlags)
1331 {
1332 TRACE("%p %p %p %lx\n",
1333 ClassGuid, pszKeyName, pulLength, ulFlags);
1334 return CM_Get_Class_Key_Name_ExA(ClassGuid, pszKeyName, pulLength,
1335 ulFlags, NULL);
1336 }
1337
1338
1339 /***********************************************************************
1340 * CM_Get_Class_Key_NameW [SETUPAPI.@]
1341 */
1342 CONFIGRET WINAPI CM_Get_Class_Key_NameW(
1343 LPGUID ClassGuid, LPWSTR pszKeyName, PULONG pulLength, ULONG ulFlags)
1344 {
1345 TRACE("%p %p %p %lx\n",
1346 ClassGuid, pszKeyName, pulLength, ulFlags);
1347 return CM_Get_Class_Key_Name_ExW(ClassGuid, pszKeyName, pulLength,
1348 ulFlags, NULL);
1349 }
1350
1351
1352 /***********************************************************************
1353 * CM_Get_Class_Key_Name_ExA [SETUPAPI.@]
1354 */
1355 CONFIGRET WINAPI CM_Get_Class_Key_Name_ExA(
1356 LPGUID ClassGuid, LPSTR pszKeyName, PULONG pulLength, ULONG ulFlags,
1357 HMACHINE hMachine)
1358 {
1359 WCHAR szBuffer[MAX_GUID_STRING_LEN];
1360 CONFIGRET ret = CR_SUCCESS;
1361 ULONG ulLength;
1362 ULONG ulOrigLength;
1363
1364 TRACE("%p %p %p %lx %lx\n",
1365 ClassGuid, pszKeyName, pulLength, ulFlags, hMachine);
1366
1367 if (ClassGuid == NULL || pszKeyName == NULL || pulLength == NULL)
1368 return CR_INVALID_POINTER;
1369
1370 ulOrigLength = *pulLength;
1371 *pulLength = 0;
1372
1373 ulLength = MAX_GUID_STRING_LEN;
1374 ret = CM_Get_Class_Key_Name_ExW(ClassGuid, szBuffer, &ulLength,
1375 ulFlags, hMachine);
1376 if (ret == CR_SUCCESS)
1377 {
1378 if (WideCharToMultiByte(CP_ACP,
1379 0,
1380 szBuffer,
1381 ulLength,
1382 pszKeyName,
1383 ulOrigLength,
1384 NULL,
1385 NULL) == 0)
1386 ret = CR_FAILURE;
1387 else
1388 *pulLength = lstrlenA(pszKeyName) + 1;
1389 }
1390
1391 return CR_SUCCESS;
1392 }
1393
1394
1395 /***********************************************************************
1396 * CM_Get_Class_Key_Name_ExW [SETUPAPI.@]
1397 */
1398 CONFIGRET WINAPI CM_Get_Class_Key_Name_ExW(
1399 LPGUID ClassGuid, LPWSTR pszKeyName, PULONG pulLength, ULONG ulFlags,
1400 HMACHINE hMachine)
1401 {
1402 TRACE("%p %p %p %lx %lx\n",
1403 ClassGuid, pszKeyName, pulLength, ulFlags, hMachine);
1404
1405 if (ClassGuid == NULL || pszKeyName == NULL || pulLength == NULL)
1406 return CR_INVALID_POINTER;
1407
1408 if (ulFlags != 0)
1409 return CR_INVALID_FLAG;
1410
1411 if (*pulLength < MAX_GUID_STRING_LEN)
1412 {
1413 *pulLength = 0;
1414 return CR_BUFFER_SMALL;
1415 }
1416
1417 if (!GuidToString(ClassGuid, pszKeyName))
1418 return CR_INVALID_DATA;
1419
1420 *pulLength = MAX_GUID_STRING_LEN;
1421
1422 return CR_SUCCESS;
1423 }
1424
1425
1426 /***********************************************************************
1427 * CM_Get_Class_NameA [SETUPAPI.@]
1428 */
1429 CONFIGRET WINAPI CM_Get_Class_NameA(
1430 LPGUID ClassGuid, PCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1431 {
1432 TRACE("%p %p %p %lx\n", ClassGuid, Buffer, pulLength, ulFlags);
1433 return CM_Get_Class_Name_ExA(ClassGuid, Buffer, pulLength, ulFlags,
1434 NULL);
1435 }
1436
1437
1438 /***********************************************************************
1439 * CM_Get_Class_NameW [SETUPAPI.@]
1440 */
1441 CONFIGRET WINAPI CM_Get_Class_NameW(
1442 LPGUID ClassGuid, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1443 {
1444 TRACE("%p %p %p %lx\n", ClassGuid, Buffer, pulLength, ulFlags);
1445 return CM_Get_Class_Name_ExW(ClassGuid, Buffer, pulLength, ulFlags,
1446 NULL);
1447 }
1448
1449
1450 /***********************************************************************
1451 * CM_Get_Class_Name_ExA [SETUPAPI.@]
1452 */
1453 CONFIGRET WINAPI CM_Get_Class_Name_ExA(
1454 LPGUID ClassGuid, PCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1455 HMACHINE hMachine)
1456 {
1457 WCHAR szBuffer[MAX_CLASS_NAME_LEN];
1458 CONFIGRET ret = CR_SUCCESS;
1459 ULONG ulLength;
1460 ULONG ulOrigLength;
1461
1462 TRACE("%p %p %p %lx %lx\n",
1463 ClassGuid, Buffer, pulLength, ulFlags, hMachine);
1464
1465 if (ClassGuid == NULL || Buffer == NULL || pulLength == NULL)
1466 return CR_INVALID_POINTER;
1467
1468 ulOrigLength = *pulLength;
1469 *pulLength = 0;
1470
1471 ulLength = MAX_CLASS_NAME_LEN;
1472 ret = CM_Get_Class_Name_ExW(ClassGuid, szBuffer, &ulLength,
1473 ulFlags, hMachine);
1474 if (ret == CR_SUCCESS)
1475 {
1476 if (WideCharToMultiByte(CP_ACP,
1477 0,
1478 szBuffer,
1479 ulLength,
1480 Buffer,
1481 ulOrigLength,
1482 NULL,
1483 NULL) == 0)
1484 ret = CR_FAILURE;
1485 else
1486 *pulLength = lstrlenA(Buffer) + 1;
1487 }
1488
1489 return ret;
1490 }
1491
1492
1493 /***********************************************************************
1494 * CM_Get_Class_Name_ExW [SETUPAPI.@]
1495 */
1496 CONFIGRET WINAPI
1497 CM_Get_Class_Name_ExW(
1498 LPGUID ClassGuid, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1499 HMACHINE hMachine)
1500 {
1501 WCHAR szGuidString[MAX_GUID_STRING_LEN];
1502 RPC_BINDING_HANDLE BindingHandle = NULL;
1503 CONFIGRET ret;
1504
1505 TRACE("%p %p %p %lx %lx\n",
1506 ClassGuid, Buffer, pulLength, ulFlags, hMachine);
1507
1508 if (ClassGuid == NULL || Buffer == NULL || pulLength == NULL)
1509 return CR_INVALID_POINTER;
1510
1511 if (ulFlags != 0)
1512 return CR_INVALID_FLAG;
1513
1514 if (!GuidToString(ClassGuid, szGuidString))
1515 return CR_INVALID_DATA;
1516
1517 TRACE("Guid %s\n", debugstr_w(szGuidString));
1518
1519 if (hMachine != NULL)
1520 {
1521 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1522 if (BindingHandle == NULL)
1523 return CR_FAILURE;
1524 }
1525 else
1526 {
1527 if (!PnpGetLocalHandles(&BindingHandle, NULL))
1528 return CR_FAILURE;
1529 }
1530
1531 RpcTryExcept
1532 {
1533 ret = PNP_GetClassName(BindingHandle,
1534 szGuidString,
1535 Buffer,
1536 pulLength,
1537 ulFlags);
1538 }
1539 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1540 {
1541 ret = RpcStatusToCmStatus(RpcExceptionCode());
1542 }
1543 RpcEndExcept;
1544
1545 return ret;
1546 }
1547
1548
1549 /***********************************************************************
1550 * CM_Get_Depth [SETUPAPI.@]
1551 */
1552 CONFIGRET WINAPI CM_Get_Depth(
1553 PULONG pulDepth, DEVINST dnDevInst, ULONG ulFlags)
1554 {
1555 TRACE("%p %lx %lx\n", pulDepth, dnDevInst, ulFlags);
1556 return CM_Get_Depth_Ex(pulDepth, dnDevInst, ulFlags, NULL);
1557 }
1558
1559
1560 /***********************************************************************
1561 * CM_Get_Depth_Ex [SETUPAPI.@]
1562 */
1563 CONFIGRET WINAPI CM_Get_Depth_Ex(
1564 PULONG pulDepth, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
1565 {
1566 RPC_BINDING_HANDLE BindingHandle = NULL;
1567 HSTRING_TABLE StringTable = NULL;
1568 LPWSTR lpDevInst;
1569 CONFIGRET ret;
1570
1571 TRACE("%p %lx %lx %lx\n",
1572 pulDepth, dnDevInst, ulFlags, hMachine);
1573
1574 if (pulDepth == NULL)
1575 return CR_INVALID_POINTER;
1576
1577 if (dnDevInst == 0)
1578 return CR_INVALID_DEVINST;
1579
1580 if (ulFlags != 0)
1581 return CR_INVALID_FLAG;
1582
1583 if (hMachine != NULL)
1584 {
1585 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1586 if (BindingHandle == NULL)
1587 return CR_FAILURE;
1588
1589 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1590 if (StringTable == 0)
1591 return CR_FAILURE;
1592 }
1593 else
1594 {
1595 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1596 return CR_FAILURE;
1597 }
1598
1599 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1600 if (lpDevInst == NULL)
1601 return CR_INVALID_DEVNODE;
1602
1603 RpcTryExcept
1604 {
1605 ret = PNP_GetDepth(BindingHandle,
1606 lpDevInst,
1607 pulDepth,
1608 ulFlags);
1609 }
1610 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1611 {
1612 ret = RpcStatusToCmStatus(RpcExceptionCode());
1613 }
1614 RpcEndExcept;
1615
1616 return ret;
1617 }
1618
1619
1620 /***********************************************************************
1621 * CM_Get_DevNode_Registry_PropertyA [SETUPAPI.@]
1622 */
1623 CONFIGRET WINAPI CM_Get_DevNode_Registry_PropertyA(
1624 DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
1625 PVOID Buffer, PULONG pulLength, ULONG ulFlags)
1626 {
1627 TRACE("%lx %lu %p %p %p %lx\n",
1628 dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength, ulFlags);
1629
1630 return CM_Get_DevNode_Registry_Property_ExA(dnDevInst, ulProperty,
1631 pulRegDataType, Buffer,
1632 pulLength, ulFlags, NULL);
1633 }
1634
1635
1636 /***********************************************************************
1637 * CM_Get_DevNode_Registry_PropertyW [SETUPAPI.@]
1638 */
1639 CONFIGRET WINAPI CM_Get_DevNode_Registry_PropertyW(
1640 DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
1641 PVOID Buffer, PULONG pulLength, ULONG ulFlags)
1642 {
1643 TRACE("%lx %lu %p %p %p %lx\n",
1644 dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength, ulFlags);
1645
1646 return CM_Get_DevNode_Registry_Property_ExW(dnDevInst, ulProperty,
1647 pulRegDataType, Buffer,
1648 pulLength, ulFlags, NULL);
1649 }
1650
1651
1652 /***********************************************************************
1653 * CM_Get_DevNode_Registry_Property_ExA [SETUPAPI.@]
1654 */
1655 CONFIGRET WINAPI CM_Get_DevNode_Registry_Property_ExA(
1656 DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
1657 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
1658 {
1659 PVOID BufferW;
1660 ULONG LengthW;
1661 ULONG RegDataType = REG_NONE;
1662 CONFIGRET ret;
1663
1664 TRACE("%lx %lu %p %p %p %lx %lx\n",
1665 dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength,
1666 ulFlags, hMachine);
1667
1668 if (!pulLength)
1669 return CR_INVALID_POINTER;
1670
1671 LengthW = *pulLength * sizeof(WCHAR);
1672 BufferW = HeapAlloc(GetProcessHeap(), 0, LengthW);
1673
1674 if (!BufferW)
1675 return CR_OUT_OF_MEMORY;
1676
1677 ret = CM_Get_DevNode_Registry_Property_ExW(dnDevInst,
1678 ulProperty,
1679 &RegDataType,
1680 BufferW,
1681 &LengthW,
1682 ulFlags,
1683 hMachine);
1684
1685 if (ret == CR_SUCCESS)
1686 {
1687 if (RegDataType == REG_SZ || RegDataType == REG_EXPAND_SZ)
1688 {
1689 /* Do W->A conversion */
1690 *pulLength = WideCharToMultiByte(CP_ACP,
1691 0,
1692 BufferW,
1693 lstrlenW(BufferW) + 1,
1694 Buffer,
1695 *pulLength,
1696 NULL,
1697 NULL);
1698 if (*pulLength == 0)
1699 ret = CR_FAILURE;
1700 }
1701 else
1702 {
1703 /* Directly copy the value */
1704 if (LengthW <= *pulLength)
1705 memcpy(Buffer, BufferW, LengthW);
1706 else
1707 {
1708 *pulLength = LengthW;
1709 ret = CR_BUFFER_SMALL;
1710 }
1711 }
1712 }
1713
1714 if (pulRegDataType)
1715 *pulRegDataType = RegDataType;
1716
1717 HeapFree(GetProcessHeap(), 0, BufferW);
1718
1719 return ret;
1720 }
1721
1722
1723 /***********************************************************************
1724 * CM_Get_DevNode_Registry_Property_ExW [SETUPAPI.@]
1725 */
1726 CONFIGRET WINAPI CM_Get_DevNode_Registry_Property_ExW(
1727 DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
1728 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
1729 {
1730 RPC_BINDING_HANDLE BindingHandle = NULL;
1731 HSTRING_TABLE StringTable = NULL;
1732 CONFIGRET ret = CR_SUCCESS;
1733 LPWSTR lpDevInst;
1734 ULONG ulDataType = 0;
1735 ULONG ulTransferLength = 0;
1736
1737 TRACE("%lx %lu %p %p %p %lx %lx\n",
1738 dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength,
1739 ulFlags, hMachine);
1740
1741 if (dnDevInst == 0)
1742 return CR_INVALID_DEVNODE;
1743
1744 if (ulProperty < CM_DRP_MIN || ulProperty > CM_DRP_MAX)
1745 return CR_INVALID_PROPERTY;
1746
1747 /* pulRegDataType is optional */
1748
1749 /* Buffer is optional */
1750
1751 if (pulLength == NULL)
1752 return CR_INVALID_POINTER;
1753
1754 if (*pulLength == 0)
1755 return CR_INVALID_POINTER;
1756
1757 if (ulFlags != 0)
1758 return CR_INVALID_FLAG;
1759
1760 if (hMachine != NULL)
1761 {
1762 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1763 if (BindingHandle == NULL)
1764 return CR_FAILURE;
1765
1766 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1767 if (StringTable == 0)
1768 return CR_FAILURE;
1769 }
1770 else
1771 {
1772 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1773 return CR_FAILURE;
1774 }
1775
1776 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1777 if (lpDevInst == NULL)
1778 return CR_INVALID_DEVNODE;
1779
1780 ulTransferLength = *pulLength;
1781
1782 RpcTryExcept
1783 {
1784 ret = PNP_GetDeviceRegProp(BindingHandle,
1785 lpDevInst,
1786 ulProperty,
1787 &ulDataType,
1788 Buffer,
1789 &ulTransferLength,
1790 pulLength,
1791 ulFlags);
1792 }
1793 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1794 {
1795 ret = RpcStatusToCmStatus(RpcExceptionCode());
1796 }
1797 RpcEndExcept;
1798
1799 if (ret == CR_SUCCESS)
1800 {
1801 if (pulRegDataType != NULL)
1802 *pulRegDataType = ulDataType;
1803 }
1804
1805 return ret;
1806 }
1807
1808
1809 /***********************************************************************
1810 * CM_Get_DevNode_Status [SETUPAPI.@]
1811 */
1812 CONFIGRET WINAPI CM_Get_DevNode_Status(
1813 PULONG pulStatus, PULONG pulProblemNumber, DEVINST dnDevInst,
1814 ULONG ulFlags)
1815 {
1816 TRACE("%p %p %lx %lx\n",
1817 pulStatus, pulProblemNumber, dnDevInst, ulFlags);
1818 return CM_Get_DevNode_Status_Ex(pulStatus, pulProblemNumber, dnDevInst,
1819 ulFlags, NULL);
1820 }
1821
1822
1823 /***********************************************************************
1824 * CM_Get_DevNode_Status_Ex [SETUPAPI.@]
1825 */
1826 CONFIGRET WINAPI
1827 CM_Get_DevNode_Status_Ex(
1828 PULONG pulStatus, PULONG pulProblemNumber, DEVINST dnDevInst,
1829 ULONG ulFlags, HMACHINE hMachine)
1830 {
1831 RPC_BINDING_HANDLE BindingHandle = NULL;
1832 HSTRING_TABLE StringTable = NULL;
1833 LPWSTR lpDevInst;
1834 CONFIGRET ret;
1835
1836 TRACE("%p %p %lx %lx %lx\n",
1837 pulStatus, pulProblemNumber, dnDevInst, ulFlags, hMachine);
1838
1839 if (pulStatus == NULL || pulProblemNumber == NULL)
1840 return CR_INVALID_POINTER;
1841
1842 if (dnDevInst == 0)
1843 return CR_INVALID_DEVINST;
1844
1845 if (ulFlags != 0)
1846 return CR_INVALID_FLAG;
1847
1848 if (hMachine != NULL)
1849 {
1850 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1851 if (BindingHandle == NULL)
1852 return CR_FAILURE;
1853
1854 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1855 if (StringTable == 0)
1856 return CR_FAILURE;
1857 }
1858 else
1859 {
1860 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1861 return CR_FAILURE;
1862 }
1863
1864 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1865 if (lpDevInst == NULL)
1866 return CR_INVALID_DEVNODE;
1867
1868 RpcTryExcept
1869 {
1870 ret = PNP_GetDeviceStatus(BindingHandle,
1871 lpDevInst,
1872 pulStatus,
1873 pulProblemNumber,
1874 ulFlags);
1875 }
1876 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1877 {
1878 ret = RpcStatusToCmStatus(RpcExceptionCode());
1879 }
1880 RpcEndExcept;
1881
1882 return ret;
1883 }
1884
1885
1886 /***********************************************************************
1887 * CM_Get_Device_IDA [SETUPAPI.@]
1888 */
1889 CONFIGRET WINAPI CM_Get_Device_IDA(
1890 DEVINST dnDevInst, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
1891 {
1892 TRACE("%lx %p %ld %ld\n",
1893 dnDevInst, Buffer, BufferLen, ulFlags);
1894 return CM_Get_Device_ID_ExA(dnDevInst, Buffer, BufferLen, ulFlags, NULL);
1895 }
1896
1897
1898 /***********************************************************************
1899 * CM_Get_Device_IDW [SETUPAPI.@]
1900 */
1901 CONFIGRET WINAPI CM_Get_Device_IDW(
1902 DEVINST dnDevInst, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
1903 {
1904 TRACE("%lx %p %ld %ld\n",
1905 dnDevInst, Buffer, BufferLen, ulFlags);
1906 return CM_Get_Device_ID_ExW(dnDevInst, Buffer, BufferLen, ulFlags, NULL);
1907 }
1908
1909
1910 /***********************************************************************
1911 * CM_Get_Device_ID_ExA [SETUPAPI.@]
1912 */
1913 CONFIGRET WINAPI CM_Get_Device_ID_ExA(
1914 DEVINST dnDevInst, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
1915 HMACHINE hMachine)
1916 {
1917 WCHAR szBufferW[MAX_DEVICE_ID_LEN];
1918 CONFIGRET ret = CR_SUCCESS;
1919
1920 TRACE("%lx %p %ld %ld %lx\n",
1921 dnDevInst, Buffer, BufferLen, ulFlags, hMachine);
1922
1923 if (Buffer == NULL)
1924 return CR_INVALID_POINTER;
1925
1926 ret = CM_Get_Device_ID_ExW(dnDevInst,
1927 szBufferW,
1928 MAX_DEVICE_ID_LEN,
1929 ulFlags,
1930 hMachine);
1931 if (ret == CR_SUCCESS)
1932 {
1933 if (WideCharToMultiByte(CP_ACP,
1934 0,
1935 szBufferW,
1936 lstrlenW(szBufferW) + 1,
1937 Buffer,
1938 BufferLen,
1939 NULL,
1940 NULL) == 0)
1941 ret = CR_FAILURE;
1942 }
1943
1944 return ret;
1945 }
1946
1947
1948 /***********************************************************************
1949 * CM_Get_Device_ID_ExW [SETUPAPI.@]
1950 */
1951 CONFIGRET WINAPI CM_Get_Device_ID_ExW(
1952 DEVINST dnDevInst, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
1953 HMACHINE hMachine)
1954 {
1955 HSTRING_TABLE StringTable = NULL;
1956
1957 TRACE("%lx %p %ld %ld %lx\n",
1958 dnDevInst, Buffer, BufferLen, ulFlags, hMachine);
1959
1960 if (dnDevInst == 0)
1961 return CR_INVALID_DEVINST;
1962
1963 if (Buffer == NULL)
1964 return CR_INVALID_POINTER;
1965
1966 if (ulFlags != 0)
1967 return CR_INVALID_FLAG;
1968
1969 if (hMachine != NULL)
1970 {
1971 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1972 if (StringTable == NULL)
1973 return CR_FAILURE;
1974 }
1975 else
1976 {
1977 if (!PnpGetLocalHandles(NULL, &StringTable))
1978 return CR_FAILURE;
1979 }
1980
1981 if (!pSetupStringTableStringFromIdEx(StringTable,
1982 dnDevInst,
1983 Buffer,
1984 &BufferLen))
1985 return CR_FAILURE;
1986
1987 return CR_SUCCESS;
1988 }
1989
1990
1991 /***********************************************************************
1992 * CM_Get_Device_ID_ListA [SETUPAPI.@]
1993 */
1994 CONFIGRET WINAPI CM_Get_Device_ID_ListA(
1995 PCSTR pszFilter, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
1996 {
1997 TRACE("%p %p %ld %ld\n", pszFilter, Buffer, BufferLen, ulFlags);
1998 return CM_Get_Device_ID_List_ExA(pszFilter, Buffer, BufferLen,
1999 ulFlags, NULL);
2000 }
2001
2002
2003 /***********************************************************************
2004 * CM_Get_Device_ID_ListW [SETUPAPI.@]
2005 */
2006 CONFIGRET WINAPI CM_Get_Device_ID_ListW(
2007 PCWSTR pszFilter, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
2008 {
2009 TRACE("%p %p %ld %ld\n", pszFilter, Buffer, BufferLen, ulFlags);
2010 return CM_Get_Device_ID_List_ExW(pszFilter, Buffer, BufferLen,
2011 ulFlags, NULL);
2012 }
2013
2014
2015 /***********************************************************************
2016 * CM_Get_Device_ID_List_ExA [SETUPAPI.@]
2017 */
2018 CONFIGRET WINAPI CM_Get_Device_ID_List_ExA(
2019 PCSTR pszFilter, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
2020 HMACHINE hMachine)
2021 {
2022 LPWSTR BufferW = NULL;
2023 LPWSTR pszFilterW = NULL;
2024 CONFIGRET ret = CR_SUCCESS;
2025
2026 TRACE("%p %p %ld %ld %lx\n",
2027 pszFilter, Buffer, BufferLen, ulFlags, hMachine);
2028
2029 BufferW = MyMalloc(BufferLen * sizeof(WCHAR));
2030 if (BufferW == NULL)
2031 return CR_OUT_OF_MEMORY;
2032
2033 if (pszFilter == NULL)
2034 {
2035 ret = CM_Get_Device_ID_List_ExW(NULL,
2036 BufferW,
2037 BufferLen,
2038 ulFlags,
2039 hMachine);
2040 }
2041 else
2042 {
2043 if (pSetupCaptureAndConvertAnsiArg(pszFilter, &pszFilterW))
2044 {
2045 ret = CR_INVALID_DEVICE_ID;
2046 goto Done;
2047 }
2048
2049 ret = CM_Get_Device_ID_List_ExW(pszFilterW,
2050 BufferW,
2051 BufferLen,
2052 ulFlags,
2053 hMachine);
2054
2055 MyFree(pszFilterW);
2056 }
2057
2058 if (WideCharToMultiByte(CP_ACP,
2059 0,
2060 BufferW,
2061 lstrlenW(BufferW) + 1,
2062 Buffer,
2063 BufferLen,
2064 NULL,
2065 NULL) == 0)
2066 ret = CR_FAILURE;
2067
2068 Done:
2069 MyFree(BufferW);
2070
2071 return ret;
2072 }
2073
2074
2075 /***********************************************************************
2076 * CM_Get_Device_ID_List_ExW [SETUPAPI.@]
2077 */
2078 CONFIGRET WINAPI CM_Get_Device_ID_List_ExW(
2079 PCWSTR pszFilter, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
2080 HMACHINE hMachine)
2081 {
2082 RPC_BINDING_HANDLE BindingHandle = NULL;
2083 CONFIGRET ret;
2084
2085 TRACE("%p %p %ld %ld %lx\n",
2086 pszFilter, Buffer, BufferLen, ulFlags, hMachine);
2087
2088 if (Buffer == NULL || BufferLen == 0)
2089 return CR_INVALID_POINTER;
2090
2091 if (ulFlags & ~CM_GETIDLIST_FILTER_BITS)
2092 return CR_INVALID_FLAG;
2093
2094 if (hMachine != NULL)
2095 {
2096 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2097 if (BindingHandle == NULL)
2098 return CR_FAILURE;
2099 }
2100 else
2101 {
2102 if (!PnpGetLocalHandles(&BindingHandle, NULL))
2103 return CR_FAILURE;
2104 }
2105
2106 *Buffer = 0;
2107
2108 RpcTryExcept
2109 {
2110 ret = PNP_GetDeviceList(BindingHandle,
2111 (LPWSTR)pszFilter,
2112 Buffer,
2113 &BufferLen,
2114 ulFlags);
2115 }
2116 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2117 {
2118 ret = RpcStatusToCmStatus(RpcExceptionCode());
2119 }
2120 RpcEndExcept;
2121
2122 return ret;
2123 }
2124
2125
2126 /***********************************************************************
2127 * CM_Get_Device_ID_List_SizeA [SETUPAPI.@]
2128 */
2129 CONFIGRET WINAPI CM_Get_Device_ID_List_SizeA(
2130 PULONG pulLen, PCSTR pszFilter, ULONG ulFlags)
2131 {
2132 TRACE("%p %s %ld\n", pulLen, pszFilter, ulFlags);
2133 return CM_Get_Device_ID_List_Size_ExA(pulLen, pszFilter, ulFlags, NULL);
2134 }
2135
2136
2137 /***********************************************************************
2138 * CM_Get_Device_ID_List_SizeW [SETUPAPI.@]
2139 */
2140 CONFIGRET WINAPI CM_Get_Device_ID_List_SizeW(
2141 PULONG pulLen, PCWSTR pszFilter, ULONG ulFlags)
2142 {
2143 TRACE("%p %s %ld\n", pulLen, debugstr_w(pszFilter), ulFlags);
2144 return CM_Get_Device_ID_List_Size_ExW(pulLen, pszFilter, ulFlags, NULL);
2145 }
2146
2147
2148 /***********************************************************************
2149 * CM_Get_Device_ID_List_Size_ExA [SETUPAPI.@]
2150 */
2151 CONFIGRET WINAPI CM_Get_Device_ID_List_Size_ExA(
2152 PULONG pulLen, PCSTR pszFilter, ULONG ulFlags, HMACHINE hMachine)
2153 {
2154 LPWSTR pszFilterW = NULL;
2155 CONFIGRET ret = CR_SUCCESS;
2156
2157 FIXME("%p %s %lx %lx\n", pulLen, pszFilter, ulFlags, hMachine);
2158
2159 if (pszFilter == NULL)
2160 {
2161 ret = CM_Get_Device_ID_List_Size_ExW(pulLen,
2162 NULL,
2163 ulFlags,
2164 hMachine);
2165 }
2166 else
2167 {
2168 if (pSetupCaptureAndConvertAnsiArg(pszFilter, &pszFilterW))
2169 return CR_INVALID_DEVICE_ID;
2170
2171 ret = CM_Get_Device_ID_List_Size_ExW(pulLen,
2172 pszFilterW,
2173 ulFlags,
2174 hMachine);
2175
2176 MyFree(pszFilterW);
2177 }
2178
2179 return ret;
2180 }
2181
2182
2183 /***********************************************************************
2184 * CM_Get_Device_ID_List_Size_ExW [SETUPAPI.@]
2185 */
2186 CONFIGRET WINAPI CM_Get_Device_ID_List_Size_ExW(
2187 PULONG pulLen, PCWSTR pszFilter, ULONG ulFlags, HMACHINE hMachine)
2188 {
2189 RPC_BINDING_HANDLE BindingHandle = NULL;
2190 CONFIGRET ret;
2191
2192 FIXME("%p %s %ld %lx\n", pulLen, debugstr_w(pszFilter), ulFlags, hMachine);
2193
2194 if (pulLen == NULL)
2195 return CR_INVALID_POINTER;
2196
2197 if (ulFlags & ~CM_GETIDLIST_FILTER_BITS)
2198 return CR_INVALID_FLAG;
2199
2200 if (hMachine != NULL)
2201 {
2202 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2203 if (BindingHandle == NULL)
2204 return CR_FAILURE;
2205 }
2206 else
2207 {
2208 if (!PnpGetLocalHandles(&BindingHandle, NULL))
2209 return CR_FAILURE;
2210 }
2211
2212 *pulLen = 0;
2213
2214 RpcTryExcept
2215 {
2216 ret = PNP_GetDeviceListSize(BindingHandle,
2217 (LPWSTR)pszFilter,
2218 pulLen,
2219 ulFlags);
2220 }
2221 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2222 {
2223 ret = RpcStatusToCmStatus(RpcExceptionCode());
2224 }
2225 RpcEndExcept;
2226
2227 return ret;
2228 }
2229
2230
2231 /***********************************************************************
2232 * CM_Get_Device_ID_Size [SETUPAPI.@]
2233 */
2234 CONFIGRET WINAPI CM_Get_Device_ID_Size(
2235 PULONG pulLen, DEVINST dnDevInst, ULONG ulFlags)
2236 {
2237 TRACE("%p %lx %lx\n", pulLen, dnDevInst, ulFlags);
2238 return CM_Get_Device_ID_Size_Ex(pulLen, dnDevInst, ulFlags, NULL);
2239 }
2240
2241
2242 /***********************************************************************
2243 * CM_Get_Device_ID_Size_Ex [SETUPAPI.@]
2244 */
2245 CONFIGRET WINAPI CM_Get_Device_ID_Size_Ex(
2246 PULONG pulLen, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
2247 {
2248 HSTRING_TABLE StringTable = NULL;
2249 LPWSTR DeviceId;
2250
2251 TRACE("%p %lx %lx %lx\n", pulLen, dnDevInst, ulFlags, hMachine);
2252
2253 if (pulLen == NULL)
2254 return CR_INVALID_POINTER;
2255
2256 if (dnDevInst == 0)
2257 return CR_INVALID_DEVINST;
2258
2259 if (ulFlags != 0)
2260 return CR_INVALID_FLAG;
2261
2262 if (hMachine != NULL)
2263 {
2264 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2265 if (StringTable == NULL)
2266 return CR_FAILURE;
2267 }
2268 else
2269 {
2270 if (!PnpGetLocalHandles(NULL, &StringTable))
2271 return CR_FAILURE;
2272 }
2273
2274 DeviceId = pSetupStringTableStringFromId(StringTable, dnDevInst);
2275 if (DeviceId == NULL)
2276 {
2277 *pulLen = 0;
2278 return CR_SUCCESS;
2279 }
2280
2281 *pulLen = lstrlenW(DeviceId);
2282
2283 return CR_SUCCESS;
2284 }
2285
2286
2287 /***********************************************************************
2288 * CM_Get_Device_Interface_AliasA [SETUPAPI.@]
2289 */
2290 CONFIGRET WINAPI CM_Get_Device_Interface_AliasA(
2291 LPCSTR pszDeviceInterface, LPGUID AliasInterfaceGuid,
2292 LPSTR pszAliasDeviceInterface, PULONG pulLength, ULONG ulFlags)
2293 {
2294 TRACE("%p %p %p %p %lu\n", pszDeviceInterface, AliasInterfaceGuid,
2295 pszAliasDeviceInterface, pulLength, ulFlags);
2296
2297 return CM_Get_Device_Interface_Alias_ExA(pszDeviceInterface,
2298 AliasInterfaceGuid, pszAliasDeviceInterface, pulLength,
2299 ulFlags, NULL);
2300 }
2301
2302
2303 /***********************************************************************
2304 * CM_Get_Device_Interface_AliasW [SETUPAPI.@]
2305 */
2306 CONFIGRET WINAPI CM_Get_Device_Interface_AliasW(
2307 LPCWSTR pszDeviceInterface, LPGUID AliasInterfaceGuid,
2308 LPWSTR pszAliasDeviceInterface, PULONG pulLength, ULONG ulFlags)
2309 {
2310 TRACE("%p %p %p %p %lu\n", pszDeviceInterface, AliasInterfaceGuid,
2311 pszAliasDeviceInterface, pulLength, ulFlags);
2312
2313 return CM_Get_Device_Interface_Alias_ExW(pszDeviceInterface,
2314 AliasInterfaceGuid, pszAliasDeviceInterface, pulLength,
2315 ulFlags, NULL);
2316 }
2317
2318
2319 /***********************************************************************
2320 * CM_Get_Device_Interface_Alias_ExA [SETUPAPI.@]
2321 */
2322 CONFIGRET WINAPI CM_Get_Device_Interface_Alias_ExA(
2323 LPCSTR pszDeviceInterface, LPGUID AliasInterfaceGuid, LPSTR pszAliasDeviceInterface,
2324 PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2325 {
2326 FIXME("%p %p %p %p %lu %lx\n", pszDeviceInterface, AliasInterfaceGuid,
2327 pszAliasDeviceInterface, pulLength, ulFlags, hMachine);
2328
2329 return CR_CALL_NOT_IMPLEMENTED;
2330 }
2331
2332
2333 /***********************************************************************
2334 * CM_Get_Device_Interface_Alias_ExW [SETUPAPI.@]
2335 */
2336 CONFIGRET WINAPI CM_Get_Device_Interface_Alias_ExW(
2337 LPCWSTR pszDeviceInterface, LPGUID AliasInterfaceGuid, LPWSTR pszAliasDeviceInterface,
2338 PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2339 {
2340 RPC_BINDING_HANDLE BindingHandle = NULL;
2341 ULONG ulTransferLength;
2342 CONFIGRET ret = CR_SUCCESS;
2343
2344 TRACE("%p %p %p %p %lu %lx\n", pszDeviceInterface, AliasInterfaceGuid,
2345 pszAliasDeviceInterface, pulLength, ulFlags, hMachine);
2346
2347 if (pszDeviceInterface == NULL ||
2348 AliasInterfaceGuid == NULL ||
2349 pszAliasDeviceInterface == NULL ||
2350 pulLength == NULL)
2351 return CR_INVALID_POINTER;
2352
2353 if (ulFlags != 0)
2354 return CR_INVALID_FLAG;
2355
2356 if (hMachine != NULL)
2357 {
2358 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2359 if (BindingHandle == NULL)
2360 return CR_FAILURE;
2361 }
2362 else
2363 {
2364 if (!PnpGetLocalHandles(&BindingHandle, NULL))
2365 return CR_FAILURE;
2366 }
2367
2368 ulTransferLength = *pulLength;
2369
2370 RpcTryExcept
2371 {
2372 ret = PNP_GetInterfaceDeviceAlias(BindingHandle,
2373 (LPWSTR)pszDeviceInterface,
2374 AliasInterfaceGuid,
2375 pszAliasDeviceInterface,
2376 pulLength,
2377 &ulTransferLength,
2378 0);
2379 }
2380 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2381 {
2382 ret = RpcStatusToCmStatus(RpcExceptionCode());
2383 }
2384 RpcEndExcept;
2385
2386 return ret;
2387 }
2388
2389
2390 /***********************************************************************
2391 * CM_Get_First_Log_Conf [SETUPAPI.@]
2392 */
2393 CONFIGRET WINAPI CM_Get_First_Log_Conf(
2394 PLOG_CONF plcLogConf, DEVINST dnDevInst, ULONG ulFlags)
2395 {
2396 TRACE("%p %lx %lx\n", plcLogConf, dnDevInst, ulFlags);
2397 return CM_Get_First_Log_Conf_Ex(plcLogConf, dnDevInst, ulFlags, NULL);
2398 }
2399
2400
2401 /***********************************************************************
2402 * CM_Get_First_Log_Conf_Ex [SETUPAPI.@]
2403 */
2404 CONFIGRET WINAPI CM_Get_First_Log_Conf_Ex(
2405 PLOG_CONF plcLogConf, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
2406 {
2407 RPC_BINDING_HANDLE BindingHandle = NULL;
2408 HSTRING_TABLE StringTable = NULL;
2409 LPWSTR lpDevInst = NULL;
2410 CONFIGRET ret = CR_SUCCESS;
2411 ULONG ulTag;
2412 PLOG_CONF_INFO pLogConfInfo;
2413
2414 FIXME("%p %lx %lx %lx\n", plcLogConf, dnDevInst, ulFlags, hMachine);
2415
2416 if (dnDevInst == 0)
2417 return CR_INVALID_DEVINST;
2418
2419 if (ulFlags & ~LOG_CONF_BITS)
2420 return CR_INVALID_FLAG;
2421
2422 if (plcLogConf)
2423 *plcLogConf = 0;
2424
2425 if (hMachine != NULL)
2426 {
2427 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2428 if (BindingHandle == NULL)
2429 return CR_FAILURE;
2430
2431 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2432 if (StringTable == 0)
2433 return CR_FAILURE;
2434 }
2435 else
2436 {
2437 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2438 return CR_FAILURE;
2439 }
2440
2441 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2442 if (lpDevInst == NULL)
2443 return CR_INVALID_DEVNODE;
2444
2445 RpcTryExcept
2446 {
2447 ret = PNP_GetFirstLogConf(BindingHandle,
2448 lpDevInst,
2449 ulFlags,
2450 &ulTag,
2451 ulFlags);
2452 }
2453 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2454 {
2455 ret = RpcStatusToCmStatus(RpcExceptionCode());
2456 }
2457 RpcEndExcept;
2458
2459 if (ret != CR_SUCCESS)
2460 return ret;
2461
2462 if (plcLogConf)
2463 {
2464 pLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
2465 if (pLogConfInfo == NULL)
2466 return CR_OUT_OF_MEMORY;
2467
2468 pLogConfInfo->ulMagic = LOG_CONF_MAGIC;
2469 pLogConfInfo->dnDevInst = dnDevInst;
2470 pLogConfInfo->ulFlags = ulFlags;
2471 pLogConfInfo->ulTag = ulTag;
2472
2473 *plcLogConf = (LOG_CONF)pLogConfInfo;
2474 }
2475
2476 return CR_SUCCESS;
2477 }
2478
2479
2480 /***********************************************************************
2481 * CM_Get_Global_State [SETUPAPI.@]
2482 */
2483 CONFIGRET WINAPI CM_Get_Global_State(
2484 PULONG pulState, ULONG ulFlags)
2485 {
2486 TRACE("%p %lx\n", pulState, ulFlags);
2487 return CM_Get_Global_State_Ex(pulState, ulFlags, NULL);
2488 }
2489
2490
2491 /***********************************************************************
2492 * CM_Get_Global_State_Ex [SETUPAPI.@]
2493 */
2494 CONFIGRET WINAPI CM_Get_Global_State_Ex(
2495 PULONG pulState, ULONG ulFlags, HMACHINE hMachine)
2496 {
2497 RPC_BINDING_HANDLE BindingHandle = NULL;
2498 CONFIGRET ret;
2499
2500 TRACE("%p %lx %lx\n", pulState, ulFlags, hMachine);
2501
2502 if (pulState == NULL)
2503 return CR_INVALID_POINTER;
2504
2505 if (ulFlags != 0)
2506 return CR_INVALID_FLAG;
2507
2508 if (hMachine != NULL)
2509 {
2510 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2511 if (BindingHandle == NULL)
2512 return CR_FAILURE;
2513 }
2514 else
2515 {
2516 if (!PnpGetLocalHandles(&BindingHandle, NULL))
2517 return CR_FAILURE;
2518 }
2519
2520 RpcTryExcept
2521 {
2522 ret = PNP_GetGlobalState(BindingHandle, pulState, ulFlags);
2523 }
2524 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2525 {
2526 ret = RpcStatusToCmStatus(RpcExceptionCode());
2527 }
2528 RpcEndExcept;
2529
2530 return ret;
2531 }
2532
2533
2534 /***********************************************************************
2535 * CM_Get_HW_Prof_FlagsA [SETUPAPI.@]
2536 */
2537 CONFIGRET WINAPI CM_Get_HW_Prof_FlagsA(
2538 DEVINSTID_A szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
2539 ULONG ulFlags)
2540 {
2541 TRACE("%s %lu %p %lx\n", szDevInstName,
2542 ulHardwareProfile, pulValue, ulFlags);
2543
2544 return CM_Get_HW_Prof_Flags_ExA(szDevInstName, ulHardwareProfile,
2545 pulValue, ulFlags, NULL);
2546 }
2547
2548
2549 /***********************************************************************
2550 * CM_Get_HW_Prof_FlagsW [SETUPAPI.@]
2551 */
2552 CONFIGRET WINAPI CM_Get_HW_Prof_FlagsW(
2553 DEVINSTID_W szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
2554 ULONG ulFlags)
2555 {
2556 TRACE("%s %lu %p %lx\n", debugstr_w(szDevInstName),
2557 ulHardwareProfile, pulValue, ulFlags);
2558
2559 return CM_Get_HW_Prof_Flags_ExW(szDevInstName, ulHardwareProfile,
2560 pulValue, ulFlags, NULL);
2561 }
2562
2563
2564 /***********************************************************************
2565 * CM_Get_HW_Prof_Flags_ExA [SETUPAPI.@]
2566 */
2567 CONFIGRET WINAPI CM_Get_HW_Prof_Flags_ExA(
2568 DEVINSTID_A szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
2569 ULONG ulFlags, HMACHINE hMachine)
2570 {
2571 DEVINSTID_W pszDevIdW = NULL;
2572 CONFIGRET ret = CR_SUCCESS;
2573
2574 TRACE("%s %lu %p %lx %lx\n", szDevInstName,
2575 ulHardwareProfile, pulValue, ulFlags, hMachine);
2576
2577 if (szDevInstName != NULL)
2578 {
2579 if (pSetupCaptureAndConvertAnsiArg(szDevInstName, &pszDevIdW))
2580 return CR_INVALID_DEVICE_ID;
2581 }
2582
2583 ret = CM_Get_HW_Prof_Flags_ExW(pszDevIdW, ulHardwareProfile,
2584 pulValue, ulFlags, hMachine);
2585
2586 if (pszDevIdW != NULL)
2587 MyFree(pszDevIdW);
2588
2589 return ret;
2590 }
2591
2592
2593 /***********************************************************************
2594 * CM_Get_HW_Prof_Flags_ExW [SETUPAPI.@]
2595 */
2596 CONFIGRET WINAPI CM_Get_HW_Prof_Flags_ExW(
2597 DEVINSTID_W szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
2598 ULONG ulFlags, HMACHINE hMachine)
2599 {
2600 RPC_BINDING_HANDLE BindingHandle = NULL;
2601 CONFIGRET ret;
2602
2603 FIXME("%s %lu %p %lx %lx\n", debugstr_w(szDevInstName),
2604 ulHardwareProfile, pulValue, ulFlags, hMachine);
2605
2606 if ((szDevInstName == NULL) || (pulValue == NULL))
2607 return CR_INVALID_POINTER;
2608
2609 if (ulFlags != 0)
2610 return CR_INVALID_FLAG;
2611
2612 /* FIXME: Check whether szDevInstName is valid */
2613
2614 if (hMachine != NULL)
2615 {
2616 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2617 if (BindingHandle == NULL)
2618 return CR_FAILURE;
2619 }
2620 else
2621 {
2622 if (!PnpGetLocalHandles(&BindingHandle, NULL))
2623 return CR_FAILURE;
2624 }
2625
2626 RpcTryExcept
2627 {
2628 ret = PNP_HwProfFlags(BindingHandle, PNP_GET_HWPROFFLAGS, szDevInstName,
2629 ulHardwareProfile, pulValue, NULL, NULL, 0, 0);
2630 }
2631 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2632 {
2633 ret = RpcStatusToCmStatus(RpcExceptionCode());
2634 }
2635 RpcEndExcept;
2636
2637 return ret;
2638 }
2639
2640
2641 /***********************************************************************
2642 * CM_Get_Hardware_Profile_InfoA [SETUPAPI.@]
2643 */
2644 CONFIGRET WINAPI CM_Get_Hardware_Profile_InfoA(
2645 ULONG ulIndex, PHWPROFILEINFO_A pHWProfileInfo, ULONG ulFlags)
2646 {
2647 TRACE("%lu %p %lx\n", ulIndex, pHWProfileInfo, ulFlags);
2648
2649 return CM_Get_Hardware_Profile_Info_ExA(ulIndex, pHWProfileInfo,
2650 ulFlags, NULL);
2651 }
2652
2653
2654 /***********************************************************************
2655 * CM_Get_Hardware_Profile_InfoW [SETUPAPI.@]
2656 */
2657 CONFIGRET WINAPI CM_Get_Hardware_Profile_InfoW(
2658 ULONG ulIndex, PHWPROFILEINFO_W pHWProfileInfo, ULONG ulFlags)
2659 {
2660 TRACE("%lu %p %lx\n", ulIndex, pHWProfileInfo, ulFlags);
2661
2662 return CM_Get_Hardware_Profile_Info_ExW(ulIndex, pHWProfileInfo,
2663 ulFlags, NULL);
2664 }
2665
2666
2667 /***********************************************************************
2668 * CM_Get_Hardware_Profile_Info_ExA [SETUPAPI.@]
2669 */
2670 CONFIGRET WINAPI CM_Get_Hardware_Profile_Info_ExA(
2671 ULONG ulIndex, PHWPROFILEINFO_A pHWProfileInfo, ULONG ulFlags,
2672 HMACHINE hMachine)
2673 {
2674 HWPROFILEINFO_W LocalProfileInfo;
2675 CONFIGRET ret;
2676
2677 TRACE("%lu %p %lx %lx\n", ulIndex, pHWProfileInfo, ulFlags, hMachine);
2678
2679 if (pHWProfileInfo == NULL)
2680 return CR_INVALID_POINTER;
2681
2682 ret = CM_Get_Hardware_Profile_Info_ExW(ulIndex, &LocalProfileInfo,
2683 ulFlags, hMachine);
2684 if (ret == CR_SUCCESS)
2685 {
2686 pHWProfileInfo->HWPI_ulHWProfile = LocalProfileInfo.HWPI_ulHWProfile;
2687 pHWProfileInfo->HWPI_dwFlags = LocalProfileInfo.HWPI_dwFlags;
2688
2689 if (WideCharToMultiByte(CP_ACP,
2690 0,
2691 LocalProfileInfo.HWPI_szFriendlyName,
2692 lstrlenW(LocalProfileInfo.HWPI_szFriendlyName) + 1,
2693 pHWProfileInfo->HWPI_szFriendlyName,
2694 MAX_PROFILE_LEN,
2695 NULL,
2696 NULL) == 0)
2697 ret = CR_FAILURE;
2698 }
2699
2700 return ret;
2701 }
2702
2703
2704 /***********************************************************************
2705 * CM_Get_Hardware_Profile_Info_ExW [SETUPAPI.@]
2706 */
2707 CONFIGRET WINAPI CM_Get_Hardware_Profile_Info_ExW(
2708 ULONG ulIndex, PHWPROFILEINFO_W pHWProfileInfo, ULONG ulFlags,
2709 HMACHINE hMachine)
2710 {
2711 RPC_BINDING_HANDLE BindingHandle = NULL;
2712 CONFIGRET ret;
2713
2714 TRACE("%lu %p %lx %lx\n", ulIndex, pHWProfileInfo, ulFlags, hMachine);
2715
2716 if (pHWProfileInfo == NULL)
2717 return CR_INVALID_POINTER;
2718
2719 if (ulFlags != 0)
2720 return CR_INVALID_FLAG;
2721
2722 if (hMachine != NULL)
2723 {
2724 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2725 if (BindingHandle == NULL)
2726 return CR_FAILURE;
2727 }
2728 else
2729 {
2730 if (!PnpGetLocalHandles(&BindingHandle, NULL))
2731 return CR_FAILURE;
2732 }
2733
2734 RpcTryExcept
2735 {
2736 ret = PNP_GetHwProfInfo(BindingHandle, ulIndex, pHWProfileInfo,
2737 sizeof(HWPROFILEINFO_W), 0);
2738 }
2739 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2740 {
2741 ret = RpcStatusToCmStatus(RpcExceptionCode());
2742 }
2743 RpcEndExcept;
2744
2745 return ret;
2746 }
2747
2748
2749 /***********************************************************************
2750 * CM_Get_Log_Conf_Priority [SETUPAPI.@]
2751 */
2752 CONFIGRET WINAPI CM_Get_Log_Conf_Priority(
2753 LOG_CONF lcLogConf, PPRIORITY pPriority, ULONG ulFlags)
2754 {
2755 TRACE("%p %p %lx\n", lcLogConf, pPriority, ulFlags);
2756 return CM_Get_Log_Conf_Priority_Ex(lcLogConf, pPriority, ulFlags, NULL);
2757 }
2758
2759
2760 /***********************************************************************
2761 * CM_Get_Log_Conf_Priority_Ex [SETUPAPI.@]
2762 */
2763 CONFIGRET WINAPI CM_Get_Log_Conf_Priority_Ex(
2764 LOG_CONF lcLogConf, PPRIORITY pPriority, ULONG ulFlags,
2765 HMACHINE hMachine)
2766 {
2767 RPC_BINDING_HANDLE BindingHandle = NULL;
2768 HSTRING_TABLE StringTable = NULL;
2769 PLOG_CONF_INFO pLogConfInfo;
2770 LPWSTR lpDevInst;
2771 CONFIGRET ret;
2772
2773 FIXME("%p %p %lx %lx\n", lcLogConf, pPriority, ulFlags, hMachine);
2774
2775 pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
2776 if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
2777 return CR_INVALID_LOG_CONF;
2778
2779 if (pPriority == NULL)
2780 return CR_INVALID_POINTER;
2781
2782 if (ulFlags != 0)
2783 return CR_INVALID_FLAG;
2784
2785 if (hMachine != NULL)
2786 {
2787 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2788 if (BindingHandle == NULL)
2789 return CR_FAILURE;
2790
2791 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2792 if (StringTable == 0)
2793 return CR_FAILURE;
2794 }
2795 else
2796 {
2797 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2798 return CR_FAILURE;
2799 }
2800
2801 lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
2802 if (lpDevInst == NULL)
2803 return CR_INVALID_DEVNODE;
2804
2805 RpcTryExcept
2806 {
2807 ret = PNP_GetLogConfPriority(BindingHandle,
2808 lpDevInst,
2809 pLogConfInfo->ulFlags,
2810 pLogConfInfo->ulTag,
2811 pPriority,
2812 0);
2813 }
2814 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2815 {
2816 ret = RpcStatusToCmStatus(RpcExceptionCode());
2817 }
2818 RpcEndExcept;
2819
2820 return ret;
2821 }
2822
2823
2824 /***********************************************************************
2825 * CM_Get_Next_Log_Conf [SETUPAPI.@]
2826 */
2827 CONFIGRET WINAPI CM_Get_Next_Log_Conf(
2828 PLOG_CONF plcLogConf, LOG_CONF lcLogConf, ULONG ulFlags)
2829 {
2830 TRACE("%p %p %lx\n", plcLogConf, lcLogConf, ulFlags);
2831 return CM_Get_Next_Log_Conf_Ex(plcLogConf, lcLogConf, ulFlags, NULL);
2832 }
2833
2834
2835 /***********************************************************************
2836 * CM_Get_Next_Log_Conf_Ex [SETUPAPI.@]
2837 */
2838 CONFIGRET WINAPI CM_Get_Next_Log_Conf_Ex(
2839 PLOG_CONF plcLogConf, LOG_CONF lcLogConf, ULONG ulFlags,
2840 HMACHINE hMachine)
2841 {
2842 RPC_BINDING_HANDLE BindingHandle = NULL;
2843 HSTRING_TABLE StringTable = NULL;
2844 PLOG_CONF_INFO pLogConfInfo;
2845 PLOG_CONF_INFO pNewLogConfInfo;
2846 ULONG ulNewTag;
2847 LPWSTR lpDevInst;
2848 CONFIGRET ret;
2849
2850 FIXME("%p %p %lx %lx\n", plcLogConf, lcLogConf, ulFlags, hMachine);
2851
2852 if (plcLogConf)
2853 *plcLogConf = 0;
2854
2855 pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
2856 if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
2857 return CR_INVALID_LOG_CONF;
2858
2859 if (ulFlags != 0)
2860 return CR_INVALID_FLAG;
2861
2862 if (hMachine != NULL)
2863 {
2864 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2865 if (BindingHandle == NULL)
2866 return CR_FAILURE;
2867
2868 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2869 if (StringTable == 0)
2870 return CR_FAILURE;
2871 }
2872 else
2873 {
2874 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2875 return CR_FAILURE;
2876 }
2877
2878 lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
2879 if (lpDevInst == NULL)
2880 return CR_INVALID_DEVNODE;
2881
2882 RpcTryExcept
2883 {
2884 ret = PNP_GetNextLogConf(BindingHandle,
2885 lpDevInst,
2886 pLogConfInfo->ulFlags,
2887 pLogConfInfo->ulTag,
2888 &ulNewTag,
2889 0);
2890 }
2891 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2892 {
2893 ret = RpcStatusToCmStatus(RpcExceptionCode());
2894 }
2895 RpcEndExcept;
2896
2897 if (ret != CR_SUCCESS)
2898 return ret;
2899
2900 if (plcLogConf)
2901 {
2902 pNewLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
2903 if (pNewLogConfInfo == NULL)
2904 return CR_OUT_OF_MEMORY;
2905
2906 pNewLogConfInfo->ulMagic = LOG_CONF_MAGIC;
2907 pNewLogConfInfo->dnDevInst = pLogConfInfo->dnDevInst;
2908 pNewLogConfInfo->ulFlags = pLogConfInfo->ulFlags;
2909 pNewLogConfInfo->ulTag = ulNewTag;
2910
2911 *plcLogConf = (LOG_CONF)pNewLogConfInfo;
2912 }
2913
2914 return CR_SUCCESS;
2915 }
2916
2917
2918 /***********************************************************************
2919 * CM_Get_Next_Re_Des [SETUPAPI.@]
2920 */
2921 CONFIGRET WINAPI CM_Get_Next_Res_Des(
2922 PRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ForResource,
2923 PRESOURCEID pResourceID, ULONG ulFlags)
2924 {
2925 TRACE("%p %p %lu %p %lx\n", prdResDes, rdResDes, ForResource,
2926 pResourceID, ulFlags);
2927 return CM_Get_Next_Res_Des_Ex(prdResDes, rdResDes, ForResource,
2928 pResourceID, ulFlags, NULL);
2929 }
2930
2931
2932 /***********************************************************************
2933 * CM_Get_Next_Re_Des_Ex [SETUPAPI.@]
2934 */
2935 CONFIGRET WINAPI CM_Get_Next_Res_Des_Ex(
2936 PRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ForResource,
2937 PRESOURCEID pResourceID, ULONG ulFlags, HMACHINE hMachine)
2938 {
2939 FIXME("%p %p %lu %p %lx %lx\n", prdResDes, rdResDes, ForResource,
2940 pResourceID, ulFlags, hMachine);
2941
2942 return CR_CALL_NOT_IMPLEMENTED;
2943 }
2944
2945
2946 /***********************************************************************
2947 * CM_Get_Parent [SETUPAPI.@]
2948 */
2949 CONFIGRET WINAPI CM_Get_Parent(
2950 PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags)
2951 {
2952 TRACE("%p %p %lx\n", pdnDevInst, dnDevInst, ulFlags);
2953 return CM_Get_Parent_Ex(pdnDevInst, dnDevInst, ulFlags, NULL);
2954 }
2955
2956
2957 /***********************************************************************
2958 * CM_Get_Parent_Ex [SETUPAPI.@]
2959 */
2960 CONFIGRET WINAPI CM_Get_Parent_Ex(
2961 PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
2962 {
2963 WCHAR szRelatedDevInst[MAX_DEVICE_ID_LEN];
2964 RPC_BINDING_HANDLE BindingHandle = NULL;
2965 HSTRING_TABLE StringTable = NULL;
2966 LPWSTR lpDevInst;
2967 DWORD dwIndex, dwLength = MAX_DEVICE_ID_LEN;
2968 CONFIGRET ret;
2969
2970 TRACE("%p %lx %lx %lx\n", pdnDevInst, dnDevInst, ulFlags, hMachine);
2971
2972 if (pdnDevInst == NULL)
2973 return CR_INVALID_POINTER;
2974
2975 if (dnDevInst == 0)
2976 return CR_INVALID_DEVINST;
2977
2978 if (ulFlags != 0)
2979 return CR_INVALID_FLAG;
2980
2981 *pdnDevInst = -1;
2982
2983 if (hMachine != NULL)
2984 {
2985 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2986 if (BindingHandle == NULL)
2987 return CR_FAILURE;
2988
2989 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2990 if (StringTable == 0)
2991 return CR_FAILURE;
2992 }
2993 else
2994 {
2995 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2996 return CR_FAILURE;
2997 }
2998
2999 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
3000 if (lpDevInst == NULL)
3001 return CR_INVALID_DEVNODE;
3002
3003 RpcTryExcept
3004 {
3005 ret = PNP_GetRelatedDeviceInstance(BindingHandle,
3006 PNP_GET_PARENT_DEVICE_INSTANCE,
3007 lpDevInst,
3008 szRelatedDevInst,
3009 &dwLength,
3010 0);
3011 }
3012 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3013 {
3014 ret = RpcStatusToCmStatus(RpcExceptionCode());
3015 }
3016 RpcEndExcept;
3017
3018 if (ret != CR_SUCCESS)
3019 return ret;
3020
3021 TRACE("szRelatedDevInst: %s\n", debugstr_w(szRelatedDevInst));
3022
3023 dwIndex = pSetupStringTableAddString(StringTable, szRelatedDevInst, 1);
3024 if (dwIndex == -1)
3025 return CR_FAILURE;
3026
3027 *pdnDevInst = dwIndex;
3028
3029 return CR_SUCCESS;
3030 }
3031
3032
3033 /***********************************************************************
3034 * CM_Get_Res_Des_Data [SETUPAPI.@]
3035 */
3036 CONFIGRET WINAPI CM_Get_Res_Des_Data(
3037 RES_DES rdResDes, PVOID Buffer, ULONG BufferLen, ULONG ulFlags)
3038 {
3039 TRACE("%p %p %l %lx\n", rdResDes, Buffer, BufferLen, ulFlags);
3040 return CM_Get_Res_Des_Data_Ex(rdResDes, Buffer, BufferLen, ulFlags, NULL);
3041 }
3042
3043
3044 /***********************************************************************
3045 * CM_Get_Res_Des_Data_Ex [SETUPAPI.@]
3046 */
3047 CONFIGRET WINAPI CM_Get_Res_Des_Data_Ex(
3048 RES_DES rdResDes, PVOID Buffer, ULONG BufferLen, ULONG ulFlags,
3049 HMACHINE hMachine)
3050 {
3051 FIXME("%p %p %l %lx %lx\n", rdResDes, Buffer, BufferLen, ulFlags, hMachine);
3052 return CR_CALL_NOT_IMPLEMENTED;
3053 }
3054
3055
3056 /***********************************************************************
3057 * CM_Get_Res_Des_Size [SETUPAPI.@]
3058 */
3059 CONFIGRET WINAPI CM_Get_Res_Des_Data_Size(
3060 PULONG pulSize, RES_DES rdResDes, ULONG ulFlags)
3061 {
3062 TRACE("%p %p %lx\n", pulSize, rdResDes, ulFlags);
3063 return CM_Get_Res_Des_Data_Size_Ex(pulSize, rdResDes, ulFlags, NULL);
3064 }
3065
3066
3067 /***********************************************************************
3068 * CM_Get_Res_Des_Size_Ex [SETUPAPI.@]
3069 */
3070 CONFIGRET WINAPI CM_Get_Res_Des_Data_Size_Ex(
3071 PULONG pulSize, RES_DES rdResDes, ULONG ulFlags, HMACHINE hMachine)
3072 {
3073 TRACE("%p %p %lx %lx\n", pulSize, rdResDes, ulFlags, hMachine);
3074 return CR_CALL_NOT_IMPLEMENTED;
3075 }
3076
3077
3078 /***********************************************************************
3079 * CM_Get_Sibling [SETUPAPI.@]
3080 */
3081 CONFIGRET WINAPI CM_Get_Sibling(
3082 PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags)
3083 {
3084 TRACE("%p %p %lx\n", pdnDevInst, dnDevInst, ulFlags);
3085 return CM_Get_Sibling_Ex(pdnDevInst, dnDevInst, ulFlags, NULL);
3086 }
3087
3088
3089 /***********************************************************************
3090 * CM_Get_Sibling_Ex [SETUPAPI.@]
3091 */
3092 CONFIGRET WINAPI CM_Get_Sibling_Ex(
3093 PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
3094 {
3095 WCHAR szRelatedDevInst[MAX_DEVICE_ID_LEN];
3096 RPC_BINDING_HANDLE BindingHandle = NULL;
3097 HSTRING_TABLE StringTable = NULL;
3098 LPWSTR lpDevInst;
3099 DWORD dwIndex, dwLength = MAX_DEVICE_ID_LEN;
3100 CONFIGRET ret;
3101
3102 TRACE("%p %lx %lx %lx\n", pdnDevInst, dnDevInst, ulFlags, hMachine);
3103
3104 if (pdnDevInst == NULL)
3105 return CR_INVALID_POINTER;
3106
3107 if (dnDevInst == 0)
3108 return CR_INVALID_DEVINST;
3109
3110 if (ulFlags != 0)
3111 return CR_INVALID_FLAG;
3112
3113 *pdnDevInst = -1;
3114
3115 if (hMachine != NULL)
3116 {
3117 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3118 if (BindingHandle == NULL)
3119 return CR_FAILURE;
3120
3121 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3122 if (StringTable == 0)
3123 return CR_FAILURE;
3124 }
3125 else
3126 {
3127 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
3128 return CR_FAILURE;
3129 }
3130
3131 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
3132 if (lpDevInst == NULL)
3133 return CR_INVALID_DEVNODE;
3134
3135 RpcTryExcept
3136 {
3137 ret = PNP_GetRelatedDeviceInstance(BindingHandle,
3138 PNP_GET_SIBLING_DEVICE_INSTANCE,
3139 lpDevInst,
3140 szRelatedDevInst,
3141 &dwLength,
3142 0);
3143 }
3144 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3145 {
3146 ret = RpcStatusToCmStatus(RpcExceptionCode());
3147 }
3148 RpcEndExcept;
3149
3150 if (ret != CR_SUCCESS)
3151 return ret;
3152
3153 TRACE("szRelatedDevInst: %s\n", debugstr_w(szRelatedDevInst));
3154
3155 dwIndex = pSetupStringTableAddString(StringTable, szRelatedDevInst, 1);
3156 if (dwIndex == -1)
3157 return CR_FAILURE;
3158
3159 *pdnDevInst = dwIndex;
3160
3161 return CR_SUCCESS;
3162 }
3163
3164
3165 /***********************************************************************
3166 * CM_Get_Version [SETUPAPI.@]
3167 */
3168 WORD WINAPI CM_Get_Version(VOID)
3169 {
3170 TRACE("\n");
3171 return CM_Get_Version_Ex(NULL);
3172 }
3173
3174
3175 /***********************************************************************
3176 * CM_Get_Version_Ex [SETUPAPI.@]
3177 */
3178 WORD WINAPI CM_Get_Version_Ex(HMACHINE hMachine)
3179 {
3180 RPC_BINDING_HANDLE BindingHandle = NULL;
3181 WORD Version = 0;
3182 CONFIGRET ret;
3183
3184 TRACE("%lx\n", hMachine);
3185
3186 if (hMachine != NULL)
3187 {
3188 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3189 if (BindingHandle == NULL)
3190 return 0;
3191 }
3192 else
3193 {
3194 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3195 return CR_FAILURE;
3196 }
3197
3198 RpcTryExcept
3199 {
3200 ret = PNP_GetVersion(BindingHandle, &Version);
3201 }
3202 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3203 {
3204 ret = RpcStatusToCmStatus(RpcExceptionCode());
3205 }
3206 RpcEndExcept;
3207
3208 if (ret != CR_SUCCESS)
3209 return 0;
3210
3211 return Version;
3212 }
3213
3214
3215 /***********************************************************************
3216 * CM_Is_Dock_Station_Present [SETUPAPI.@]
3217 */
3218 CONFIGRET WINAPI CM_Is_Dock_Station_Present(
3219 PBOOL pbPresent)
3220 {
3221 TRACE("%p\n", pbPresent);
3222 return CM_Is_Dock_Station_Present_Ex(pbPresent, NULL);
3223 }
3224
3225
3226 /***********************************************************************
3227 * CM_Is_Dock_Station_Present_Ex [SETUPAPI.@]
3228 */
3229 CONFIGRET WINAPI CM_Is_Dock_Station_Present_Ex(
3230 PBOOL pbPresent, HMACHINE hMachine)
3231 {
3232 RPC_BINDING_HANDLE BindingHandle = NULL;
3233 CONFIGRET ret;
3234
3235 TRACE("%p %lx\n", pbPresent, hMachine);
3236
3237 if (pbPresent == NULL)
3238 return CR_INVALID_POINTER;
3239
3240 *pbPresent = FALSE;
3241
3242 if (hMachine != NULL)
3243 {
3244 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3245 if (BindingHandle == NULL)
3246 return CR_FAILURE;
3247 }
3248 else
3249 {
3250 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3251 return CR_FAILURE;
3252 }
3253
3254 RpcTryExcept
3255 {
3256 ret = PNP_IsDockStationPresent(BindingHandle,
3257 pbPresent);
3258 }
3259 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3260 {
3261 ret = RpcStatusToCmStatus(RpcExceptionCode());
3262 }
3263 RpcEndExcept;
3264
3265 return ret;
3266 }
3267
3268
3269 /***********************************************************************
3270 * CM_Is_Version_Available_Ex [SETUPAPI.@]
3271 */
3272 BOOL WINAPI CM_Is_Version_Available(
3273 WORD wVersion)
3274 {
3275 TRACE("%hu\n", wVersion);
3276 return CM_Is_Version_Available_Ex(wVersion, NULL);
3277 }
3278
3279
3280 /***********************************************************************
3281 * CM_Is_Version_Available_Ex [SETUPAPI.@]
3282 */
3283 BOOL WINAPI CM_Is_Version_Available_Ex(
3284 WORD wVersion, HMACHINE hMachine)
3285 {
3286 RPC_BINDING_HANDLE BindingHandle = NULL;
3287 WORD wServerVersion;
3288 CONFIGRET ret;
3289
3290 TRACE("%hu %lx\n", wVersion, hMachine);
3291
3292 if (wVersion <= 0x400)
3293 return TRUE;
3294
3295 if (hMachine != NULL)
3296 {
3297 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3298 if (BindingHandle == NULL)
3299 return FALSE;
3300 }
3301 else
3302 {
3303 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3304 return FALSE;
3305 }
3306
3307 RpcTryExcept
3308 {
3309 ret = PNP_GetVersion(BindingHandle, &wServerVersion);
3310 }
3311 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3312 {
3313 ret = RpcStatusToCmStatus(RpcExceptionCode());
3314 }
3315 RpcEndExcept;
3316
3317 if (ret != CR_SUCCESS)
3318 return FALSE;
3319
3320 return (wServerVersion >= wVersion);
3321 }
3322
3323
3324 /***********************************************************************
3325 * CM_Locate_DevNodeA [SETUPAPI.@]
3326 */
3327 CONFIGRET WINAPI CM_Locate_DevNodeA(
3328 PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags)
3329 {
3330 TRACE("%p %s %lu\n", pdnDevInst, pDeviceID, ulFlags);
3331 return CM_Locate_DevNode_ExA(pdnDevInst, pDeviceID, ulFlags, NULL);
3332 }
3333
3334
3335 /***********************************************************************
3336 * CM_Locate_DevNodeW [SETUPAPI.@]
3337 */
3338 CONFIGRET WINAPI CM_Locate_DevNodeW(
3339 PDEVINST pdnDevInst, DEVINSTID_W pDeviceID, ULONG ulFlags)
3340 {
3341 TRACE("%p %s %lu\n", pdnDevInst, debugstr_w(pDeviceID), ulFlags);
3342 return CM_Locate_DevNode_ExW(pdnDevInst, pDeviceID, ulFlags, NULL);
3343 }
3344
3345
3346 /***********************************************************************
3347 * CM_Locate_DevNode_ExA [SETUPAPI.@]
3348 */
3349 CONFIGRET WINAPI CM_Locate_DevNode_ExA(
3350 PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags, HMACHINE hMachine)
3351 {
3352 DEVINSTID_W pDevIdW = NULL;
3353 CONFIGRET ret = CR_SUCCESS;
3354
3355 TRACE("%p %s %lu %lx\n", pdnDevInst, pDeviceID, ulFlags, hMachine);
3356
3357 if (pDeviceID != NULL)
3358 {
3359 if (pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDevIdW))
3360 return CR_INVALID_DEVICE_ID;
3361 }
3362
3363 ret = CM_Locate_DevNode_ExW(pdnDevInst, pDevIdW, ulFlags, hMachine);
3364
3365 if (pDevIdW != NULL)
3366 MyFree(pDevIdW);
3367
3368 return ret;
3369 }
3370
3371
3372 /***********************************************************************
3373 * CM_Locate_DevNode_ExW [SETUPAPI.@]
3374 */
3375 CONFIGRET WINAPI CM_Locate_DevNode_ExW(
3376 PDEVINST pdnDevInst, DEVINSTID_W pDeviceID, ULONG ulFlags, HMACHINE hMachine)
3377 {
3378 WCHAR DeviceIdBuffer[MAX_DEVICE_ID_LEN];
3379 RPC_BINDING_HANDLE BindingHandle = NULL;
3380 HSTRING_TABLE StringTable = NULL;
3381 CONFIGRET ret = CR_SUCCESS;
3382
3383 TRACE("%p %s %lu %lx\n", pdnDevInst, debugstr_w(pDeviceID), ulFlags, hMachine);
3384
3385 if (pdnDevInst == NULL)
3386