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