xref: /reactos/dll/win32/setupapi/cfgmgr.c (revision c2c66aff)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * Configuration manager functions
3*c2c66affSColin Finck  *
4*c2c66affSColin Finck  * Copyright 2000 James Hatheway
5*c2c66affSColin Finck  * Copyright 2005, 2006 Eric Kohl
6*c2c66affSColin Finck  *
7*c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
8*c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
9*c2c66affSColin Finck  * License as published by the Free Software Foundation; either
10*c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
11*c2c66affSColin Finck  *
12*c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
13*c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14*c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15*c2c66affSColin Finck  * Lesser General Public License for more details.
16*c2c66affSColin Finck  *
17*c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
18*c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
19*c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20*c2c66affSColin Finck  */
21*c2c66affSColin Finck 
22*c2c66affSColin Finck #include "setupapi_private.h"
23*c2c66affSColin Finck 
24*c2c66affSColin Finck #include <dbt.h>
25*c2c66affSColin Finck #include <pnp_c.h>
26*c2c66affSColin Finck 
27*c2c66affSColin Finck #include "rpc_private.h"
28*c2c66affSColin Finck 
29*c2c66affSColin Finck /* Registry key and value names */
30*c2c66affSColin Finck static const WCHAR Backslash[] = {'\\', 0};
31*c2c66affSColin Finck static const WCHAR Class[]  = {'C','l','a','s','s',0};
32*c2c66affSColin Finck 
33*c2c66affSColin Finck static const WCHAR ControlClass[] = {'S','y','s','t','e','m','\\',
34*c2c66affSColin Finck                                      'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
35*c2c66affSColin Finck                                      'C','o','n','t','r','o','l','\\',
36*c2c66affSColin Finck                                      'C','l','a','s','s',0};
37*c2c66affSColin Finck 
38*c2c66affSColin Finck static const WCHAR DeviceClasses[] = {'S','y','s','t','e','m','\\',
39*c2c66affSColin Finck                                       'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
40*c2c66affSColin Finck                                       'C','o','n','t','r','o','l','\\',
41*c2c66affSColin Finck                                       'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
42*c2c66affSColin Finck 
43*c2c66affSColin Finck typedef struct _MACHINE_INFO
44*c2c66affSColin Finck {
45*c2c66affSColin Finck     WCHAR szMachineName[SP_MAX_MACHINENAME_LENGTH];
46*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle;
47*c2c66affSColin Finck     HSTRING_TABLE StringTable;
48*c2c66affSColin Finck     BOOL bLocal;
49*c2c66affSColin Finck } MACHINE_INFO, *PMACHINE_INFO;
50*c2c66affSColin Finck 
51*c2c66affSColin Finck 
52*c2c66affSColin Finck typedef struct _LOG_CONF_INFO
53*c2c66affSColin Finck {
54*c2c66affSColin Finck     ULONG ulMagic;
55*c2c66affSColin Finck     DEVINST dnDevInst;
56*c2c66affSColin Finck     ULONG ulFlags;
57*c2c66affSColin Finck     ULONG ulTag;
58*c2c66affSColin Finck } LOG_CONF_INFO, *PLOG_CONF_INFO;
59*c2c66affSColin Finck 
60*c2c66affSColin Finck #define LOG_CONF_MAGIC 0x464E434C  /* "LCNF" */
61*c2c66affSColin Finck 
62*c2c66affSColin Finck 
63*c2c66affSColin Finck typedef struct _NOTIFY_DATA
64*c2c66affSColin Finck {
65*c2c66affSColin Finck     ULONG ulMagic;
66*c2c66affSColin Finck     ULONG ulNotifyData;
67*c2c66affSColin Finck } NOTIFY_DATA, *PNOTIFY_DATA;
68*c2c66affSColin Finck 
69*c2c66affSColin Finck #define NOTIFY_MAGIC 0x44556677
70*c2c66affSColin Finck 
71*c2c66affSColin Finck 
72*c2c66affSColin Finck typedef struct _INTERNAL_RANGE_ELEMENT
73*c2c66affSColin Finck {
74*c2c66affSColin Finck     struct _INTERNAL_RANGE_ELEMENT *Next;
75*c2c66affSColin Finck     ULONG ulDummy;
76*c2c66affSColin Finck } INTERNAL_RANGE_ELEMENT, *PINTERNAL_RANGE_ELEMENT;
77*c2c66affSColin Finck 
78*c2c66affSColin Finck typedef struct _INTERNAL_RANGE_LIST
79*c2c66affSColin Finck {
80*c2c66affSColin Finck     ULONG ulMagic;
81*c2c66affSColin Finck     PINTERNAL_RANGE_ELEMENT Current;
82*c2c66affSColin Finck     PINTERNAL_RANGE_ELEMENT First;
83*c2c66affSColin Finck } INTERNAL_RANGE_LIST, *PINTERNAL_RANGE_LIST;
84*c2c66affSColin Finck 
85*c2c66affSColin Finck #define RANGE_LIST_MAGIC 0x33445566
86*c2c66affSColin Finck 
87*c2c66affSColin Finck 
88*c2c66affSColin Finck static BOOL GuidToString(LPGUID Guid, LPWSTR String)
89*c2c66affSColin Finck {
90*c2c66affSColin Finck     LPWSTR lpString;
91*c2c66affSColin Finck 
92*c2c66affSColin Finck     if (UuidToStringW(Guid, &lpString) != RPC_S_OK)
93*c2c66affSColin Finck         return FALSE;
94*c2c66affSColin Finck 
95*c2c66affSColin Finck     lstrcpyW(&String[1], lpString);
96*c2c66affSColin Finck 
97*c2c66affSColin Finck     String[0] = '{';
98*c2c66affSColin Finck     String[MAX_GUID_STRING_LEN - 2] = '}';
99*c2c66affSColin Finck     String[MAX_GUID_STRING_LEN - 1] = UNICODE_NULL;
100*c2c66affSColin Finck 
101*c2c66affSColin Finck     RpcStringFreeW(&lpString);
102*c2c66affSColin Finck 
103*c2c66affSColin Finck     return TRUE;
104*c2c66affSColin Finck }
105*c2c66affSColin Finck 
106*c2c66affSColin Finck 
107*c2c66affSColin Finck static CONFIGRET
108*c2c66affSColin Finck RpcStatusToCmStatus(RPC_STATUS Status)
109*c2c66affSColin Finck {
110*c2c66affSColin Finck     return CR_FAILURE;
111*c2c66affSColin Finck }
112*c2c66affSColin Finck 
113*c2c66affSColin Finck 
114*c2c66affSColin Finck static
115*c2c66affSColin Finck ULONG
116*c2c66affSColin Finck GetRegistryPropertyType(
117*c2c66affSColin Finck     ULONG ulProperty)
118*c2c66affSColin Finck {
119*c2c66affSColin Finck     switch (ulProperty)
120*c2c66affSColin Finck     {
121*c2c66affSColin Finck         case CM_DRP_DEVICEDESC:
122*c2c66affSColin Finck         case CM_DRP_SERVICE:
123*c2c66affSColin Finck         case CM_DRP_CLASS:
124*c2c66affSColin Finck         case CM_DRP_CLASSGUID:
125*c2c66affSColin Finck         case CM_DRP_DRIVER:
126*c2c66affSColin Finck         case CM_DRP_MFG:
127*c2c66affSColin Finck         case CM_DRP_FRIENDLYNAME:
128*c2c66affSColin Finck         case CM_DRP_LOCATION_INFORMATION:
129*c2c66affSColin Finck         case CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME:
130*c2c66affSColin Finck         case CM_DRP_ENUMERATOR_NAME:
131*c2c66affSColin Finck         case CM_DRP_SECURITY_SDS:
132*c2c66affSColin Finck         case CM_DRP_UI_NUMBER_DESC_FORMAT:
133*c2c66affSColin Finck             return REG_SZ;
134*c2c66affSColin Finck 
135*c2c66affSColin Finck         case CM_DRP_HARDWAREID:
136*c2c66affSColin Finck         case CM_DRP_COMPATIBLEIDS:
137*c2c66affSColin Finck         case CM_DRP_UPPERFILTERS:
138*c2c66affSColin Finck         case CM_DRP_LOWERFILTERS:
139*c2c66affSColin Finck             return REG_MULTI_SZ;
140*c2c66affSColin Finck 
141*c2c66affSColin Finck         case CM_DRP_CONFIGFLAGS:
142*c2c66affSColin Finck         case CM_DRP_CAPABILITIES:
143*c2c66affSColin Finck         case CM_DRP_UI_NUMBER:
144*c2c66affSColin Finck         case CM_DRP_LEGACYBUSTYPE:
145*c2c66affSColin Finck         case CM_DRP_BUSNUMBER:
146*c2c66affSColin Finck         case CM_DRP_DEVTYPE:
147*c2c66affSColin Finck         case CM_DRP_EXCLUSIVE:
148*c2c66affSColin Finck         case CM_DRP_CHARACTERISTICS:
149*c2c66affSColin Finck         case CM_DRP_ADDRESS:
150*c2c66affSColin Finck         case CM_DRP_REMOVAL_POLICY:
151*c2c66affSColin Finck         case CM_DRP_REMOVAL_POLICY_HW_DEFAULT:
152*c2c66affSColin Finck         case CM_DRP_REMOVAL_POLICY_OVERRIDE:
153*c2c66affSColin Finck         case CM_DRP_INSTALL_STATE:
154*c2c66affSColin Finck             return REG_DWORD;
155*c2c66affSColin Finck 
156*c2c66affSColin Finck         case CM_DRP_BUSTYPEGUID:
157*c2c66affSColin Finck         case CM_DRP_SECURITY:
158*c2c66affSColin Finck         case CM_DRP_DEVICE_POWER_DATA:
159*c2c66affSColin Finck         default:
160*c2c66affSColin Finck             return REG_BINARY;
161*c2c66affSColin Finck     }
162*c2c66affSColin Finck 
163*c2c66affSColin Finck     return REG_NONE;
164*c2c66affSColin Finck }
165*c2c66affSColin Finck 
166*c2c66affSColin Finck 
167*c2c66affSColin Finck /***********************************************************************
168*c2c66affSColin Finck  * CMP_GetBlockedDriverInfo [SETUPAPI.@]
169*c2c66affSColin Finck  */
170*c2c66affSColin Finck CONFIGRET
171*c2c66affSColin Finck WINAPI
172*c2c66affSColin Finck CMP_GetBlockedDriverInfo(
173*c2c66affSColin Finck     _Out_opt_ LPWSTR pszNames,
174*c2c66affSColin Finck     _Inout_ PULONG pulLength,
175*c2c66affSColin Finck     _In_ ULONG ulFlags,
176*c2c66affSColin Finck     _In_opt_ HMACHINE hMachine)
177*c2c66affSColin Finck {
178*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
179*c2c66affSColin Finck     ULONG ulTransferLength;
180*c2c66affSColin Finck     CONFIGRET ret;
181*c2c66affSColin Finck 
182*c2c66affSColin Finck     TRACE("CMP_GetBlockedDriverInfo(%p %p %lx %p)\n",
183*c2c66affSColin Finck           pszNames, pulLength, ulFlags, hMachine);
184*c2c66affSColin Finck 
185*c2c66affSColin Finck     if (hMachine != NULL)
186*c2c66affSColin Finck     {
187*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
188*c2c66affSColin Finck         if (BindingHandle == NULL)
189*c2c66affSColin Finck             return CR_FAILURE;
190*c2c66affSColin Finck     }
191*c2c66affSColin Finck     else
192*c2c66affSColin Finck     {
193*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
194*c2c66affSColin Finck             return CR_FAILURE;
195*c2c66affSColin Finck     }
196*c2c66affSColin Finck 
197*c2c66affSColin Finck     ulTransferLength = *pulLength;
198*c2c66affSColin Finck 
199*c2c66affSColin Finck     RpcTryExcept
200*c2c66affSColin Finck     {
201*c2c66affSColin Finck         ret = PNP_GetBlockedDriverInfo(BindingHandle,
202*c2c66affSColin Finck                                        (PBYTE)pszNames,
203*c2c66affSColin Finck                                        &ulTransferLength,
204*c2c66affSColin Finck                                        pulLength,
205*c2c66affSColin Finck                                        ulFlags);
206*c2c66affSColin Finck     }
207*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
208*c2c66affSColin Finck     {
209*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
210*c2c66affSColin Finck     }
211*c2c66affSColin Finck     RpcEndExcept;
212*c2c66affSColin Finck 
213*c2c66affSColin Finck     return ret;
214*c2c66affSColin Finck }
215*c2c66affSColin Finck 
216*c2c66affSColin Finck 
217*c2c66affSColin Finck /***********************************************************************
218*c2c66affSColin Finck  * CMP_GetServerSideDeviceInstallFlags [SETUPAPI.@]
219*c2c66affSColin Finck  */
220*c2c66affSColin Finck CONFIGRET
221*c2c66affSColin Finck WINAPI
222*c2c66affSColin Finck CMP_GetServerSideDeviceInstallFlags(
223*c2c66affSColin Finck     _Out_ PULONG pulSSDIFlags,
224*c2c66affSColin Finck     _In_ ULONG ulFlags,
225*c2c66affSColin Finck     _In_opt_ HMACHINE hMachine)
226*c2c66affSColin Finck {
227*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
228*c2c66affSColin Finck     CONFIGRET ret;
229*c2c66affSColin Finck 
230*c2c66affSColin Finck     TRACE("CMP_GetServerSideDeviceInstallFlags(%p %lx %p)\n",
231*c2c66affSColin Finck           pulSSDIFlags, ulFlags, hMachine);
232*c2c66affSColin Finck 
233*c2c66affSColin Finck     if (pulSSDIFlags == NULL)
234*c2c66affSColin Finck         return CR_INVALID_POINTER;
235*c2c66affSColin Finck 
236*c2c66affSColin Finck     if (ulFlags != 0)
237*c2c66affSColin Finck         return CR_INVALID_FLAG;
238*c2c66affSColin Finck 
239*c2c66affSColin Finck     if (hMachine != NULL)
240*c2c66affSColin Finck     {
241*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
242*c2c66affSColin Finck         if (BindingHandle == NULL)
243*c2c66affSColin Finck             return CR_FAILURE;
244*c2c66affSColin Finck     }
245*c2c66affSColin Finck     else
246*c2c66affSColin Finck     {
247*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
248*c2c66affSColin Finck             return CR_FAILURE;
249*c2c66affSColin Finck     }
250*c2c66affSColin Finck 
251*c2c66affSColin Finck     RpcTryExcept
252*c2c66affSColin Finck     {
253*c2c66affSColin Finck         ret = PNP_GetServerSideDeviceInstallFlags(BindingHandle,
254*c2c66affSColin Finck                                                   pulSSDIFlags,
255*c2c66affSColin Finck                                                   ulFlags);
256*c2c66affSColin Finck     }
257*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
258*c2c66affSColin Finck     {
259*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
260*c2c66affSColin Finck     }
261*c2c66affSColin Finck     RpcEndExcept;
262*c2c66affSColin Finck 
263*c2c66affSColin Finck     return ret;
264*c2c66affSColin Finck }
265*c2c66affSColin Finck 
266*c2c66affSColin Finck 
267*c2c66affSColin Finck /***********************************************************************
268*c2c66affSColin Finck  * CMP_Init_Detection [SETUPAPI.@]
269*c2c66affSColin Finck  */
270*c2c66affSColin Finck CONFIGRET
271*c2c66affSColin Finck WINAPI
272*c2c66affSColin Finck CMP_Init_Detection(
273*c2c66affSColin Finck     _In_ ULONG ulMagic)
274*c2c66affSColin Finck {
275*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
276*c2c66affSColin Finck     CONFIGRET ret;
277*c2c66affSColin Finck 
278*c2c66affSColin Finck     TRACE("CMP_Init_Detection(%lu)\n", ulMagic);
279*c2c66affSColin Finck 
280*c2c66affSColin Finck     if (ulMagic != CMP_MAGIC)
281*c2c66affSColin Finck         return CR_INVALID_DATA;
282*c2c66affSColin Finck 
283*c2c66affSColin Finck     if (!PnpGetLocalHandles(&BindingHandle, NULL))
284*c2c66affSColin Finck         return CR_FAILURE;
285*c2c66affSColin Finck 
286*c2c66affSColin Finck     RpcTryExcept
287*c2c66affSColin Finck     {
288*c2c66affSColin Finck         ret = PNP_InitDetection(BindingHandle);
289*c2c66affSColin Finck     }
290*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
291*c2c66affSColin Finck     {
292*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
293*c2c66affSColin Finck     }
294*c2c66affSColin Finck     RpcEndExcept;
295*c2c66affSColin Finck 
296*c2c66affSColin Finck     return ret;
297*c2c66affSColin Finck }
298*c2c66affSColin Finck 
299*c2c66affSColin Finck 
300*c2c66affSColin Finck /***********************************************************************
301*c2c66affSColin Finck  * CMP_RegisterNotification [SETUPAPI.@]
302*c2c66affSColin Finck  */
303*c2c66affSColin Finck CONFIGRET
304*c2c66affSColin Finck WINAPI
305*c2c66affSColin Finck CMP_RegisterNotification(
306*c2c66affSColin Finck     _In_ HANDLE hRecipient,
307*c2c66affSColin Finck     _In_ LPVOID lpvNotificationFilter,
308*c2c66affSColin Finck     _In_ ULONG ulFlags,
309*c2c66affSColin Finck     _Out_ PHDEVNOTIFY phDevNotify)
310*c2c66affSColin Finck {
311*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
312*c2c66affSColin Finck     PNOTIFY_DATA pNotifyData = NULL;
313*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
314*c2c66affSColin Finck 
315*c2c66affSColin Finck     TRACE("CMP_RegisterNotification(%p %p %lu %p)\n",
316*c2c66affSColin Finck           hRecipient, lpvNotificationFilter, ulFlags, phDevNotify);
317*c2c66affSColin Finck 
318*c2c66affSColin Finck     if ((hRecipient == NULL) ||
319*c2c66affSColin Finck         (lpvNotificationFilter == NULL) ||
320*c2c66affSColin Finck         (phDevNotify == NULL))
321*c2c66affSColin Finck         return CR_INVALID_POINTER;
322*c2c66affSColin Finck 
323*c2c66affSColin Finck     if (ulFlags & ~0x7)
324*c2c66affSColin Finck         return CR_INVALID_FLAG;
325*c2c66affSColin Finck 
326*c2c66affSColin Finck     if (((PDEV_BROADCAST_HDR)lpvNotificationFilter)->dbch_size < sizeof(DEV_BROADCAST_HDR))
327*c2c66affSColin Finck         return CR_INVALID_DATA;
328*c2c66affSColin Finck 
329*c2c66affSColin Finck     if (!PnpGetLocalHandles(&BindingHandle, NULL))
330*c2c66affSColin Finck         return CR_FAILURE;
331*c2c66affSColin Finck 
332*c2c66affSColin Finck     pNotifyData = HeapAlloc(GetProcessHeap(),
333*c2c66affSColin Finck                             HEAP_ZERO_MEMORY,
334*c2c66affSColin Finck                             sizeof(NOTIFY_DATA));
335*c2c66affSColin Finck     if (pNotifyData == NULL)
336*c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
337*c2c66affSColin Finck 
338*c2c66affSColin Finck     pNotifyData->ulMagic = NOTIFY_MAGIC;
339*c2c66affSColin Finck 
340*c2c66affSColin Finck /*
341*c2c66affSColin Finck     if (dwFlags & DEVICE_NOTIFY_SERVICE_HANDLE == DEVICE_NOTYFY_WINDOW_HANDLE)
342*c2c66affSColin Finck     {
343*c2c66affSColin Finck 
344*c2c66affSColin Finck     }
345*c2c66affSColin Finck     else if (dwFlags & DEVICE_NOTIFY_SERVICE_HANDLE == DEVICE_NOTYFY_SERVICE_HANDLE)
346*c2c66affSColin Finck     {
347*c2c66affSColin Finck 
348*c2c66affSColin Finck     }
349*c2c66affSColin Finck */
350*c2c66affSColin Finck 
351*c2c66affSColin Finck     RpcTryExcept
352*c2c66affSColin Finck     {
353*c2c66affSColin Finck         ret = PNP_RegisterNotification(BindingHandle,
354*c2c66affSColin Finck                                        ulFlags,
355*c2c66affSColin Finck                                        &pNotifyData->ulNotifyData);
356*c2c66affSColin Finck     }
357*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
358*c2c66affSColin Finck     {
359*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
360*c2c66affSColin Finck     }
361*c2c66affSColin Finck     RpcEndExcept;
362*c2c66affSColin Finck 
363*c2c66affSColin Finck     if (ret == CR_SUCCESS)
364*c2c66affSColin Finck     {
365*c2c66affSColin Finck         *phDevNotify = (HDEVNOTIFY)pNotifyData;
366*c2c66affSColin Finck     }
367*c2c66affSColin Finck     else
368*c2c66affSColin Finck     {
369*c2c66affSColin Finck         if (pNotifyData != NULL)
370*c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, pNotifyData);
371*c2c66affSColin Finck 
372*c2c66affSColin Finck         *phDevNotify = (HDEVNOTIFY)NULL;
373*c2c66affSColin Finck     }
374*c2c66affSColin Finck 
375*c2c66affSColin Finck     return ret;
376*c2c66affSColin Finck }
377*c2c66affSColin Finck 
378*c2c66affSColin Finck 
379*c2c66affSColin Finck /***********************************************************************
380*c2c66affSColin Finck  * CMP_Report_LogOn [SETUPAPI.@]
381*c2c66affSColin Finck  */
382*c2c66affSColin Finck CONFIGRET
383*c2c66affSColin Finck WINAPI
384*c2c66affSColin Finck CMP_Report_LogOn(
385*c2c66affSColin Finck     _In_ DWORD dwMagic,
386*c2c66affSColin Finck     _In_ DWORD dwProcessId)
387*c2c66affSColin Finck {
388*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
389*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
390*c2c66affSColin Finck     BOOL bAdmin;
391*c2c66affSColin Finck     DWORD i;
392*c2c66affSColin Finck 
393*c2c66affSColin Finck     TRACE("CMP_Report_LogOn(%lu %lu)\n", dwMagic, dwProcessId);
394*c2c66affSColin Finck 
395*c2c66affSColin Finck     if (dwMagic != CMP_MAGIC)
396*c2c66affSColin Finck         return CR_INVALID_DATA;
397*c2c66affSColin Finck 
398*c2c66affSColin Finck     if (!PnpGetLocalHandles(&BindingHandle, NULL))
399*c2c66affSColin Finck         return CR_FAILURE;
400*c2c66affSColin Finck 
401*c2c66affSColin Finck     bAdmin = pSetupIsUserAdmin();
402*c2c66affSColin Finck 
403*c2c66affSColin Finck     for (i = 0; i < 30; i++)
404*c2c66affSColin Finck     {
405*c2c66affSColin Finck         RpcTryExcept
406*c2c66affSColin Finck         {
407*c2c66affSColin Finck             ret = PNP_ReportLogOn(BindingHandle,
408*c2c66affSColin Finck                                   bAdmin,
409*c2c66affSColin Finck                                   dwProcessId);
410*c2c66affSColin Finck         }
411*c2c66affSColin Finck         RpcExcept(EXCEPTION_EXECUTE_HANDLER)
412*c2c66affSColin Finck         {
413*c2c66affSColin Finck             ret = RpcStatusToCmStatus(RpcExceptionCode());
414*c2c66affSColin Finck         }
415*c2c66affSColin Finck         RpcEndExcept;
416*c2c66affSColin Finck 
417*c2c66affSColin Finck         if (ret == CR_SUCCESS)
418*c2c66affSColin Finck             break;
419*c2c66affSColin Finck 
420*c2c66affSColin Finck         Sleep(5000);
421*c2c66affSColin Finck     }
422*c2c66affSColin Finck 
423*c2c66affSColin Finck     return ret;
424*c2c66affSColin Finck }
425*c2c66affSColin Finck 
426*c2c66affSColin Finck 
427*c2c66affSColin Finck /***********************************************************************
428*c2c66affSColin Finck  * CMP_UnregisterNotification [SETUPAPI.@]
429*c2c66affSColin Finck  */
430*c2c66affSColin Finck CONFIGRET
431*c2c66affSColin Finck WINAPI
432*c2c66affSColin Finck CMP_UnregisterNotification(
433*c2c66affSColin Finck     _In_ HDEVNOTIFY hDevNotify)
434*c2c66affSColin Finck {
435*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
436*c2c66affSColin Finck     PNOTIFY_DATA pNotifyData;
437*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
438*c2c66affSColin Finck 
439*c2c66affSColin Finck     TRACE("CMP_UnregisterNotification(%p)\n", hDevNotify);
440*c2c66affSColin Finck 
441*c2c66affSColin Finck     pNotifyData = (PNOTIFY_DATA)hDevNotify;
442*c2c66affSColin Finck 
443*c2c66affSColin Finck     if ((pNotifyData == NULL) ||
444*c2c66affSColin Finck         (pNotifyData->ulMagic != NOTIFY_MAGIC))
445*c2c66affSColin Finck         return CR_INVALID_POINTER;
446*c2c66affSColin Finck 
447*c2c66affSColin Finck     if (!PnpGetLocalHandles(&BindingHandle, NULL))
448*c2c66affSColin Finck         return CR_FAILURE;
449*c2c66affSColin Finck 
450*c2c66affSColin Finck     RpcTryExcept
451*c2c66affSColin Finck     {
452*c2c66affSColin Finck         ret = PNP_UnregisterNotification(BindingHandle,
453*c2c66affSColin Finck                                          pNotifyData->ulNotifyData);
454*c2c66affSColin Finck     }
455*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
456*c2c66affSColin Finck     {
457*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
458*c2c66affSColin Finck     }
459*c2c66affSColin Finck     RpcEndExcept;
460*c2c66affSColin Finck 
461*c2c66affSColin Finck     if (ret == CR_SUCCESS)
462*c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, pNotifyData);
463*c2c66affSColin Finck 
464*c2c66affSColin Finck     return ret;
465*c2c66affSColin Finck }
466*c2c66affSColin Finck 
467*c2c66affSColin Finck 
468*c2c66affSColin Finck /***********************************************************************
469*c2c66affSColin Finck  * CMP_WaitNoPendingInstallEvents [SETUPAPI.@]
470*c2c66affSColin Finck  */
471*c2c66affSColin Finck DWORD
472*c2c66affSColin Finck WINAPI
473*c2c66affSColin Finck CMP_WaitNoPendingInstallEvents(
474*c2c66affSColin Finck     _In_ DWORD dwTimeout)
475*c2c66affSColin Finck {
476*c2c66affSColin Finck     HANDLE hEvent;
477*c2c66affSColin Finck     DWORD ret;
478*c2c66affSColin Finck 
479*c2c66affSColin Finck     TRACE("CMP_WaitNoPendingInstallEvents(%lu)\n", dwTimeout);
480*c2c66affSColin Finck 
481*c2c66affSColin Finck     hEvent = OpenEventW(SYNCHRONIZE, FALSE, L"Global\\PnP_No_Pending_Install_Events");
482*c2c66affSColin Finck     if (hEvent == NULL)
483*c2c66affSColin Finck        return WAIT_FAILED;
484*c2c66affSColin Finck 
485*c2c66affSColin Finck     ret = WaitForSingleObject(hEvent, dwTimeout);
486*c2c66affSColin Finck     CloseHandle(hEvent);
487*c2c66affSColin Finck     return ret;
488*c2c66affSColin Finck }
489*c2c66affSColin Finck 
490*c2c66affSColin Finck 
491*c2c66affSColin Finck /***********************************************************************
492*c2c66affSColin Finck  * CMP_WaitServicesAvailable [SETUPAPI.@]
493*c2c66affSColin Finck  */
494*c2c66affSColin Finck CONFIGRET
495*c2c66affSColin Finck WINAPI
496*c2c66affSColin Finck CMP_WaitServicesAvailable(
497*c2c66affSColin Finck     _In_opt_ HMACHINE hMachine)
498*c2c66affSColin Finck {
499*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
500*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
501*c2c66affSColin Finck     WORD Version;
502*c2c66affSColin Finck 
503*c2c66affSColin Finck     TRACE("CMP_WaitServicesAvailable(%p)\n", hMachine);
504*c2c66affSColin Finck 
505*c2c66affSColin Finck     if (hMachine != NULL)
506*c2c66affSColin Finck     {
507*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
508*c2c66affSColin Finck         if (BindingHandle == NULL)
509*c2c66affSColin Finck             return CR_FAILURE;
510*c2c66affSColin Finck     }
511*c2c66affSColin Finck     else
512*c2c66affSColin Finck     {
513*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
514*c2c66affSColin Finck             return CR_FAILURE;
515*c2c66affSColin Finck     }
516*c2c66affSColin Finck 
517*c2c66affSColin Finck     RpcTryExcept
518*c2c66affSColin Finck     {
519*c2c66affSColin Finck         ret = PNP_GetVersion(BindingHandle, &Version);
520*c2c66affSColin Finck     }
521*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
522*c2c66affSColin Finck     {
523*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
524*c2c66affSColin Finck     }
525*c2c66affSColin Finck     RpcEndExcept;
526*c2c66affSColin Finck 
527*c2c66affSColin Finck     return ret;
528*c2c66affSColin Finck }
529*c2c66affSColin Finck 
530*c2c66affSColin Finck 
531*c2c66affSColin Finck /***********************************************************************
532*c2c66affSColin Finck  * CM_Add_Empty_Log_Conf [SETUPAPI.@]
533*c2c66affSColin Finck  */
534*c2c66affSColin Finck CONFIGRET WINAPI CM_Add_Empty_Log_Conf(
535*c2c66affSColin Finck     PLOG_CONF plcLogConf, DEVINST dnDevInst, PRIORITY Priority,
536*c2c66affSColin Finck     ULONG ulFlags)
537*c2c66affSColin Finck {
538*c2c66affSColin Finck     TRACE("%p %p %lu %lx\n", plcLogConf, dnDevInst, Priority, ulFlags);
539*c2c66affSColin Finck     return CM_Add_Empty_Log_Conf_Ex(plcLogConf, dnDevInst, Priority,
540*c2c66affSColin Finck                                     ulFlags, NULL);
541*c2c66affSColin Finck }
542*c2c66affSColin Finck 
543*c2c66affSColin Finck 
544*c2c66affSColin Finck /***********************************************************************
545*c2c66affSColin Finck  * CM_Add_Empty_Log_Conf_Ex [SETUPAPI.@]
546*c2c66affSColin Finck  */
547*c2c66affSColin Finck CONFIGRET WINAPI CM_Add_Empty_Log_Conf_Ex(
548*c2c66affSColin Finck     PLOG_CONF plcLogConf, DEVINST dnDevInst, PRIORITY Priority,
549*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
550*c2c66affSColin Finck {
551*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
552*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
553*c2c66affSColin Finck     ULONG ulLogConfTag = 0;
554*c2c66affSColin Finck     LPWSTR lpDevInst;
555*c2c66affSColin Finck     PLOG_CONF_INFO pLogConfInfo;
556*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
557*c2c66affSColin Finck 
558*c2c66affSColin Finck     FIXME("%p %p %lu %lx %p\n",
559*c2c66affSColin Finck           plcLogConf, dnDevInst, Priority, ulFlags, hMachine);
560*c2c66affSColin Finck 
561*c2c66affSColin Finck     if (!pSetupIsUserAdmin())
562*c2c66affSColin Finck         return CR_ACCESS_DENIED;
563*c2c66affSColin Finck 
564*c2c66affSColin Finck     if (plcLogConf == NULL)
565*c2c66affSColin Finck         return CR_INVALID_POINTER;
566*c2c66affSColin Finck 
567*c2c66affSColin Finck     if (dnDevInst == 0)
568*c2c66affSColin Finck         return CR_INVALID_DEVINST;
569*c2c66affSColin Finck 
570*c2c66affSColin Finck     if (Priority > 0xFFFF)
571*c2c66affSColin Finck         return CR_INVALID_PRIORITY;
572*c2c66affSColin Finck 
573*c2c66affSColin Finck     if (ulFlags & ~(LOG_CONF_BITS | PRIORITY_BIT))
574*c2c66affSColin Finck         return CR_INVALID_FLAG;
575*c2c66affSColin Finck 
576*c2c66affSColin Finck     if (hMachine != NULL)
577*c2c66affSColin Finck     {
578*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
579*c2c66affSColin Finck         if (BindingHandle == NULL)
580*c2c66affSColin Finck             return CR_FAILURE;
581*c2c66affSColin Finck 
582*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
583*c2c66affSColin Finck         if (StringTable == 0)
584*c2c66affSColin Finck             return CR_FAILURE;
585*c2c66affSColin Finck     }
586*c2c66affSColin Finck     else
587*c2c66affSColin Finck     {
588*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
589*c2c66affSColin Finck             return CR_FAILURE;
590*c2c66affSColin Finck     }
591*c2c66affSColin Finck 
592*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
593*c2c66affSColin Finck     if (lpDevInst == NULL)
594*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
595*c2c66affSColin Finck 
596*c2c66affSColin Finck     RpcTryExcept
597*c2c66affSColin Finck     {
598*c2c66affSColin Finck         ret = PNP_AddEmptyLogConf(BindingHandle, lpDevInst, Priority,
599*c2c66affSColin Finck                                   &ulLogConfTag, ulFlags);
600*c2c66affSColin Finck     }
601*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
602*c2c66affSColin Finck     {
603*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
604*c2c66affSColin Finck     }
605*c2c66affSColin Finck     RpcEndExcept;
606*c2c66affSColin Finck 
607*c2c66affSColin Finck     if (ret == CR_SUCCESS)
608*c2c66affSColin Finck     {
609*c2c66affSColin Finck         pLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
610*c2c66affSColin Finck         if (pLogConfInfo == NULL)
611*c2c66affSColin Finck         {
612*c2c66affSColin Finck             ret = CR_OUT_OF_MEMORY;
613*c2c66affSColin Finck         }
614*c2c66affSColin Finck         else
615*c2c66affSColin Finck         {
616*c2c66affSColin Finck             pLogConfInfo->ulMagic = LOG_CONF_MAGIC;
617*c2c66affSColin Finck             pLogConfInfo->dnDevInst = dnDevInst;
618*c2c66affSColin Finck             pLogConfInfo->ulFlags = ulFlags;
619*c2c66affSColin Finck             pLogConfInfo->ulTag = ulLogConfTag;
620*c2c66affSColin Finck 
621*c2c66affSColin Finck             *plcLogConf = (LOG_CONF)pLogConfInfo;
622*c2c66affSColin Finck 
623*c2c66affSColin Finck             ret = CR_SUCCESS;
624*c2c66affSColin Finck         }
625*c2c66affSColin Finck     }
626*c2c66affSColin Finck 
627*c2c66affSColin Finck     return ret;
628*c2c66affSColin Finck }
629*c2c66affSColin Finck 
630*c2c66affSColin Finck 
631*c2c66affSColin Finck /***********************************************************************
632*c2c66affSColin Finck  * CM_Add_IDA [SETUPAPI.@]
633*c2c66affSColin Finck  */
634*c2c66affSColin Finck CONFIGRET WINAPI CM_Add_IDA(
635*c2c66affSColin Finck     DEVINST dnDevInst, PSTR pszID, ULONG ulFlags)
636*c2c66affSColin Finck {
637*c2c66affSColin Finck     TRACE("%p %s %lx\n", dnDevInst, pszID, ulFlags);
638*c2c66affSColin Finck     return CM_Add_ID_ExA(dnDevInst, pszID, ulFlags, NULL);
639*c2c66affSColin Finck }
640*c2c66affSColin Finck 
641*c2c66affSColin Finck 
642*c2c66affSColin Finck /***********************************************************************
643*c2c66affSColin Finck  * CM_Add_IDW [SETUPAPI.@]
644*c2c66affSColin Finck  */
645*c2c66affSColin Finck CONFIGRET WINAPI CM_Add_IDW(
646*c2c66affSColin Finck     DEVINST dnDevInst, PWSTR pszID, ULONG ulFlags)
647*c2c66affSColin Finck {
648*c2c66affSColin Finck     TRACE("%p %s %lx\n", dnDevInst, debugstr_w(pszID), ulFlags);
649*c2c66affSColin Finck     return CM_Add_ID_ExW(dnDevInst, pszID, ulFlags, NULL);
650*c2c66affSColin Finck }
651*c2c66affSColin Finck 
652*c2c66affSColin Finck 
653*c2c66affSColin Finck /***********************************************************************
654*c2c66affSColin Finck  * CM_Add_ID_ExA [SETUPAPI.@]
655*c2c66affSColin Finck  */
656*c2c66affSColin Finck CONFIGRET WINAPI CM_Add_ID_ExA(
657*c2c66affSColin Finck     DEVINST dnDevInst, PSTR pszID, ULONG ulFlags, HMACHINE hMachine)
658*c2c66affSColin Finck {
659*c2c66affSColin Finck     PWSTR pszIDW;
660*c2c66affSColin Finck     CONFIGRET ret;
661*c2c66affSColin Finck 
662*c2c66affSColin Finck     TRACE("%p %s %lx %p\n", dnDevInst, pszID, ulFlags, hMachine);
663*c2c66affSColin Finck 
664*c2c66affSColin Finck     if (pSetupCaptureAndConvertAnsiArg(pszID, &pszIDW))
665*c2c66affSColin Finck         return CR_INVALID_DATA;
666*c2c66affSColin Finck 
667*c2c66affSColin Finck     ret = CM_Add_ID_ExW(dnDevInst, pszIDW, ulFlags, hMachine);
668*c2c66affSColin Finck 
669*c2c66affSColin Finck     MyFree(pszIDW);
670*c2c66affSColin Finck 
671*c2c66affSColin Finck     return ret;
672*c2c66affSColin Finck }
673*c2c66affSColin Finck 
674*c2c66affSColin Finck 
675*c2c66affSColin Finck /***********************************************************************
676*c2c66affSColin Finck  * CM_Add_ID_ExW [SETUPAPI.@]
677*c2c66affSColin Finck  */
678*c2c66affSColin Finck CONFIGRET WINAPI CM_Add_ID_ExW(
679*c2c66affSColin Finck     DEVINST dnDevInst, PWSTR pszID, ULONG ulFlags, HMACHINE hMachine)
680*c2c66affSColin Finck {
681*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
682*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
683*c2c66affSColin Finck     LPWSTR lpDevInst;
684*c2c66affSColin Finck     CONFIGRET ret;
685*c2c66affSColin Finck 
686*c2c66affSColin Finck     TRACE("%p %s %lx %p\n", dnDevInst, debugstr_w(pszID), ulFlags, hMachine);
687*c2c66affSColin Finck 
688*c2c66affSColin Finck     if (!pSetupIsUserAdmin())
689*c2c66affSColin Finck         return CR_ACCESS_DENIED;
690*c2c66affSColin Finck 
691*c2c66affSColin Finck     if (dnDevInst == 0)
692*c2c66affSColin Finck         return CR_INVALID_DEVINST;
693*c2c66affSColin Finck 
694*c2c66affSColin Finck     if (pszID == NULL)
695*c2c66affSColin Finck         return CR_INVALID_POINTER;
696*c2c66affSColin Finck 
697*c2c66affSColin Finck     if (ulFlags & ~CM_ADD_ID_BITS)
698*c2c66affSColin Finck         return CR_INVALID_FLAG;
699*c2c66affSColin Finck 
700*c2c66affSColin Finck     if (hMachine != NULL)
701*c2c66affSColin Finck     {
702*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
703*c2c66affSColin Finck         if (BindingHandle == NULL)
704*c2c66affSColin Finck             return CR_FAILURE;
705*c2c66affSColin Finck 
706*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
707*c2c66affSColin Finck         if (StringTable == 0)
708*c2c66affSColin Finck             return CR_FAILURE;
709*c2c66affSColin Finck     }
710*c2c66affSColin Finck     else
711*c2c66affSColin Finck     {
712*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
713*c2c66affSColin Finck             return CR_FAILURE;
714*c2c66affSColin Finck     }
715*c2c66affSColin Finck 
716*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
717*c2c66affSColin Finck     if (lpDevInst == NULL)
718*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
719*c2c66affSColin Finck 
720*c2c66affSColin Finck     RpcTryExcept
721*c2c66affSColin Finck     {
722*c2c66affSColin Finck         ret = PNP_AddID(BindingHandle,
723*c2c66affSColin Finck                         lpDevInst,
724*c2c66affSColin Finck                         pszID,
725*c2c66affSColin Finck                         ulFlags);
726*c2c66affSColin Finck     }
727*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
728*c2c66affSColin Finck     {
729*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
730*c2c66affSColin Finck     }
731*c2c66affSColin Finck     RpcEndExcept;
732*c2c66affSColin Finck 
733*c2c66affSColin Finck     return ret;
734*c2c66affSColin Finck }
735*c2c66affSColin Finck 
736*c2c66affSColin Finck 
737*c2c66affSColin Finck /***********************************************************************
738*c2c66affSColin Finck  * CM_Add_Range [SETUPAPI.@]
739*c2c66affSColin Finck  */
740*c2c66affSColin Finck CONFIGRET
741*c2c66affSColin Finck WINAPI
742*c2c66affSColin Finck CM_Add_Range(
743*c2c66affSColin Finck     _In_ DWORDLONG ullStartValue,
744*c2c66affSColin Finck     _In_ DWORDLONG ullEndValue,
745*c2c66affSColin Finck     _In_ RANGE_LIST rlh,
746*c2c66affSColin Finck     _In_ ULONG ulFlags)
747*c2c66affSColin Finck {
748*c2c66affSColin Finck     FIXME("CM_Add_Range(%I64u %I64u %p %lx)\n",
749*c2c66affSColin Finck           ullStartValue, ullEndValue, rlh, ulFlags);
750*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
751*c2c66affSColin Finck }
752*c2c66affSColin Finck 
753*c2c66affSColin Finck 
754*c2c66affSColin Finck /***********************************************************************
755*c2c66affSColin Finck  * CM_Add_Res_Des [SETUPAPI.@]
756*c2c66affSColin Finck  */
757*c2c66affSColin Finck CONFIGRET WINAPI CM_Add_Res_Des(
758*c2c66affSColin Finck     PRES_DES prdResDes, LOG_CONF lcLogConf, RESOURCEID ResourceID,
759*c2c66affSColin Finck     PCVOID ResourceData, ULONG ResourceLen, ULONG ulFlags)
760*c2c66affSColin Finck {
761*c2c66affSColin Finck     TRACE("%p %p %lu %p %lu %lx\n", prdResDes, lcLogConf, ResourceID,
762*c2c66affSColin Finck           ResourceData, ResourceLen, ulFlags);
763*c2c66affSColin Finck     return CM_Add_Res_Des_Ex(prdResDes, lcLogConf, ResourceID, ResourceData,
764*c2c66affSColin Finck                              ResourceLen, ulFlags, NULL);
765*c2c66affSColin Finck }
766*c2c66affSColin Finck 
767*c2c66affSColin Finck 
768*c2c66affSColin Finck /***********************************************************************
769*c2c66affSColin Finck  * CM_Add_Res_Des_Ex [SETUPAPI.@]
770*c2c66affSColin Finck  */
771*c2c66affSColin Finck CONFIGRET WINAPI CM_Add_Res_Des_Ex(
772*c2c66affSColin Finck     PRES_DES prdResDes, LOG_CONF lcLogConf, RESOURCEID ResourceID,
773*c2c66affSColin Finck     PCVOID ResourceData, ULONG ResourceLen, ULONG ulFlags, HMACHINE hMachine)
774*c2c66affSColin Finck {
775*c2c66affSColin Finck     FIXME("%p %p %lu %p %lu %lx %p\n", prdResDes, lcLogConf, ResourceID,
776*c2c66affSColin Finck           ResourceData, ResourceLen, ulFlags, hMachine);
777*c2c66affSColin Finck 
778*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
779*c2c66affSColin Finck }
780*c2c66affSColin Finck 
781*c2c66affSColin Finck 
782*c2c66affSColin Finck /***********************************************************************
783*c2c66affSColin Finck  * CM_Connect_MachineA [SETUPAPI.@]
784*c2c66affSColin Finck  */
785*c2c66affSColin Finck CONFIGRET WINAPI CM_Connect_MachineA(
786*c2c66affSColin Finck     PCSTR UNCServerName, PHMACHINE phMachine)
787*c2c66affSColin Finck {
788*c2c66affSColin Finck     PWSTR pServerNameW;
789*c2c66affSColin Finck     CONFIGRET ret;
790*c2c66affSColin Finck 
791*c2c66affSColin Finck     TRACE("%s %p\n", UNCServerName, phMachine);
792*c2c66affSColin Finck 
793*c2c66affSColin Finck     if (UNCServerName == NULL || *UNCServerName == 0)
794*c2c66affSColin Finck         return CM_Connect_MachineW(NULL, phMachine);
795*c2c66affSColin Finck 
796*c2c66affSColin Finck     if (pSetupCaptureAndConvertAnsiArg(UNCServerName, &pServerNameW))
797*c2c66affSColin Finck         return CR_INVALID_DATA;
798*c2c66affSColin Finck 
799*c2c66affSColin Finck     ret = CM_Connect_MachineW(pServerNameW, phMachine);
800*c2c66affSColin Finck 
801*c2c66affSColin Finck     MyFree(pServerNameW);
802*c2c66affSColin Finck 
803*c2c66affSColin Finck     return ret;
804*c2c66affSColin Finck }
805*c2c66affSColin Finck 
806*c2c66affSColin Finck 
807*c2c66affSColin Finck /***********************************************************************
808*c2c66affSColin Finck  * CM_Connect_MachineW [SETUPAPI.@]
809*c2c66affSColin Finck  */
810*c2c66affSColin Finck CONFIGRET WINAPI CM_Connect_MachineW(
811*c2c66affSColin Finck     PCWSTR UNCServerName, PHMACHINE phMachine)
812*c2c66affSColin Finck {
813*c2c66affSColin Finck     PMACHINE_INFO pMachine;
814*c2c66affSColin Finck 
815*c2c66affSColin Finck     TRACE("%s %p\n", debugstr_w(UNCServerName), phMachine);
816*c2c66affSColin Finck 
817*c2c66affSColin Finck     if (phMachine == NULL)
818*c2c66affSColin Finck         return CR_INVALID_POINTER;
819*c2c66affSColin Finck 
820*c2c66affSColin Finck     *phMachine = NULL;
821*c2c66affSColin Finck 
822*c2c66affSColin Finck     pMachine = HeapAlloc(GetProcessHeap(), 0, sizeof(MACHINE_INFO));
823*c2c66affSColin Finck     if (pMachine == NULL)
824*c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
825*c2c66affSColin Finck 
826*c2c66affSColin Finck     if (UNCServerName == NULL || *UNCServerName == 0)
827*c2c66affSColin Finck     {
828*c2c66affSColin Finck         pMachine->bLocal = TRUE;
829*c2c66affSColin Finck 
830*c2c66affSColin Finck         /* FIXME: store the computers name in pMachine->szMachineName */
831*c2c66affSColin Finck 
832*c2c66affSColin Finck         if (!PnpGetLocalHandles(&pMachine->BindingHandle,
833*c2c66affSColin Finck                                 &pMachine->StringTable))
834*c2c66affSColin Finck         {
835*c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, pMachine);
836*c2c66affSColin Finck             return CR_FAILURE;
837*c2c66affSColin Finck         }
838*c2c66affSColin Finck     }
839*c2c66affSColin Finck     else
840*c2c66affSColin Finck     {
841*c2c66affSColin Finck         pMachine->bLocal = FALSE;
842*c2c66affSColin Finck         if (wcslen(UNCServerName) >= SP_MAX_MACHINENAME_LENGTH - 1)
843*c2c66affSColin Finck         {
844*c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, pMachine);
845*c2c66affSColin Finck             return CR_INVALID_MACHINENAME;
846*c2c66affSColin Finck         }
847*c2c66affSColin Finck         lstrcpyW(pMachine->szMachineName, UNCServerName);
848*c2c66affSColin Finck 
849*c2c66affSColin Finck         pMachine->StringTable = pSetupStringTableInitialize();
850*c2c66affSColin Finck         if (pMachine->StringTable == NULL)
851*c2c66affSColin Finck         {
852*c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, pMachine);
853*c2c66affSColin Finck             return CR_FAILURE;
854*c2c66affSColin Finck         }
855*c2c66affSColin Finck 
856*c2c66affSColin Finck         pSetupStringTableAddString(pMachine->StringTable, L"PLT", 1);
857*c2c66affSColin Finck 
858*c2c66affSColin Finck         if (!PnpBindRpc(UNCServerName, &pMachine->BindingHandle))
859*c2c66affSColin Finck         {
860*c2c66affSColin Finck             pSetupStringTableDestroy(pMachine->StringTable);
861*c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, pMachine);
862*c2c66affSColin Finck             return CR_INVALID_MACHINENAME;
863*c2c66affSColin Finck         }
864*c2c66affSColin Finck     }
865*c2c66affSColin Finck 
866*c2c66affSColin Finck     *phMachine = (PHMACHINE)pMachine;
867*c2c66affSColin Finck 
868*c2c66affSColin Finck     return CR_SUCCESS;
869*c2c66affSColin Finck }
870*c2c66affSColin Finck 
871*c2c66affSColin Finck 
872*c2c66affSColin Finck /***********************************************************************
873*c2c66affSColin Finck  * CM_Create_DevNodeA [SETUPAPI.@]
874*c2c66affSColin Finck  */
875*c2c66affSColin Finck CONFIGRET WINAPI CM_Create_DevNodeA(
876*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, DEVINST dnParent,
877*c2c66affSColin Finck     ULONG ulFlags)
878*c2c66affSColin Finck {
879*c2c66affSColin Finck     TRACE("%p %s %p %lx\n",
880*c2c66affSColin Finck           pdnDevInst, debugstr_a(pDeviceID), dnParent, ulFlags);
881*c2c66affSColin Finck     return CM_Create_DevNode_ExA(pdnDevInst, pDeviceID, dnParent,
882*c2c66affSColin Finck                                  ulFlags, NULL);
883*c2c66affSColin Finck }
884*c2c66affSColin Finck 
885*c2c66affSColin Finck 
886*c2c66affSColin Finck /***********************************************************************
887*c2c66affSColin Finck  * CM_Create_DevNodeW [SETUPAPI.@]
888*c2c66affSColin Finck  */
889*c2c66affSColin Finck CONFIGRET WINAPI CM_Create_DevNodeW(
890*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINSTID_W pDeviceID, DEVINST dnParent,
891*c2c66affSColin Finck     ULONG ulFlags)
892*c2c66affSColin Finck {
893*c2c66affSColin Finck     TRACE("%p %s %p %lx\n",
894*c2c66affSColin Finck           pdnDevInst, debugstr_w(pDeviceID), dnParent, ulFlags);
895*c2c66affSColin Finck     return CM_Create_DevNode_ExW(pdnDevInst, pDeviceID, dnParent,
896*c2c66affSColin Finck                                  ulFlags, NULL);
897*c2c66affSColin Finck }
898*c2c66affSColin Finck 
899*c2c66affSColin Finck 
900*c2c66affSColin Finck /***********************************************************************
901*c2c66affSColin Finck  * CM_Create_DevNode_ExA [SETUPAPI.@]
902*c2c66affSColin Finck  */
903*c2c66affSColin Finck CONFIGRET WINAPI CM_Create_DevNode_ExA(
904*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, DEVINST dnParent,
905*c2c66affSColin Finck     ULONG ulFlags, HANDLE hMachine)
906*c2c66affSColin Finck {
907*c2c66affSColin Finck     DEVINSTID_W pDeviceIDW;
908*c2c66affSColin Finck     CONFIGRET ret;
909*c2c66affSColin Finck 
910*c2c66affSColin Finck     TRACE("%p %s %p %lx %p\n",
911*c2c66affSColin Finck           pdnDevInst, debugstr_a(pDeviceID), dnParent, ulFlags, hMachine);
912*c2c66affSColin Finck 
913*c2c66affSColin Finck     if (pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDeviceIDW))
914*c2c66affSColin Finck         return CR_INVALID_DATA;
915*c2c66affSColin Finck 
916*c2c66affSColin Finck     ret = CM_Create_DevNode_ExW(pdnDevInst, pDeviceIDW, dnParent, ulFlags,
917*c2c66affSColin Finck                                 hMachine);
918*c2c66affSColin Finck 
919*c2c66affSColin Finck     MyFree(pDeviceIDW);
920*c2c66affSColin Finck 
921*c2c66affSColin Finck     return ret;
922*c2c66affSColin Finck }
923*c2c66affSColin Finck 
924*c2c66affSColin Finck 
925*c2c66affSColin Finck /***********************************************************************
926*c2c66affSColin Finck  * CM_Create_DevNode_ExW [SETUPAPI.@]
927*c2c66affSColin Finck  */
928*c2c66affSColin Finck CONFIGRET WINAPI CM_Create_DevNode_ExW(
929*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINSTID_W pDeviceID, DEVINST dnParent,
930*c2c66affSColin Finck     ULONG ulFlags, HANDLE hMachine)
931*c2c66affSColin Finck {
932*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
933*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
934*c2c66affSColin Finck     LPWSTR lpParentDevInst;
935*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
936*c2c66affSColin Finck     WCHAR szLocalDeviceID[MAX_DEVICE_ID_LEN];
937*c2c66affSColin Finck 
938*c2c66affSColin Finck     TRACE("%p %s %p %lx %p\n",
939*c2c66affSColin Finck           pdnDevInst, debugstr_w(pDeviceID), dnParent, ulFlags, hMachine);
940*c2c66affSColin Finck 
941*c2c66affSColin Finck     if (!pSetupIsUserAdmin())
942*c2c66affSColin Finck         return CR_ACCESS_DENIED;
943*c2c66affSColin Finck 
944*c2c66affSColin Finck     if (pdnDevInst == NULL)
945*c2c66affSColin Finck         return CR_INVALID_POINTER;
946*c2c66affSColin Finck 
947*c2c66affSColin Finck     if (pDeviceID == NULL || wcslen(pDeviceID) == 0 || wcslen(pDeviceID) >= MAX_DEVICE_ID_LEN)
948*c2c66affSColin Finck         return CR_INVALID_DEVICE_ID;
949*c2c66affSColin Finck 
950*c2c66affSColin Finck     if (dnParent == 0)
951*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
952*c2c66affSColin Finck 
953*c2c66affSColin Finck     if (ulFlags & ~CM_CREATE_DEVNODE_BITS)
954*c2c66affSColin Finck         return CR_INVALID_FLAG;
955*c2c66affSColin Finck 
956*c2c66affSColin Finck     if (hMachine != NULL)
957*c2c66affSColin Finck     {
958*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
959*c2c66affSColin Finck         if (BindingHandle == NULL)
960*c2c66affSColin Finck             return CR_FAILURE;
961*c2c66affSColin Finck 
962*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
963*c2c66affSColin Finck         if (StringTable == 0)
964*c2c66affSColin Finck             return CR_FAILURE;
965*c2c66affSColin Finck     }
966*c2c66affSColin Finck     else
967*c2c66affSColin Finck     {
968*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
969*c2c66affSColin Finck             return CR_FAILURE;
970*c2c66affSColin Finck     }
971*c2c66affSColin Finck 
972*c2c66affSColin Finck     lpParentDevInst = pSetupStringTableStringFromId(StringTable, dnParent);
973*c2c66affSColin Finck     if (lpParentDevInst == NULL)
974*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
975*c2c66affSColin Finck 
976*c2c66affSColin Finck     wcscpy(szLocalDeviceID, pDeviceID);
977*c2c66affSColin Finck 
978*c2c66affSColin Finck     RpcTryExcept
979*c2c66affSColin Finck     {
980*c2c66affSColin Finck         ret = PNP_CreateDevInst(BindingHandle,
981*c2c66affSColin Finck                                 szLocalDeviceID,
982*c2c66affSColin Finck                                 lpParentDevInst,
983*c2c66affSColin Finck                                 MAX_DEVICE_ID_LEN,
984*c2c66affSColin Finck                                 ulFlags);
985*c2c66affSColin Finck     }
986*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
987*c2c66affSColin Finck     {
988*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
989*c2c66affSColin Finck     }
990*c2c66affSColin Finck     RpcEndExcept;
991*c2c66affSColin Finck 
992*c2c66affSColin Finck     if (ret == CR_SUCCESS)
993*c2c66affSColin Finck     {
994*c2c66affSColin Finck         /* If CM_CREATE_DEVINST_GENERATE_ID was passed in, PNP_CreateDevInst
995*c2c66affSColin Finck          * will return the generated device ID in szLocalDeviceID */
996*c2c66affSColin Finck         *pdnDevInst = pSetupStringTableAddString(StringTable, szLocalDeviceID, 1);
997*c2c66affSColin Finck         if (*pdnDevInst == 0)
998*c2c66affSColin Finck             ret = CR_NO_SUCH_DEVNODE;
999*c2c66affSColin Finck     }
1000*c2c66affSColin Finck 
1001*c2c66affSColin Finck     return ret;
1002*c2c66affSColin Finck }
1003*c2c66affSColin Finck 
1004*c2c66affSColin Finck 
1005*c2c66affSColin Finck /***********************************************************************
1006*c2c66affSColin Finck  * CM_Create_Range_List [SETUPAPI.@]
1007*c2c66affSColin Finck  */
1008*c2c66affSColin Finck CONFIGRET
1009*c2c66affSColin Finck WINAPI
1010*c2c66affSColin Finck CM_Create_Range_List(
1011*c2c66affSColin Finck     _Out_ PRANGE_LIST prlh,
1012*c2c66affSColin Finck     _In_ ULONG ulFlags)
1013*c2c66affSColin Finck {
1014*c2c66affSColin Finck     PINTERNAL_RANGE_LIST pRangeList = NULL;
1015*c2c66affSColin Finck 
1016*c2c66affSColin Finck     FIXME("CM_Create_Range_List(%p %lx)\n", prlh, ulFlags);
1017*c2c66affSColin Finck 
1018*c2c66affSColin Finck     if (ulFlags != 0)
1019*c2c66affSColin Finck         return CR_INVALID_FLAG;
1020*c2c66affSColin Finck 
1021*c2c66affSColin Finck     if (prlh == NULL)
1022*c2c66affSColin Finck         return CR_INVALID_POINTER;
1023*c2c66affSColin Finck 
1024*c2c66affSColin Finck     pRangeList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(INTERNAL_RANGE_LIST));
1025*c2c66affSColin Finck     if (pRangeList == NULL)
1026*c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
1027*c2c66affSColin Finck 
1028*c2c66affSColin Finck     pRangeList->ulMagic = RANGE_LIST_MAGIC;
1029*c2c66affSColin Finck 
1030*c2c66affSColin Finck     // TODO: More initialization
1031*c2c66affSColin Finck 
1032*c2c66affSColin Finck     *prlh = (RANGE_LIST)pRangeList;
1033*c2c66affSColin Finck 
1034*c2c66affSColin Finck     return CR_SUCCESS;
1035*c2c66affSColin Finck }
1036*c2c66affSColin Finck 
1037*c2c66affSColin Finck 
1038*c2c66affSColin Finck /***********************************************************************
1039*c2c66affSColin Finck  * CM_Delete_Class_Key [SETUPAPI.@]
1040*c2c66affSColin Finck  */
1041*c2c66affSColin Finck CONFIGRET WINAPI CM_Delete_Class_Key(
1042*c2c66affSColin Finck     LPGUID ClassGuid, ULONG ulFlags)
1043*c2c66affSColin Finck {
1044*c2c66affSColin Finck     TRACE("%p %lx\n", ClassGuid, ulFlags);
1045*c2c66affSColin Finck     return CM_Delete_Class_Key_Ex(ClassGuid, ulFlags, NULL);
1046*c2c66affSColin Finck }
1047*c2c66affSColin Finck 
1048*c2c66affSColin Finck 
1049*c2c66affSColin Finck /***********************************************************************
1050*c2c66affSColin Finck  * CM_Delete_Class_Key_Ex [SETUPAPI.@]
1051*c2c66affSColin Finck  */
1052*c2c66affSColin Finck CONFIGRET WINAPI CM_Delete_Class_Key_Ex(
1053*c2c66affSColin Finck     LPGUID ClassGuid, ULONG ulFlags, HANDLE hMachine)
1054*c2c66affSColin Finck {
1055*c2c66affSColin Finck     WCHAR szGuidString[MAX_GUID_STRING_LEN];
1056*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
1057*c2c66affSColin Finck     CONFIGRET ret;
1058*c2c66affSColin Finck 
1059*c2c66affSColin Finck     TRACE("%p %lx %lx\n", ClassGuid, ulFlags, hMachine);
1060*c2c66affSColin Finck 
1061*c2c66affSColin Finck     if (ClassGuid == NULL)
1062*c2c66affSColin Finck         return CR_INVALID_POINTER;
1063*c2c66affSColin Finck 
1064*c2c66affSColin Finck     if (ulFlags & ~CM_DELETE_CLASS_BITS)
1065*c2c66affSColin Finck         return CR_INVALID_FLAG;
1066*c2c66affSColin Finck 
1067*c2c66affSColin Finck     if (!GuidToString(ClassGuid, szGuidString))
1068*c2c66affSColin Finck         return CR_INVALID_DATA;
1069*c2c66affSColin Finck 
1070*c2c66affSColin Finck     if (hMachine != NULL)
1071*c2c66affSColin Finck     {
1072*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1073*c2c66affSColin Finck         if (BindingHandle == NULL)
1074*c2c66affSColin Finck             return CR_FAILURE;
1075*c2c66affSColin Finck     }
1076*c2c66affSColin Finck     else
1077*c2c66affSColin Finck     {
1078*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
1079*c2c66affSColin Finck             return CR_FAILURE;
1080*c2c66affSColin Finck     }
1081*c2c66affSColin Finck 
1082*c2c66affSColin Finck     RpcTryExcept
1083*c2c66affSColin Finck     {
1084*c2c66affSColin Finck         ret = PNP_DeleteClassKey(BindingHandle,
1085*c2c66affSColin Finck                                  szGuidString,
1086*c2c66affSColin Finck                                  ulFlags);
1087*c2c66affSColin Finck     }
1088*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1089*c2c66affSColin Finck     {
1090*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
1091*c2c66affSColin Finck     }
1092*c2c66affSColin Finck     RpcEndExcept;
1093*c2c66affSColin Finck 
1094*c2c66affSColin Finck     return ret;
1095*c2c66affSColin Finck }
1096*c2c66affSColin Finck 
1097*c2c66affSColin Finck 
1098*c2c66affSColin Finck /***********************************************************************
1099*c2c66affSColin Finck  * CM_Delete_DevNode_Key [SETUPAPI.@]
1100*c2c66affSColin Finck  */
1101*c2c66affSColin Finck CONFIGRET WINAPI CM_Delete_DevNode_Key(
1102*c2c66affSColin Finck     DEVNODE dnDevNode, ULONG ulHardwareProfile, ULONG ulFlags)
1103*c2c66affSColin Finck {
1104*c2c66affSColin Finck     TRACE("%p %lu %lx\n", dnDevNode, ulHardwareProfile, ulFlags);
1105*c2c66affSColin Finck     return CM_Delete_DevNode_Key_Ex(dnDevNode, ulHardwareProfile, ulFlags,
1106*c2c66affSColin Finck                                     NULL);
1107*c2c66affSColin Finck }
1108*c2c66affSColin Finck 
1109*c2c66affSColin Finck 
1110*c2c66affSColin Finck /***********************************************************************
1111*c2c66affSColin Finck  * CM_Delete_DevNode_Key_Ex [SETUPAPI.@]
1112*c2c66affSColin Finck  */
1113*c2c66affSColin Finck CONFIGRET WINAPI CM_Delete_DevNode_Key_Ex(
1114*c2c66affSColin Finck     DEVNODE dnDevNode, ULONG ulHardwareProfile, ULONG ulFlags,
1115*c2c66affSColin Finck     HANDLE hMachine)
1116*c2c66affSColin Finck {
1117*c2c66affSColin Finck     FIXME("%p %lu %lx %p\n",
1118*c2c66affSColin Finck           dnDevNode, ulHardwareProfile, ulFlags, hMachine);
1119*c2c66affSColin Finck 
1120*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
1121*c2c66affSColin Finck }
1122*c2c66affSColin Finck 
1123*c2c66affSColin Finck 
1124*c2c66affSColin Finck /***********************************************************************
1125*c2c66affSColin Finck  * CM_Delete_Range [SETUPAPI.@]
1126*c2c66affSColin Finck  */
1127*c2c66affSColin Finck CONFIGRET
1128*c2c66affSColin Finck WINAPI
1129*c2c66affSColin Finck CM_Delete_Range(
1130*c2c66affSColin Finck     _In_ DWORDLONG ullStartValue,
1131*c2c66affSColin Finck     _In_ DWORDLONG ullEndValue,
1132*c2c66affSColin Finck     _In_ RANGE_LIST rlh,
1133*c2c66affSColin Finck     _In_ ULONG ulFlags)
1134*c2c66affSColin Finck {
1135*c2c66affSColin Finck     FIXME("CM_Delete_Range(%I64u %I64u %p %lx)\n",
1136*c2c66affSColin Finck           ullStartValue, ullEndValue, rlh, ulFlags);
1137*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
1138*c2c66affSColin Finck }
1139*c2c66affSColin Finck 
1140*c2c66affSColin Finck 
1141*c2c66affSColin Finck /***********************************************************************
1142*c2c66affSColin Finck  * CM_Disable_DevNode [SETUPAPI.@]
1143*c2c66affSColin Finck  */
1144*c2c66affSColin Finck CONFIGRET WINAPI CM_Disable_DevNode(
1145*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulFlags)
1146*c2c66affSColin Finck {
1147*c2c66affSColin Finck     TRACE("%p %lx\n", dnDevInst, ulFlags);
1148*c2c66affSColin Finck     return CM_Disable_DevNode_Ex(dnDevInst, ulFlags, NULL);
1149*c2c66affSColin Finck }
1150*c2c66affSColin Finck 
1151*c2c66affSColin Finck 
1152*c2c66affSColin Finck /***********************************************************************
1153*c2c66affSColin Finck  * CM_Disable_DevNode_Ex [SETUPAPI.@]
1154*c2c66affSColin Finck  */
1155*c2c66affSColin Finck CONFIGRET WINAPI CM_Disable_DevNode_Ex(
1156*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
1157*c2c66affSColin Finck {
1158*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
1159*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
1160*c2c66affSColin Finck     LPWSTR lpDevInst;
1161*c2c66affSColin Finck     CONFIGRET ret;
1162*c2c66affSColin Finck 
1163*c2c66affSColin Finck     FIXME("%p %lx %p\n", dnDevInst, ulFlags, hMachine);
1164*c2c66affSColin Finck 
1165*c2c66affSColin Finck     if (!pSetupIsUserAdmin())
1166*c2c66affSColin Finck         return CR_ACCESS_DENIED;
1167*c2c66affSColin Finck 
1168*c2c66affSColin Finck     if (dnDevInst == 0)
1169*c2c66affSColin Finck         return CR_INVALID_DEVINST;
1170*c2c66affSColin Finck 
1171*c2c66affSColin Finck     if (ulFlags != 0)
1172*c2c66affSColin Finck         return CR_INVALID_FLAG;
1173*c2c66affSColin Finck 
1174*c2c66affSColin Finck     if (hMachine != NULL)
1175*c2c66affSColin Finck     {
1176*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1177*c2c66affSColin Finck         if (BindingHandle == NULL)
1178*c2c66affSColin Finck             return CR_FAILURE;
1179*c2c66affSColin Finck 
1180*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1181*c2c66affSColin Finck         if (StringTable == 0)
1182*c2c66affSColin Finck             return CR_FAILURE;
1183*c2c66affSColin Finck     }
1184*c2c66affSColin Finck     else
1185*c2c66affSColin Finck     {
1186*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1187*c2c66affSColin Finck             return CR_FAILURE;
1188*c2c66affSColin Finck     }
1189*c2c66affSColin Finck 
1190*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1191*c2c66affSColin Finck     if (lpDevInst == NULL)
1192*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
1193*c2c66affSColin Finck 
1194*c2c66affSColin Finck     RpcTryExcept
1195*c2c66affSColin Finck     {
1196*c2c66affSColin Finck         ret = PNP_DeviceInstanceAction(BindingHandle,
1197*c2c66affSColin Finck                                        PNP_DEVINST_DISABLE,
1198*c2c66affSColin Finck                                        ulFlags,
1199*c2c66affSColin Finck                                        lpDevInst,
1200*c2c66affSColin Finck                                        NULL);
1201*c2c66affSColin Finck     }
1202*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1203*c2c66affSColin Finck     {
1204*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
1205*c2c66affSColin Finck     }
1206*c2c66affSColin Finck     RpcEndExcept;
1207*c2c66affSColin Finck 
1208*c2c66affSColin Finck     return ret;
1209*c2c66affSColin Finck }
1210*c2c66affSColin Finck 
1211*c2c66affSColin Finck 
1212*c2c66affSColin Finck /***********************************************************************
1213*c2c66affSColin Finck  * CM_Disconnect_Machine [SETUPAPI.@]
1214*c2c66affSColin Finck  */
1215*c2c66affSColin Finck CONFIGRET WINAPI CM_Disconnect_Machine(HMACHINE hMachine)
1216*c2c66affSColin Finck {
1217*c2c66affSColin Finck     PMACHINE_INFO pMachine;
1218*c2c66affSColin Finck 
1219*c2c66affSColin Finck     TRACE("%lx\n", hMachine);
1220*c2c66affSColin Finck 
1221*c2c66affSColin Finck     pMachine = (PMACHINE_INFO)hMachine;
1222*c2c66affSColin Finck     if (pMachine == NULL)
1223*c2c66affSColin Finck         return CR_SUCCESS;
1224*c2c66affSColin Finck 
1225*c2c66affSColin Finck     if (pMachine->bLocal == FALSE)
1226*c2c66affSColin Finck     {
1227*c2c66affSColin Finck         if (pMachine->StringTable != NULL)
1228*c2c66affSColin Finck             pSetupStringTableDestroy(pMachine->StringTable);
1229*c2c66affSColin Finck 
1230*c2c66affSColin Finck         if (!PnpUnbindRpc(pMachine->BindingHandle))
1231*c2c66affSColin Finck             return CR_ACCESS_DENIED;
1232*c2c66affSColin Finck     }
1233*c2c66affSColin Finck 
1234*c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, pMachine);
1235*c2c66affSColin Finck 
1236*c2c66affSColin Finck     return CR_SUCCESS;
1237*c2c66affSColin Finck }
1238*c2c66affSColin Finck 
1239*c2c66affSColin Finck 
1240*c2c66affSColin Finck /***********************************************************************
1241*c2c66affSColin Finck  * CM_Dup_Range_List [SETUPAPI.@]
1242*c2c66affSColin Finck  */
1243*c2c66affSColin Finck CONFIGRET
1244*c2c66affSColin Finck WINAPI
1245*c2c66affSColin Finck CM_Dup_Range_List(
1246*c2c66affSColin Finck     _In_ RANGE_LIST rlhOld,
1247*c2c66affSColin Finck     _In_ RANGE_LIST rlhNew,
1248*c2c66affSColin Finck     _In_ ULONG ulFlags)
1249*c2c66affSColin Finck {
1250*c2c66affSColin Finck     FIXME("CM_Dup_Range_List(%p %p %lx)\n",
1251*c2c66affSColin Finck           rlhOld, rlhNew, ulFlags);
1252*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
1253*c2c66affSColin Finck }
1254*c2c66affSColin Finck 
1255*c2c66affSColin Finck 
1256*c2c66affSColin Finck /***********************************************************************
1257*c2c66affSColin Finck  * CM_Enable_DevNode [SETUPAPI.@]
1258*c2c66affSColin Finck  */
1259*c2c66affSColin Finck CONFIGRET WINAPI CM_Enable_DevNode(
1260*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulFlags)
1261*c2c66affSColin Finck {
1262*c2c66affSColin Finck     TRACE("%p %lx\n", dnDevInst, ulFlags);
1263*c2c66affSColin Finck     return CM_Enable_DevNode_Ex(dnDevInst, ulFlags, NULL);
1264*c2c66affSColin Finck }
1265*c2c66affSColin Finck 
1266*c2c66affSColin Finck 
1267*c2c66affSColin Finck /***********************************************************************
1268*c2c66affSColin Finck  * CM_Enable_DevNode_Ex [SETUPAPI.@]
1269*c2c66affSColin Finck  */
1270*c2c66affSColin Finck CONFIGRET WINAPI CM_Enable_DevNode_Ex(
1271*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
1272*c2c66affSColin Finck {
1273*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
1274*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
1275*c2c66affSColin Finck     LPWSTR lpDevInst;
1276*c2c66affSColin Finck     CONFIGRET ret;
1277*c2c66affSColin Finck 
1278*c2c66affSColin Finck     TRACE("%p %lx %p\n", dnDevInst, ulFlags, hMachine);
1279*c2c66affSColin Finck 
1280*c2c66affSColin Finck     if (!pSetupIsUserAdmin())
1281*c2c66affSColin Finck         return CR_ACCESS_DENIED;
1282*c2c66affSColin Finck 
1283*c2c66affSColin Finck     if (dnDevInst == 0)
1284*c2c66affSColin Finck         return CR_INVALID_DEVINST;
1285*c2c66affSColin Finck 
1286*c2c66affSColin Finck     if (ulFlags != 0)
1287*c2c66affSColin Finck         return CR_INVALID_FLAG;
1288*c2c66affSColin Finck 
1289*c2c66affSColin Finck     if (hMachine != NULL)
1290*c2c66affSColin Finck     {
1291*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1292*c2c66affSColin Finck         if (BindingHandle == NULL)
1293*c2c66affSColin Finck             return CR_FAILURE;
1294*c2c66affSColin Finck 
1295*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1296*c2c66affSColin Finck         if (StringTable == 0)
1297*c2c66affSColin Finck             return CR_FAILURE;
1298*c2c66affSColin Finck     }
1299*c2c66affSColin Finck     else
1300*c2c66affSColin Finck     {
1301*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1302*c2c66affSColin Finck             return CR_FAILURE;
1303*c2c66affSColin Finck     }
1304*c2c66affSColin Finck 
1305*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1306*c2c66affSColin Finck     if (lpDevInst == NULL)
1307*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
1308*c2c66affSColin Finck 
1309*c2c66affSColin Finck     RpcTryExcept
1310*c2c66affSColin Finck     {
1311*c2c66affSColin Finck         ret = PNP_DeviceInstanceAction(BindingHandle,
1312*c2c66affSColin Finck                                        PNP_DEVINST_ENABLE,
1313*c2c66affSColin Finck                                        ulFlags,
1314*c2c66affSColin Finck                                        lpDevInst,
1315*c2c66affSColin Finck                                        NULL);
1316*c2c66affSColin Finck     }
1317*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1318*c2c66affSColin Finck     {
1319*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
1320*c2c66affSColin Finck     }
1321*c2c66affSColin Finck     RpcEndExcept;
1322*c2c66affSColin Finck 
1323*c2c66affSColin Finck     return ret;
1324*c2c66affSColin Finck }
1325*c2c66affSColin Finck 
1326*c2c66affSColin Finck 
1327*c2c66affSColin Finck /***********************************************************************
1328*c2c66affSColin Finck  * CM_Enumerate_Classes [SETUPAPI.@]
1329*c2c66affSColin Finck  */
1330*c2c66affSColin Finck CONFIGRET WINAPI CM_Enumerate_Classes(
1331*c2c66affSColin Finck     ULONG ulClassIndex, LPGUID ClassGuid, ULONG ulFlags)
1332*c2c66affSColin Finck {
1333*c2c66affSColin Finck     TRACE("%lx %p %lx\n", ulClassIndex, ClassGuid, ulFlags);
1334*c2c66affSColin Finck     return CM_Enumerate_Classes_Ex(ulClassIndex, ClassGuid, ulFlags, NULL);
1335*c2c66affSColin Finck }
1336*c2c66affSColin Finck 
1337*c2c66affSColin Finck 
1338*c2c66affSColin Finck /***********************************************************************
1339*c2c66affSColin Finck  * CM_Enumerate_Classes_Ex [SETUPAPI.@]
1340*c2c66affSColin Finck  */
1341*c2c66affSColin Finck CONFIGRET WINAPI CM_Enumerate_Classes_Ex(
1342*c2c66affSColin Finck     ULONG ulClassIndex, LPGUID ClassGuid, ULONG ulFlags, HMACHINE hMachine)
1343*c2c66affSColin Finck {
1344*c2c66affSColin Finck     WCHAR szBuffer[MAX_GUID_STRING_LEN];
1345*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
1346*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
1347*c2c66affSColin Finck     ULONG ulLength = MAX_GUID_STRING_LEN;
1348*c2c66affSColin Finck 
1349*c2c66affSColin Finck     TRACE("%lx %p %lx %p\n", ulClassIndex, ClassGuid, ulFlags, hMachine);
1350*c2c66affSColin Finck 
1351*c2c66affSColin Finck     if (ClassGuid == NULL)
1352*c2c66affSColin Finck         return CR_INVALID_POINTER;
1353*c2c66affSColin Finck 
1354*c2c66affSColin Finck     if (ulFlags != 0)
1355*c2c66affSColin Finck         return CR_INVALID_FLAG;
1356*c2c66affSColin Finck 
1357*c2c66affSColin Finck     if (hMachine != NULL)
1358*c2c66affSColin Finck     {
1359*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1360*c2c66affSColin Finck         if (BindingHandle == NULL)
1361*c2c66affSColin Finck             return CR_FAILURE;
1362*c2c66affSColin Finck     }
1363*c2c66affSColin Finck     else
1364*c2c66affSColin Finck     {
1365*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
1366*c2c66affSColin Finck             return CR_FAILURE;
1367*c2c66affSColin Finck     }
1368*c2c66affSColin Finck 
1369*c2c66affSColin Finck     RpcTryExcept
1370*c2c66affSColin Finck     {
1371*c2c66affSColin Finck         ret = PNP_EnumerateSubKeys(BindingHandle,
1372*c2c66affSColin Finck                                    PNP_CLASS_SUBKEYS,
1373*c2c66affSColin Finck                                    ulClassIndex,
1374*c2c66affSColin Finck                                    szBuffer,
1375*c2c66affSColin Finck                                    MAX_GUID_STRING_LEN,
1376*c2c66affSColin Finck                                    &ulLength,
1377*c2c66affSColin Finck                                    ulFlags);
1378*c2c66affSColin Finck     }
1379*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1380*c2c66affSColin Finck     {
1381*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
1382*c2c66affSColin Finck     }
1383*c2c66affSColin Finck     RpcEndExcept;
1384*c2c66affSColin Finck 
1385*c2c66affSColin Finck     if (ret == CR_SUCCESS)
1386*c2c66affSColin Finck     {
1387*c2c66affSColin Finck         /* Remove the {} */
1388*c2c66affSColin Finck         szBuffer[MAX_GUID_STRING_LEN - 2] = UNICODE_NULL;
1389*c2c66affSColin Finck 
1390*c2c66affSColin Finck         /* Convert the buffer to a GUID */
1391*c2c66affSColin Finck         if (UuidFromStringW(&szBuffer[1], ClassGuid) != RPC_S_OK)
1392*c2c66affSColin Finck             return CR_FAILURE;
1393*c2c66affSColin Finck     }
1394*c2c66affSColin Finck 
1395*c2c66affSColin Finck     return ret;
1396*c2c66affSColin Finck }
1397*c2c66affSColin Finck 
1398*c2c66affSColin Finck 
1399*c2c66affSColin Finck /***********************************************************************
1400*c2c66affSColin Finck  * CM_Enumerate_EnumeratorsA [SETUPAPI.@]
1401*c2c66affSColin Finck  */
1402*c2c66affSColin Finck CONFIGRET WINAPI CM_Enumerate_EnumeratorsA(
1403*c2c66affSColin Finck     ULONG ulEnumIndex, PCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1404*c2c66affSColin Finck {
1405*c2c66affSColin Finck     TRACE("%lu %p %p %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags);
1406*c2c66affSColin Finck     return CM_Enumerate_Enumerators_ExA(ulEnumIndex, Buffer, pulLength,
1407*c2c66affSColin Finck                                         ulFlags, NULL);
1408*c2c66affSColin Finck }
1409*c2c66affSColin Finck 
1410*c2c66affSColin Finck 
1411*c2c66affSColin Finck /***********************************************************************
1412*c2c66affSColin Finck  * CM_Enumerate_EnumeratorsW [SETUPAPI.@]
1413*c2c66affSColin Finck  */
1414*c2c66affSColin Finck CONFIGRET WINAPI CM_Enumerate_EnumeratorsW(
1415*c2c66affSColin Finck     ULONG ulEnumIndex, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1416*c2c66affSColin Finck {
1417*c2c66affSColin Finck     TRACE("%lu %p %p %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags);
1418*c2c66affSColin Finck     return CM_Enumerate_Enumerators_ExW(ulEnumIndex, Buffer, pulLength,
1419*c2c66affSColin Finck                                         ulFlags, NULL);
1420*c2c66affSColin Finck }
1421*c2c66affSColin Finck 
1422*c2c66affSColin Finck 
1423*c2c66affSColin Finck /***********************************************************************
1424*c2c66affSColin Finck  * CM_Enumerate_Enumerators_ExA [SETUPAPI.@]
1425*c2c66affSColin Finck  */
1426*c2c66affSColin Finck CONFIGRET WINAPI CM_Enumerate_Enumerators_ExA(
1427*c2c66affSColin Finck     ULONG ulEnumIndex, PCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1428*c2c66affSColin Finck     HMACHINE hMachine)
1429*c2c66affSColin Finck {
1430*c2c66affSColin Finck     WCHAR szBuffer[MAX_DEVICE_ID_LEN];
1431*c2c66affSColin Finck     ULONG ulOrigLength;
1432*c2c66affSColin Finck     ULONG ulLength;
1433*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
1434*c2c66affSColin Finck 
1435*c2c66affSColin Finck     TRACE("%lu %p %p %lx %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags,
1436*c2c66affSColin Finck           hMachine);
1437*c2c66affSColin Finck 
1438*c2c66affSColin Finck     if (Buffer == NULL || pulLength == NULL)
1439*c2c66affSColin Finck         return CR_INVALID_POINTER;
1440*c2c66affSColin Finck 
1441*c2c66affSColin Finck     if (ulFlags != 0)
1442*c2c66affSColin Finck         return CR_INVALID_FLAG;
1443*c2c66affSColin Finck 
1444*c2c66affSColin Finck     ulOrigLength = *pulLength;
1445*c2c66affSColin Finck     *pulLength = 0;
1446*c2c66affSColin Finck 
1447*c2c66affSColin Finck     ulLength = MAX_DEVICE_ID_LEN;
1448*c2c66affSColin Finck     ret = CM_Enumerate_Enumerators_ExW(ulEnumIndex, szBuffer, &ulLength,
1449*c2c66affSColin Finck                                        ulFlags, hMachine);
1450*c2c66affSColin Finck     if (ret == CR_SUCCESS)
1451*c2c66affSColin Finck     {
1452*c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
1453*c2c66affSColin Finck                                 0,
1454*c2c66affSColin Finck                                 szBuffer,
1455*c2c66affSColin Finck                                 ulLength,
1456*c2c66affSColin Finck                                 Buffer,
1457*c2c66affSColin Finck                                 ulOrigLength,
1458*c2c66affSColin Finck                                 NULL,
1459*c2c66affSColin Finck                                 NULL) == 0)
1460*c2c66affSColin Finck             ret = CR_FAILURE;
1461*c2c66affSColin Finck         else
1462*c2c66affSColin Finck             *pulLength = lstrlenA(Buffer) + 1;
1463*c2c66affSColin Finck     }
1464*c2c66affSColin Finck 
1465*c2c66affSColin Finck     return ret;
1466*c2c66affSColin Finck }
1467*c2c66affSColin Finck 
1468*c2c66affSColin Finck 
1469*c2c66affSColin Finck /***********************************************************************
1470*c2c66affSColin Finck  * CM_Enumerate_Enumerators_ExW [SETUPAPI.@]
1471*c2c66affSColin Finck  */
1472*c2c66affSColin Finck CONFIGRET WINAPI CM_Enumerate_Enumerators_ExW(
1473*c2c66affSColin Finck     ULONG ulEnumIndex, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1474*c2c66affSColin Finck     HMACHINE hMachine)
1475*c2c66affSColin Finck {
1476*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
1477*c2c66affSColin Finck     CONFIGRET ret;
1478*c2c66affSColin Finck 
1479*c2c66affSColin Finck     TRACE("%lu %p %p %lx %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags,
1480*c2c66affSColin Finck           hMachine);
1481*c2c66affSColin Finck 
1482*c2c66affSColin Finck     if (Buffer == NULL || pulLength == NULL)
1483*c2c66affSColin Finck         return CR_INVALID_POINTER;
1484*c2c66affSColin Finck 
1485*c2c66affSColin Finck     if (ulFlags != 0)
1486*c2c66affSColin Finck         return CR_INVALID_FLAG;
1487*c2c66affSColin Finck 
1488*c2c66affSColin Finck     *Buffer = UNICODE_NULL;
1489*c2c66affSColin Finck 
1490*c2c66affSColin Finck     if (hMachine != NULL)
1491*c2c66affSColin Finck     {
1492*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1493*c2c66affSColin Finck         if (BindingHandle == NULL)
1494*c2c66affSColin Finck             return CR_FAILURE;
1495*c2c66affSColin Finck     }
1496*c2c66affSColin Finck     else
1497*c2c66affSColin Finck     {
1498*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
1499*c2c66affSColin Finck             return CR_FAILURE;
1500*c2c66affSColin Finck     }
1501*c2c66affSColin Finck 
1502*c2c66affSColin Finck     RpcTryExcept
1503*c2c66affSColin Finck     {
1504*c2c66affSColin Finck         ret = PNP_EnumerateSubKeys(BindingHandle,
1505*c2c66affSColin Finck                                    PNP_ENUMERATOR_SUBKEYS,
1506*c2c66affSColin Finck                                    ulEnumIndex,
1507*c2c66affSColin Finck                                    Buffer,
1508*c2c66affSColin Finck                                    *pulLength,
1509*c2c66affSColin Finck                                    pulLength,
1510*c2c66affSColin Finck                                    ulFlags);
1511*c2c66affSColin Finck     }
1512*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1513*c2c66affSColin Finck     {
1514*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
1515*c2c66affSColin Finck     }
1516*c2c66affSColin Finck     RpcEndExcept;
1517*c2c66affSColin Finck 
1518*c2c66affSColin Finck     return ret;
1519*c2c66affSColin Finck }
1520*c2c66affSColin Finck 
1521*c2c66affSColin Finck 
1522*c2c66affSColin Finck /***********************************************************************
1523*c2c66affSColin Finck  * CM_Find_Range [SETUPAPI.@]
1524*c2c66affSColin Finck  */
1525*c2c66affSColin Finck CONFIGRET
1526*c2c66affSColin Finck WINAPI
1527*c2c66affSColin Finck CM_Find_Range(
1528*c2c66affSColin Finck     _Out_ PDWORDLONG pullStart,
1529*c2c66affSColin Finck     _In_ DWORDLONG ullStart,
1530*c2c66affSColin Finck     _In_ ULONG ulLength,
1531*c2c66affSColin Finck     _In_ DWORDLONG ullAlignment,
1532*c2c66affSColin Finck     _In_ DWORDLONG ullEnd,
1533*c2c66affSColin Finck     _In_ RANGE_LIST rlh,
1534*c2c66affSColin Finck     _In_ ULONG ulFlags)
1535*c2c66affSColin Finck {
1536*c2c66affSColin Finck     FIXME("CM_Find_Range(%p %I64u %lu %I64u %I64u %p %lx)\n",
1537*c2c66affSColin Finck           pullStart, ullStart, ulLength, ullAlignment, ullEnd, rlh, ulFlags);
1538*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
1539*c2c66affSColin Finck }
1540*c2c66affSColin Finck 
1541*c2c66affSColin Finck 
1542*c2c66affSColin Finck /***********************************************************************
1543*c2c66affSColin Finck  * CM_First_Range [SETUPAPI.@]
1544*c2c66affSColin Finck  */
1545*c2c66affSColin Finck CONFIGRET
1546*c2c66affSColin Finck WINAPI
1547*c2c66affSColin Finck CM_First_Range(
1548*c2c66affSColin Finck     _In_ RANGE_LIST rlh,
1549*c2c66affSColin Finck     _Out_ PDWORDLONG pullStart,
1550*c2c66affSColin Finck     _Out_ PDWORDLONG pullEnd,
1551*c2c66affSColin Finck     _Out_ PRANGE_ELEMENT preElement,
1552*c2c66affSColin Finck     _In_ ULONG ulFlags)
1553*c2c66affSColin Finck {
1554*c2c66affSColin Finck     FIXME("CM_First_Range(%p %p %p %p %lx)\n",
1555*c2c66affSColin Finck           rlh, pullStart, pullEnd, preElement, ulFlags);
1556*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
1557*c2c66affSColin Finck }
1558*c2c66affSColin Finck 
1559*c2c66affSColin Finck 
1560*c2c66affSColin Finck /***********************************************************************
1561*c2c66affSColin Finck  * CM_Free_Log_Conf [SETUPAPI.@]
1562*c2c66affSColin Finck  */
1563*c2c66affSColin Finck CONFIGRET WINAPI CM_Free_Log_Conf(
1564*c2c66affSColin Finck     LOG_CONF lcLogConfToBeFreed, ULONG ulFlags)
1565*c2c66affSColin Finck {
1566*c2c66affSColin Finck     TRACE("%lx %lx\n", lcLogConfToBeFreed, ulFlags);
1567*c2c66affSColin Finck     return CM_Free_Log_Conf_Ex(lcLogConfToBeFreed, ulFlags, NULL);
1568*c2c66affSColin Finck }
1569*c2c66affSColin Finck 
1570*c2c66affSColin Finck 
1571*c2c66affSColin Finck /***********************************************************************
1572*c2c66affSColin Finck  * CM_Free_Log_Conf_Ex [SETUPAPI.@]
1573*c2c66affSColin Finck  */
1574*c2c66affSColin Finck CONFIGRET WINAPI CM_Free_Log_Conf_Ex(
1575*c2c66affSColin Finck     LOG_CONF lcLogConfToBeFreed, ULONG ulFlags, HMACHINE hMachine)
1576*c2c66affSColin Finck {
1577*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
1578*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
1579*c2c66affSColin Finck     LPWSTR lpDevInst;
1580*c2c66affSColin Finck     PLOG_CONF_INFO pLogConfInfo;
1581*c2c66affSColin Finck     CONFIGRET ret;
1582*c2c66affSColin Finck 
1583*c2c66affSColin Finck     TRACE("%lx %lx %lx\n", lcLogConfToBeFreed, ulFlags, hMachine);
1584*c2c66affSColin Finck 
1585*c2c66affSColin Finck     if (!pSetupIsUserAdmin())
1586*c2c66affSColin Finck         return CR_ACCESS_DENIED;
1587*c2c66affSColin Finck 
1588*c2c66affSColin Finck     pLogConfInfo = (PLOG_CONF_INFO)lcLogConfToBeFreed;
1589*c2c66affSColin Finck     if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
1590*c2c66affSColin Finck         return CR_INVALID_LOG_CONF;
1591*c2c66affSColin Finck 
1592*c2c66affSColin Finck     if (ulFlags != 0)
1593*c2c66affSColin Finck         return CR_INVALID_FLAG;
1594*c2c66affSColin Finck 
1595*c2c66affSColin Finck     if (hMachine != NULL)
1596*c2c66affSColin Finck     {
1597*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1598*c2c66affSColin Finck         if (BindingHandle == NULL)
1599*c2c66affSColin Finck             return CR_FAILURE;
1600*c2c66affSColin Finck 
1601*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1602*c2c66affSColin Finck         if (StringTable == 0)
1603*c2c66affSColin Finck             return CR_FAILURE;
1604*c2c66affSColin Finck     }
1605*c2c66affSColin Finck     else
1606*c2c66affSColin Finck     {
1607*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1608*c2c66affSColin Finck             return CR_FAILURE;
1609*c2c66affSColin Finck     }
1610*c2c66affSColin Finck 
1611*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
1612*c2c66affSColin Finck     if (lpDevInst == NULL)
1613*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
1614*c2c66affSColin Finck 
1615*c2c66affSColin Finck     RpcTryExcept
1616*c2c66affSColin Finck     {
1617*c2c66affSColin Finck         ret = PNP_FreeLogConf(BindingHandle, lpDevInst, pLogConfInfo->ulFlags,
1618*c2c66affSColin Finck                               pLogConfInfo->ulTag, 0);
1619*c2c66affSColin Finck     }
1620*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1621*c2c66affSColin Finck     {
1622*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
1623*c2c66affSColin Finck     }
1624*c2c66affSColin Finck     RpcEndExcept;
1625*c2c66affSColin Finck 
1626*c2c66affSColin Finck     return ret;
1627*c2c66affSColin Finck }
1628*c2c66affSColin Finck 
1629*c2c66affSColin Finck 
1630*c2c66affSColin Finck /***********************************************************************
1631*c2c66affSColin Finck  * CM_Free_Log_Conf_Handle [SETUPAPI.@]
1632*c2c66affSColin Finck  */
1633*c2c66affSColin Finck CONFIGRET WINAPI CM_Free_Log_Conf_Handle(
1634*c2c66affSColin Finck     LOG_CONF lcLogConf)
1635*c2c66affSColin Finck {
1636*c2c66affSColin Finck     PLOG_CONF_INFO pLogConfInfo;
1637*c2c66affSColin Finck 
1638*c2c66affSColin Finck     TRACE("%lx\n", lcLogConf);
1639*c2c66affSColin Finck 
1640*c2c66affSColin Finck     pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
1641*c2c66affSColin Finck     if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
1642*c2c66affSColin Finck         return CR_INVALID_LOG_CONF;
1643*c2c66affSColin Finck 
1644*c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, pLogConfInfo);
1645*c2c66affSColin Finck 
1646*c2c66affSColin Finck     return CR_SUCCESS;
1647*c2c66affSColin Finck }
1648*c2c66affSColin Finck 
1649*c2c66affSColin Finck 
1650*c2c66affSColin Finck /***********************************************************************
1651*c2c66affSColin Finck  * CM_Free_Range_List [SETUPAPI.@]
1652*c2c66affSColin Finck  */
1653*c2c66affSColin Finck CONFIGRET
1654*c2c66affSColin Finck WINAPI
1655*c2c66affSColin Finck CM_Free_Range_List(
1656*c2c66affSColin Finck     _In_ RANGE_LIST RangeList,
1657*c2c66affSColin Finck     _In_ ULONG ulFlags)
1658*c2c66affSColin Finck {
1659*c2c66affSColin Finck     PINTERNAL_RANGE_LIST pRangeList;
1660*c2c66affSColin Finck 
1661*c2c66affSColin Finck     FIXME("CM_Free_Range_List(%p %lx)\n", RangeList, ulFlags);
1662*c2c66affSColin Finck 
1663*c2c66affSColin Finck     pRangeList = (PINTERNAL_RANGE_LIST)RangeList;
1664*c2c66affSColin Finck 
1665*c2c66affSColin Finck     if (pRangeList == NULL || pRangeList->ulMagic != RANGE_LIST_MAGIC)
1666*c2c66affSColin Finck         return CR_INVALID_RANGE_LIST;
1667*c2c66affSColin Finck 
1668*c2c66affSColin Finck     if (ulFlags != 0)
1669*c2c66affSColin Finck         return CR_INVALID_FLAG;
1670*c2c66affSColin Finck 
1671*c2c66affSColin Finck     // TODO: Free the list of ranges
1672*c2c66affSColin Finck 
1673*c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, pRangeList);
1674*c2c66affSColin Finck 
1675*c2c66affSColin Finck     return CR_SUCCESS;
1676*c2c66affSColin Finck }
1677*c2c66affSColin Finck 
1678*c2c66affSColin Finck 
1679*c2c66affSColin Finck /***********************************************************************
1680*c2c66affSColin Finck  * CM_Free_Res_Des [SETUPAPI.@]
1681*c2c66affSColin Finck  */
1682*c2c66affSColin Finck CONFIGRET WINAPI CM_Free_Res_Des(
1683*c2c66affSColin Finck    PRES_DES prdResDes, RES_DES rdResDes, ULONG ulFlags)
1684*c2c66affSColin Finck {
1685*c2c66affSColin Finck     TRACE("%p %p %lx\n", prdResDes, rdResDes, ulFlags);
1686*c2c66affSColin Finck     return CM_Free_Res_Des_Ex(prdResDes, rdResDes, ulFlags, NULL);
1687*c2c66affSColin Finck }
1688*c2c66affSColin Finck 
1689*c2c66affSColin Finck 
1690*c2c66affSColin Finck /***********************************************************************
1691*c2c66affSColin Finck  * CM_Free_Res_Des_Ex [SETUPAPI.@]
1692*c2c66affSColin Finck  */
1693*c2c66affSColin Finck CONFIGRET WINAPI CM_Free_Res_Des_Ex(
1694*c2c66affSColin Finck     PRES_DES prdResDes, RES_DES rdResDes, ULONG ulFlags,
1695*c2c66affSColin Finck     HMACHINE hMachine)
1696*c2c66affSColin Finck {
1697*c2c66affSColin Finck     FIXME("%p %p %lx %lx\n", prdResDes, rdResDes, ulFlags, hMachine);
1698*c2c66affSColin Finck 
1699*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
1700*c2c66affSColin Finck }
1701*c2c66affSColin Finck 
1702*c2c66affSColin Finck 
1703*c2c66affSColin Finck /***********************************************************************
1704*c2c66affSColin Finck  * CM_Free_Res_Des_Handle [SETUPAPI.@]
1705*c2c66affSColin Finck  */
1706*c2c66affSColin Finck CONFIGRET WINAPI CM_Free_Res_Des_Handle(
1707*c2c66affSColin Finck     RES_DES rdResDes)
1708*c2c66affSColin Finck {
1709*c2c66affSColin Finck     FIXME("%p\n", rdResDes);
1710*c2c66affSColin Finck 
1711*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
1712*c2c66affSColin Finck }
1713*c2c66affSColin Finck 
1714*c2c66affSColin Finck 
1715*c2c66affSColin Finck /***********************************************************************
1716*c2c66affSColin Finck  * CM_Get_Child [SETUPAPI.@]
1717*c2c66affSColin Finck  */
1718*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Child(
1719*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags)
1720*c2c66affSColin Finck {
1721*c2c66affSColin Finck     TRACE("%p %p %lx\n", pdnDevInst, dnDevInst, ulFlags);
1722*c2c66affSColin Finck     return CM_Get_Child_Ex(pdnDevInst, dnDevInst, ulFlags, NULL);
1723*c2c66affSColin Finck }
1724*c2c66affSColin Finck 
1725*c2c66affSColin Finck 
1726*c2c66affSColin Finck /***********************************************************************
1727*c2c66affSColin Finck  * CM_Get_Child_Ex [SETUPAPI.@]
1728*c2c66affSColin Finck  */
1729*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Child_Ex(
1730*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
1731*c2c66affSColin Finck {
1732*c2c66affSColin Finck     WCHAR szRelatedDevInst[MAX_DEVICE_ID_LEN];
1733*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
1734*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
1735*c2c66affSColin Finck     LPWSTR lpDevInst;
1736*c2c66affSColin Finck     DWORD dwIndex, dwLength = MAX_DEVICE_ID_LEN;
1737*c2c66affSColin Finck     CONFIGRET ret;
1738*c2c66affSColin Finck 
1739*c2c66affSColin Finck     TRACE("%p %lx %lx %lx\n", pdnDevInst, dnDevInst, ulFlags, hMachine);
1740*c2c66affSColin Finck 
1741*c2c66affSColin Finck     if (pdnDevInst == NULL)
1742*c2c66affSColin Finck         return CR_INVALID_POINTER;
1743*c2c66affSColin Finck 
1744*c2c66affSColin Finck     if (dnDevInst == 0)
1745*c2c66affSColin Finck         return CR_INVALID_DEVINST;
1746*c2c66affSColin Finck 
1747*c2c66affSColin Finck     if (ulFlags != 0)
1748*c2c66affSColin Finck         return CR_INVALID_FLAG;
1749*c2c66affSColin Finck 
1750*c2c66affSColin Finck     *pdnDevInst = -1;
1751*c2c66affSColin Finck 
1752*c2c66affSColin Finck     if (hMachine != NULL)
1753*c2c66affSColin Finck     {
1754*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1755*c2c66affSColin Finck         if (BindingHandle == NULL)
1756*c2c66affSColin Finck             return CR_FAILURE;
1757*c2c66affSColin Finck 
1758*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1759*c2c66affSColin Finck         if (StringTable == 0)
1760*c2c66affSColin Finck             return CR_FAILURE;
1761*c2c66affSColin Finck     }
1762*c2c66affSColin Finck     else
1763*c2c66affSColin Finck     {
1764*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1765*c2c66affSColin Finck             return CR_FAILURE;
1766*c2c66affSColin Finck     }
1767*c2c66affSColin Finck 
1768*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1769*c2c66affSColin Finck     if (lpDevInst == NULL)
1770*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
1771*c2c66affSColin Finck 
1772*c2c66affSColin Finck     RpcTryExcept
1773*c2c66affSColin Finck     {
1774*c2c66affSColin Finck         ret = PNP_GetRelatedDeviceInstance(BindingHandle,
1775*c2c66affSColin Finck                                            PNP_GET_CHILD_DEVICE_INSTANCE,
1776*c2c66affSColin Finck                                            lpDevInst,
1777*c2c66affSColin Finck                                            szRelatedDevInst,
1778*c2c66affSColin Finck                                            &dwLength,
1779*c2c66affSColin Finck                                            0);
1780*c2c66affSColin Finck     }
1781*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1782*c2c66affSColin Finck     {
1783*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
1784*c2c66affSColin Finck     }
1785*c2c66affSColin Finck     RpcEndExcept;
1786*c2c66affSColin Finck 
1787*c2c66affSColin Finck     if (ret != CR_SUCCESS)
1788*c2c66affSColin Finck         return ret;
1789*c2c66affSColin Finck 
1790*c2c66affSColin Finck     TRACE("szRelatedDevInst: %s\n", debugstr_w(szRelatedDevInst));
1791*c2c66affSColin Finck 
1792*c2c66affSColin Finck     dwIndex = pSetupStringTableAddString(StringTable, szRelatedDevInst, 1);
1793*c2c66affSColin Finck     if (dwIndex == -1)
1794*c2c66affSColin Finck         return CR_FAILURE;
1795*c2c66affSColin Finck 
1796*c2c66affSColin Finck     *pdnDevInst = dwIndex;
1797*c2c66affSColin Finck 
1798*c2c66affSColin Finck     return CR_SUCCESS;
1799*c2c66affSColin Finck }
1800*c2c66affSColin Finck 
1801*c2c66affSColin Finck 
1802*c2c66affSColin Finck /***********************************************************************
1803*c2c66affSColin Finck  * CM_Get_Class_Key_NameA [SETUPAPI.@]
1804*c2c66affSColin Finck  */
1805*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Class_Key_NameA(
1806*c2c66affSColin Finck     LPGUID ClassGuid, LPSTR pszKeyName, PULONG pulLength, ULONG ulFlags)
1807*c2c66affSColin Finck {
1808*c2c66affSColin Finck     TRACE("%p %p %p %lx\n",
1809*c2c66affSColin Finck           ClassGuid, pszKeyName, pulLength, ulFlags);
1810*c2c66affSColin Finck     return CM_Get_Class_Key_Name_ExA(ClassGuid, pszKeyName, pulLength,
1811*c2c66affSColin Finck                                      ulFlags, NULL);
1812*c2c66affSColin Finck }
1813*c2c66affSColin Finck 
1814*c2c66affSColin Finck 
1815*c2c66affSColin Finck /***********************************************************************
1816*c2c66affSColin Finck  * CM_Get_Class_Key_NameW [SETUPAPI.@]
1817*c2c66affSColin Finck  */
1818*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Class_Key_NameW(
1819*c2c66affSColin Finck     LPGUID ClassGuid, LPWSTR pszKeyName, PULONG pulLength, ULONG ulFlags)
1820*c2c66affSColin Finck {
1821*c2c66affSColin Finck     TRACE("%p %p %p %lx\n",
1822*c2c66affSColin Finck           ClassGuid, pszKeyName, pulLength, ulFlags);
1823*c2c66affSColin Finck     return CM_Get_Class_Key_Name_ExW(ClassGuid, pszKeyName, pulLength,
1824*c2c66affSColin Finck                                      ulFlags, NULL);
1825*c2c66affSColin Finck }
1826*c2c66affSColin Finck 
1827*c2c66affSColin Finck 
1828*c2c66affSColin Finck /***********************************************************************
1829*c2c66affSColin Finck  * CM_Get_Class_Key_Name_ExA [SETUPAPI.@]
1830*c2c66affSColin Finck  */
1831*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Class_Key_Name_ExA(
1832*c2c66affSColin Finck     LPGUID ClassGuid, LPSTR pszKeyName, PULONG pulLength, ULONG ulFlags,
1833*c2c66affSColin Finck     HMACHINE hMachine)
1834*c2c66affSColin Finck {
1835*c2c66affSColin Finck     WCHAR szBuffer[MAX_GUID_STRING_LEN];
1836*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
1837*c2c66affSColin Finck     ULONG ulLength;
1838*c2c66affSColin Finck     ULONG ulOrigLength;
1839*c2c66affSColin Finck 
1840*c2c66affSColin Finck     TRACE("%p %p %p %lx %lx\n",
1841*c2c66affSColin Finck           ClassGuid, pszKeyName, pulLength, ulFlags, hMachine);
1842*c2c66affSColin Finck 
1843*c2c66affSColin Finck     if (ClassGuid == NULL || pszKeyName == NULL || pulLength == NULL)
1844*c2c66affSColin Finck         return CR_INVALID_POINTER;
1845*c2c66affSColin Finck 
1846*c2c66affSColin Finck     ulOrigLength = *pulLength;
1847*c2c66affSColin Finck     *pulLength = 0;
1848*c2c66affSColin Finck 
1849*c2c66affSColin Finck     ulLength = MAX_GUID_STRING_LEN;
1850*c2c66affSColin Finck     ret = CM_Get_Class_Key_Name_ExW(ClassGuid, szBuffer, &ulLength,
1851*c2c66affSColin Finck                                     ulFlags, hMachine);
1852*c2c66affSColin Finck     if (ret == CR_SUCCESS)
1853*c2c66affSColin Finck     {
1854*c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
1855*c2c66affSColin Finck                                 0,
1856*c2c66affSColin Finck                                 szBuffer,
1857*c2c66affSColin Finck                                 ulLength,
1858*c2c66affSColin Finck                                 pszKeyName,
1859*c2c66affSColin Finck                                 ulOrigLength,
1860*c2c66affSColin Finck                                 NULL,
1861*c2c66affSColin Finck                                 NULL) == 0)
1862*c2c66affSColin Finck             ret = CR_FAILURE;
1863*c2c66affSColin Finck         else
1864*c2c66affSColin Finck             *pulLength = lstrlenA(pszKeyName) + 1;
1865*c2c66affSColin Finck     }
1866*c2c66affSColin Finck 
1867*c2c66affSColin Finck     return CR_SUCCESS;
1868*c2c66affSColin Finck }
1869*c2c66affSColin Finck 
1870*c2c66affSColin Finck 
1871*c2c66affSColin Finck /***********************************************************************
1872*c2c66affSColin Finck  * CM_Get_Class_Key_Name_ExW [SETUPAPI.@]
1873*c2c66affSColin Finck  */
1874*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Class_Key_Name_ExW(
1875*c2c66affSColin Finck     LPGUID ClassGuid, LPWSTR pszKeyName, PULONG pulLength, ULONG ulFlags,
1876*c2c66affSColin Finck     HMACHINE hMachine)
1877*c2c66affSColin Finck {
1878*c2c66affSColin Finck     TRACE("%p %p %p %lx %lx\n",
1879*c2c66affSColin Finck           ClassGuid, pszKeyName, pulLength, ulFlags, hMachine);
1880*c2c66affSColin Finck 
1881*c2c66affSColin Finck     if (ClassGuid == NULL || pszKeyName == NULL || pulLength == NULL)
1882*c2c66affSColin Finck         return CR_INVALID_POINTER;
1883*c2c66affSColin Finck 
1884*c2c66affSColin Finck     if (ulFlags != 0)
1885*c2c66affSColin Finck         return CR_INVALID_FLAG;
1886*c2c66affSColin Finck 
1887*c2c66affSColin Finck     if (*pulLength < MAX_GUID_STRING_LEN)
1888*c2c66affSColin Finck     {
1889*c2c66affSColin Finck         *pulLength = 0;
1890*c2c66affSColin Finck         return CR_BUFFER_SMALL;
1891*c2c66affSColin Finck     }
1892*c2c66affSColin Finck 
1893*c2c66affSColin Finck     if (!GuidToString(ClassGuid, pszKeyName))
1894*c2c66affSColin Finck         return CR_INVALID_DATA;
1895*c2c66affSColin Finck 
1896*c2c66affSColin Finck     *pulLength = MAX_GUID_STRING_LEN;
1897*c2c66affSColin Finck 
1898*c2c66affSColin Finck     return CR_SUCCESS;
1899*c2c66affSColin Finck }
1900*c2c66affSColin Finck 
1901*c2c66affSColin Finck 
1902*c2c66affSColin Finck /***********************************************************************
1903*c2c66affSColin Finck  * CM_Get_Class_NameA [SETUPAPI.@]
1904*c2c66affSColin Finck  */
1905*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Class_NameA(
1906*c2c66affSColin Finck     LPGUID ClassGuid, PCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1907*c2c66affSColin Finck {
1908*c2c66affSColin Finck     TRACE("%p %p %p %lx\n", ClassGuid, Buffer, pulLength, ulFlags);
1909*c2c66affSColin Finck     return CM_Get_Class_Name_ExA(ClassGuid, Buffer, pulLength, ulFlags,
1910*c2c66affSColin Finck                                  NULL);
1911*c2c66affSColin Finck }
1912*c2c66affSColin Finck 
1913*c2c66affSColin Finck 
1914*c2c66affSColin Finck /***********************************************************************
1915*c2c66affSColin Finck  * CM_Get_Class_NameW [SETUPAPI.@]
1916*c2c66affSColin Finck  */
1917*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Class_NameW(
1918*c2c66affSColin Finck     LPGUID ClassGuid, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1919*c2c66affSColin Finck {
1920*c2c66affSColin Finck     TRACE("%p %p %p %lx\n", ClassGuid, Buffer, pulLength, ulFlags);
1921*c2c66affSColin Finck     return CM_Get_Class_Name_ExW(ClassGuid, Buffer, pulLength, ulFlags,
1922*c2c66affSColin Finck                                  NULL);
1923*c2c66affSColin Finck }
1924*c2c66affSColin Finck 
1925*c2c66affSColin Finck 
1926*c2c66affSColin Finck /***********************************************************************
1927*c2c66affSColin Finck  * CM_Get_Class_Name_ExA [SETUPAPI.@]
1928*c2c66affSColin Finck  */
1929*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Class_Name_ExA(
1930*c2c66affSColin Finck     LPGUID ClassGuid, PCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1931*c2c66affSColin Finck     HMACHINE hMachine)
1932*c2c66affSColin Finck {
1933*c2c66affSColin Finck     WCHAR szBuffer[MAX_CLASS_NAME_LEN];
1934*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
1935*c2c66affSColin Finck     ULONG ulLength;
1936*c2c66affSColin Finck     ULONG ulOrigLength;
1937*c2c66affSColin Finck 
1938*c2c66affSColin Finck     TRACE("%p %p %p %lx %lx\n",
1939*c2c66affSColin Finck           ClassGuid, Buffer, pulLength, ulFlags, hMachine);
1940*c2c66affSColin Finck 
1941*c2c66affSColin Finck     if (ClassGuid == NULL || Buffer == NULL || pulLength == NULL)
1942*c2c66affSColin Finck         return CR_INVALID_POINTER;
1943*c2c66affSColin Finck 
1944*c2c66affSColin Finck     ulOrigLength = *pulLength;
1945*c2c66affSColin Finck     *pulLength = 0;
1946*c2c66affSColin Finck 
1947*c2c66affSColin Finck     ulLength = MAX_CLASS_NAME_LEN;
1948*c2c66affSColin Finck     ret = CM_Get_Class_Name_ExW(ClassGuid, szBuffer, &ulLength,
1949*c2c66affSColin Finck                                 ulFlags, hMachine);
1950*c2c66affSColin Finck     if (ret == CR_SUCCESS)
1951*c2c66affSColin Finck     {
1952*c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
1953*c2c66affSColin Finck                                 0,
1954*c2c66affSColin Finck                                 szBuffer,
1955*c2c66affSColin Finck                                 ulLength,
1956*c2c66affSColin Finck                                 Buffer,
1957*c2c66affSColin Finck                                 ulOrigLength,
1958*c2c66affSColin Finck                                 NULL,
1959*c2c66affSColin Finck                                 NULL) == 0)
1960*c2c66affSColin Finck             ret = CR_FAILURE;
1961*c2c66affSColin Finck         else
1962*c2c66affSColin Finck             *pulLength = lstrlenA(Buffer) + 1;
1963*c2c66affSColin Finck     }
1964*c2c66affSColin Finck 
1965*c2c66affSColin Finck     return ret;
1966*c2c66affSColin Finck }
1967*c2c66affSColin Finck 
1968*c2c66affSColin Finck 
1969*c2c66affSColin Finck /***********************************************************************
1970*c2c66affSColin Finck  * CM_Get_Class_Name_ExW [SETUPAPI.@]
1971*c2c66affSColin Finck  */
1972*c2c66affSColin Finck CONFIGRET WINAPI
1973*c2c66affSColin Finck CM_Get_Class_Name_ExW(
1974*c2c66affSColin Finck     LPGUID ClassGuid, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1975*c2c66affSColin Finck     HMACHINE hMachine)
1976*c2c66affSColin Finck {
1977*c2c66affSColin Finck     WCHAR szGuidString[MAX_GUID_STRING_LEN];
1978*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
1979*c2c66affSColin Finck     CONFIGRET ret;
1980*c2c66affSColin Finck 
1981*c2c66affSColin Finck     TRACE("%p %p %p %lx %lx\n",
1982*c2c66affSColin Finck           ClassGuid, Buffer, pulLength, ulFlags, hMachine);
1983*c2c66affSColin Finck 
1984*c2c66affSColin Finck     if (ClassGuid == NULL || Buffer == NULL || pulLength == NULL)
1985*c2c66affSColin Finck         return CR_INVALID_POINTER;
1986*c2c66affSColin Finck 
1987*c2c66affSColin Finck     if (ulFlags != 0)
1988*c2c66affSColin Finck         return CR_INVALID_FLAG;
1989*c2c66affSColin Finck 
1990*c2c66affSColin Finck     if (!GuidToString(ClassGuid, szGuidString))
1991*c2c66affSColin Finck         return CR_INVALID_DATA;
1992*c2c66affSColin Finck 
1993*c2c66affSColin Finck     TRACE("Guid %s\n", debugstr_w(szGuidString));
1994*c2c66affSColin Finck 
1995*c2c66affSColin Finck     if (hMachine != NULL)
1996*c2c66affSColin Finck     {
1997*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1998*c2c66affSColin Finck         if (BindingHandle == NULL)
1999*c2c66affSColin Finck             return CR_FAILURE;
2000*c2c66affSColin Finck     }
2001*c2c66affSColin Finck     else
2002*c2c66affSColin Finck     {
2003*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
2004*c2c66affSColin Finck             return CR_FAILURE;
2005*c2c66affSColin Finck     }
2006*c2c66affSColin Finck 
2007*c2c66affSColin Finck     RpcTryExcept
2008*c2c66affSColin Finck     {
2009*c2c66affSColin Finck         ret = PNP_GetClassName(BindingHandle,
2010*c2c66affSColin Finck                                szGuidString,
2011*c2c66affSColin Finck                                Buffer,
2012*c2c66affSColin Finck                                pulLength,
2013*c2c66affSColin Finck                                ulFlags);
2014*c2c66affSColin Finck     }
2015*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2016*c2c66affSColin Finck     {
2017*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2018*c2c66affSColin Finck     }
2019*c2c66affSColin Finck     RpcEndExcept;
2020*c2c66affSColin Finck 
2021*c2c66affSColin Finck     return ret;
2022*c2c66affSColin Finck }
2023*c2c66affSColin Finck 
2024*c2c66affSColin Finck 
2025*c2c66affSColin Finck /***********************************************************************
2026*c2c66affSColin Finck  * CM_Get_Class_Registry_PropertyA [SETUPAPI.@]
2027*c2c66affSColin Finck  */
2028*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Class_Registry_PropertyA(
2029*c2c66affSColin Finck     LPGUID ClassGuid, ULONG ulProperty, PULONG pulRegDataType,
2030*c2c66affSColin Finck     PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2031*c2c66affSColin Finck {
2032*c2c66affSColin Finck     PWSTR BufferW = NULL;
2033*c2c66affSColin Finck     ULONG ulLength = 0;
2034*c2c66affSColin Finck     ULONG ulType;
2035*c2c66affSColin Finck     CONFIGRET ret;
2036*c2c66affSColin Finck 
2037*c2c66affSColin Finck     TRACE("%p %lu %p %p %p %lx %lx\n",
2038*c2c66affSColin Finck           ClassGuid, ulProperty, pulRegDataType, Buffer, pulLength,
2039*c2c66affSColin Finck           ulFlags, hMachine);
2040*c2c66affSColin Finck 
2041*c2c66affSColin Finck     if (pulLength == NULL)
2042*c2c66affSColin Finck         return CR_INVALID_POINTER;
2043*c2c66affSColin Finck 
2044*c2c66affSColin Finck     if (ulProperty < CM_CRP_MIN || ulProperty > CM_CRP_MAX)
2045*c2c66affSColin Finck         return CR_INVALID_PROPERTY;
2046*c2c66affSColin Finck 
2047*c2c66affSColin Finck     ulType = GetRegistryPropertyType(ulProperty);
2048*c2c66affSColin Finck     if (ulType == REG_SZ || ulType == REG_MULTI_SZ)
2049*c2c66affSColin Finck     {
2050*c2c66affSColin Finck         /* Get the required buffer size */
2051*c2c66affSColin Finck         ret = CM_Get_Class_Registry_PropertyW(ClassGuid, ulProperty, pulRegDataType,
2052*c2c66affSColin Finck                                               NULL, &ulLength, ulFlags, hMachine);
2053*c2c66affSColin Finck         if (ret != CR_BUFFER_SMALL)
2054*c2c66affSColin Finck             return ret;
2055*c2c66affSColin Finck 
2056*c2c66affSColin Finck         /* Allocate the unicode buffer */
2057*c2c66affSColin Finck         BufferW = HeapAlloc(GetProcessHeap(), 0, ulLength);
2058*c2c66affSColin Finck         if (BufferW == NULL)
2059*c2c66affSColin Finck             return CR_OUT_OF_MEMORY;
2060*c2c66affSColin Finck 
2061*c2c66affSColin Finck         /* Get the property */
2062*c2c66affSColin Finck         ret = CM_Get_Class_Registry_PropertyW(ClassGuid, ulProperty, pulRegDataType,
2063*c2c66affSColin Finck                                               BufferW, &ulLength, ulFlags, hMachine);
2064*c2c66affSColin Finck         if (ret != CR_SUCCESS)
2065*c2c66affSColin Finck         {
2066*c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, BufferW);
2067*c2c66affSColin Finck             return ret;
2068*c2c66affSColin Finck         }
2069*c2c66affSColin Finck 
2070*c2c66affSColin Finck         /* Do W->A conversion */
2071*c2c66affSColin Finck         *pulLength = WideCharToMultiByte(CP_ACP,
2072*c2c66affSColin Finck                                          0,
2073*c2c66affSColin Finck                                          BufferW,
2074*c2c66affSColin Finck                                          lstrlenW(BufferW) + 1,
2075*c2c66affSColin Finck                                          Buffer,
2076*c2c66affSColin Finck                                          *pulLength,
2077*c2c66affSColin Finck                                          NULL,
2078*c2c66affSColin Finck                                          NULL);
2079*c2c66affSColin Finck 
2080*c2c66affSColin Finck         /* Release the unicode buffer */
2081*c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, BufferW);
2082*c2c66affSColin Finck 
2083*c2c66affSColin Finck         if (*pulLength == 0)
2084*c2c66affSColin Finck             ret = CR_FAILURE;
2085*c2c66affSColin Finck     }
2086*c2c66affSColin Finck     else
2087*c2c66affSColin Finck     {
2088*c2c66affSColin Finck         /* Get the property */
2089*c2c66affSColin Finck         ret = CM_Get_Class_Registry_PropertyW(ClassGuid, ulProperty, pulRegDataType,
2090*c2c66affSColin Finck                                               Buffer, pulLength, ulFlags, hMachine);
2091*c2c66affSColin Finck     }
2092*c2c66affSColin Finck 
2093*c2c66affSColin Finck     return ret;
2094*c2c66affSColin Finck }
2095*c2c66affSColin Finck 
2096*c2c66affSColin Finck 
2097*c2c66affSColin Finck /***********************************************************************
2098*c2c66affSColin Finck  * CM_Get_Class_Registry_PropertyW [SETUPAPI.@]
2099*c2c66affSColin Finck  */
2100*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Class_Registry_PropertyW(
2101*c2c66affSColin Finck     LPGUID ClassGuid, ULONG ulProperty, PULONG pulRegDataType,
2102*c2c66affSColin Finck     PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2103*c2c66affSColin Finck {
2104*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
2105*c2c66affSColin Finck     WCHAR szGuidString[PNP_MAX_GUID_STRING_LEN + 1];
2106*c2c66affSColin Finck     ULONG ulType = 0;
2107*c2c66affSColin Finck     ULONG ulTransferLength = 0;
2108*c2c66affSColin Finck     CONFIGRET ret;
2109*c2c66affSColin Finck 
2110*c2c66affSColin Finck     TRACE("%p %lu %p %p %p %lx %lx\n",
2111*c2c66affSColin Finck           ClassGuid, ulProperty, pulRegDataType, Buffer, pulLength,
2112*c2c66affSColin Finck           ulFlags, hMachine);
2113*c2c66affSColin Finck 
2114*c2c66affSColin Finck     if (ClassGuid == NULL || pulLength == NULL)
2115*c2c66affSColin Finck         return CR_INVALID_POINTER;
2116*c2c66affSColin Finck 
2117*c2c66affSColin Finck     if (ulFlags != 0)
2118*c2c66affSColin Finck         return CR_INVALID_FLAG;
2119*c2c66affSColin Finck 
2120*c2c66affSColin Finck     if (pSetupStringFromGuid(ClassGuid,
2121*c2c66affSColin Finck                              szGuidString,
2122*c2c66affSColin Finck                              PNP_MAX_GUID_STRING_LEN) != 0)
2123*c2c66affSColin Finck         return CR_INVALID_DATA;
2124*c2c66affSColin Finck 
2125*c2c66affSColin Finck     if (ulProperty < CM_CRP_MIN || ulProperty > CM_CRP_MAX)
2126*c2c66affSColin Finck         return CR_INVALID_PROPERTY;
2127*c2c66affSColin Finck 
2128*c2c66affSColin Finck     if (hMachine != NULL)
2129*c2c66affSColin Finck     {
2130*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2131*c2c66affSColin Finck         if (BindingHandle == NULL)
2132*c2c66affSColin Finck             return CR_FAILURE;
2133*c2c66affSColin Finck     }
2134*c2c66affSColin Finck     else
2135*c2c66affSColin Finck     {
2136*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
2137*c2c66affSColin Finck             return CR_FAILURE;
2138*c2c66affSColin Finck     }
2139*c2c66affSColin Finck 
2140*c2c66affSColin Finck     ulTransferLength = *pulLength;
2141*c2c66affSColin Finck 
2142*c2c66affSColin Finck     RpcTryExcept
2143*c2c66affSColin Finck     {
2144*c2c66affSColin Finck         ret = PNP_GetClassRegProp(BindingHandle,
2145*c2c66affSColin Finck                                   szGuidString,
2146*c2c66affSColin Finck                                   ulProperty,
2147*c2c66affSColin Finck                                   &ulType,
2148*c2c66affSColin Finck                                   Buffer,
2149*c2c66affSColin Finck                                   &ulTransferLength,
2150*c2c66affSColin Finck                                   pulLength,
2151*c2c66affSColin Finck                                   ulFlags);
2152*c2c66affSColin Finck     }
2153*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2154*c2c66affSColin Finck     {
2155*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2156*c2c66affSColin Finck     }
2157*c2c66affSColin Finck     RpcEndExcept;
2158*c2c66affSColin Finck 
2159*c2c66affSColin Finck     if (ret == CR_SUCCESS)
2160*c2c66affSColin Finck     {
2161*c2c66affSColin Finck         if (pulRegDataType != NULL)
2162*c2c66affSColin Finck             *pulRegDataType = ulType;
2163*c2c66affSColin Finck     }
2164*c2c66affSColin Finck 
2165*c2c66affSColin Finck     return ret;
2166*c2c66affSColin Finck }
2167*c2c66affSColin Finck 
2168*c2c66affSColin Finck 
2169*c2c66affSColin Finck /***********************************************************************
2170*c2c66affSColin Finck  * CM_Get_Depth [SETUPAPI.@]
2171*c2c66affSColin Finck  */
2172*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Depth(
2173*c2c66affSColin Finck     PULONG pulDepth, DEVINST dnDevInst, ULONG ulFlags)
2174*c2c66affSColin Finck {
2175*c2c66affSColin Finck     TRACE("%p %lx %lx\n", pulDepth, dnDevInst, ulFlags);
2176*c2c66affSColin Finck     return CM_Get_Depth_Ex(pulDepth, dnDevInst, ulFlags, NULL);
2177*c2c66affSColin Finck }
2178*c2c66affSColin Finck 
2179*c2c66affSColin Finck 
2180*c2c66affSColin Finck /***********************************************************************
2181*c2c66affSColin Finck  * CM_Get_Depth_Ex [SETUPAPI.@]
2182*c2c66affSColin Finck  */
2183*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Depth_Ex(
2184*c2c66affSColin Finck     PULONG pulDepth, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
2185*c2c66affSColin Finck {
2186*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
2187*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
2188*c2c66affSColin Finck     LPWSTR lpDevInst;
2189*c2c66affSColin Finck     CONFIGRET ret;
2190*c2c66affSColin Finck 
2191*c2c66affSColin Finck     TRACE("%p %lx %lx %lx\n",
2192*c2c66affSColin Finck           pulDepth, dnDevInst, ulFlags, hMachine);
2193*c2c66affSColin Finck 
2194*c2c66affSColin Finck     if (pulDepth == NULL)
2195*c2c66affSColin Finck         return CR_INVALID_POINTER;
2196*c2c66affSColin Finck 
2197*c2c66affSColin Finck     if (dnDevInst == 0)
2198*c2c66affSColin Finck         return CR_INVALID_DEVINST;
2199*c2c66affSColin Finck 
2200*c2c66affSColin Finck     if (ulFlags != 0)
2201*c2c66affSColin Finck         return CR_INVALID_FLAG;
2202*c2c66affSColin Finck 
2203*c2c66affSColin Finck     if (hMachine != NULL)
2204*c2c66affSColin Finck     {
2205*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2206*c2c66affSColin Finck         if (BindingHandle == NULL)
2207*c2c66affSColin Finck             return CR_FAILURE;
2208*c2c66affSColin Finck 
2209*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2210*c2c66affSColin Finck         if (StringTable == 0)
2211*c2c66affSColin Finck             return CR_FAILURE;
2212*c2c66affSColin Finck     }
2213*c2c66affSColin Finck     else
2214*c2c66affSColin Finck     {
2215*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2216*c2c66affSColin Finck             return CR_FAILURE;
2217*c2c66affSColin Finck     }
2218*c2c66affSColin Finck 
2219*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2220*c2c66affSColin Finck     if (lpDevInst == NULL)
2221*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
2222*c2c66affSColin Finck 
2223*c2c66affSColin Finck     RpcTryExcept
2224*c2c66affSColin Finck     {
2225*c2c66affSColin Finck         ret = PNP_GetDepth(BindingHandle,
2226*c2c66affSColin Finck                            lpDevInst,
2227*c2c66affSColin Finck                            pulDepth,
2228*c2c66affSColin Finck                            ulFlags);
2229*c2c66affSColin Finck     }
2230*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2231*c2c66affSColin Finck     {
2232*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2233*c2c66affSColin Finck     }
2234*c2c66affSColin Finck     RpcEndExcept;
2235*c2c66affSColin Finck 
2236*c2c66affSColin Finck     return ret;
2237*c2c66affSColin Finck }
2238*c2c66affSColin Finck 
2239*c2c66affSColin Finck 
2240*c2c66affSColin Finck /***********************************************************************
2241*c2c66affSColin Finck  * CM_Get_DevNode_Custom_PropertyA [SETUPAPI.@]
2242*c2c66affSColin Finck  */
2243*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_DevNode_Custom_PropertyA(
2244*c2c66affSColin Finck     DEVINST dnDevInst, PCSTR pszCustomPropertyName, PULONG pulRegDataType,
2245*c2c66affSColin Finck     PVOID Buffer, PULONG pulLength, ULONG ulFlags)
2246*c2c66affSColin Finck {
2247*c2c66affSColin Finck     TRACE("%lx %s %p %p %p %lx\n", dnDevInst, pszCustomPropertyName,
2248*c2c66affSColin Finck           pulRegDataType, Buffer, pulLength, ulFlags);
2249*c2c66affSColin Finck     return CM_Get_DevNode_Custom_Property_ExA(dnDevInst, pszCustomPropertyName,
2250*c2c66affSColin Finck                                               pulRegDataType, Buffer,
2251*c2c66affSColin Finck                                               pulLength, ulFlags, NULL);
2252*c2c66affSColin Finck }
2253*c2c66affSColin Finck 
2254*c2c66affSColin Finck 
2255*c2c66affSColin Finck /***********************************************************************
2256*c2c66affSColin Finck  * CM_Get_DevNode_Custom_PropertyW [SETUPAPI.@]
2257*c2c66affSColin Finck  */
2258*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_DevNode_Custom_PropertyW(
2259*c2c66affSColin Finck     DEVINST dnDevInst, PCWSTR pszCustomPropertyName, PULONG pulRegDataType,
2260*c2c66affSColin Finck     PVOID Buffer, PULONG pulLength, ULONG ulFlags)
2261*c2c66affSColin Finck {
2262*c2c66affSColin Finck     TRACE("%lx %s %p %p %p %lx\n", dnDevInst, debugstr_w(pszCustomPropertyName),
2263*c2c66affSColin Finck           pulRegDataType, Buffer, pulLength, ulFlags);
2264*c2c66affSColin Finck     return CM_Get_DevNode_Custom_Property_ExW(dnDevInst, pszCustomPropertyName,
2265*c2c66affSColin Finck                                               pulRegDataType, Buffer,
2266*c2c66affSColin Finck                                               pulLength, ulFlags, NULL);
2267*c2c66affSColin Finck }
2268*c2c66affSColin Finck 
2269*c2c66affSColin Finck 
2270*c2c66affSColin Finck /***********************************************************************
2271*c2c66affSColin Finck  * CM_Get_DevNode_Custom_Property_ExA [SETUPAPI.@]
2272*c2c66affSColin Finck  */
2273*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_DevNode_Custom_Property_ExA(
2274*c2c66affSColin Finck     DEVINST dnDevInst, PCSTR pszCustomPropertyName, PULONG pulRegDataType,
2275*c2c66affSColin Finck     PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2276*c2c66affSColin Finck {
2277*c2c66affSColin Finck     LPWSTR pszPropertyNameW = NULL;
2278*c2c66affSColin Finck     PVOID BufferW;
2279*c2c66affSColin Finck     ULONG ulLengthW;
2280*c2c66affSColin Finck     ULONG ulDataType = REG_NONE;
2281*c2c66affSColin Finck     CONFIGRET ret;
2282*c2c66affSColin Finck 
2283*c2c66affSColin Finck     TRACE("%lx %s %p %p %p %lx %p\n", dnDevInst, pszCustomPropertyName,
2284*c2c66affSColin Finck           pulRegDataType, Buffer, pulLength, ulFlags, hMachine);
2285*c2c66affSColin Finck 
2286*c2c66affSColin Finck     if (!pulLength)
2287*c2c66affSColin Finck         return CR_INVALID_POINTER;
2288*c2c66affSColin Finck 
2289*c2c66affSColin Finck     ulLengthW = *pulLength * sizeof(WCHAR);
2290*c2c66affSColin Finck     BufferW = HeapAlloc(GetProcessHeap(), 0, ulLengthW);
2291*c2c66affSColin Finck     if (!BufferW)
2292*c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
2293*c2c66affSColin Finck 
2294*c2c66affSColin Finck     pszPropertyNameW = pSetupMultiByteToUnicode(pszCustomPropertyName,
2295*c2c66affSColin Finck                                                 CP_ACP);
2296*c2c66affSColin Finck     if (pszPropertyNameW == NULL)
2297*c2c66affSColin Finck     {
2298*c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, BufferW);
2299*c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
2300*c2c66affSColin Finck     }
2301*c2c66affSColin Finck 
2302*c2c66affSColin Finck     ret = CM_Get_DevNode_Custom_Property_ExW(dnDevInst,
2303*c2c66affSColin Finck                                              pszPropertyNameW,
2304*c2c66affSColin Finck                                              &ulDataType,
2305*c2c66affSColin Finck                                              BufferW,
2306*c2c66affSColin Finck                                              &ulLengthW,
2307*c2c66affSColin Finck                                              ulFlags,
2308*c2c66affSColin Finck                                              hMachine);
2309*c2c66affSColin Finck     if (ret == CR_SUCCESS)
2310*c2c66affSColin Finck     {
2311*c2c66affSColin Finck         if (ulDataType == REG_SZ ||
2312*c2c66affSColin Finck             ulDataType == REG_EXPAND_SZ ||
2313*c2c66affSColin Finck             ulDataType == REG_MULTI_SZ)
2314*c2c66affSColin Finck         {
2315*c2c66affSColin Finck             /* Do W->A conversion */
2316*c2c66affSColin Finck             *pulLength = WideCharToMultiByte(CP_ACP,
2317*c2c66affSColin Finck                                              0,
2318*c2c66affSColin Finck                                              BufferW,
2319*c2c66affSColin Finck                                              lstrlenW(BufferW) + 1,
2320*c2c66affSColin Finck                                              Buffer,
2321*c2c66affSColin Finck                                              *pulLength,
2322*c2c66affSColin Finck                                              NULL,
2323*c2c66affSColin Finck                                              NULL);
2324*c2c66affSColin Finck             if (*pulLength == 0)
2325*c2c66affSColin Finck                 ret = CR_FAILURE;
2326*c2c66affSColin Finck         }
2327*c2c66affSColin Finck         else
2328*c2c66affSColin Finck         {
2329*c2c66affSColin Finck             /* Directly copy the value */
2330*c2c66affSColin Finck             if (ulLengthW <= *pulLength)
2331*c2c66affSColin Finck                 memcpy(Buffer, BufferW, ulLengthW);
2332*c2c66affSColin Finck             else
2333*c2c66affSColin Finck             {
2334*c2c66affSColin Finck                 *pulLength = ulLengthW;
2335*c2c66affSColin Finck                 ret = CR_BUFFER_SMALL;
2336*c2c66affSColin Finck             }
2337*c2c66affSColin Finck         }
2338*c2c66affSColin Finck     }
2339*c2c66affSColin Finck 
2340*c2c66affSColin Finck     if (pulRegDataType)
2341*c2c66affSColin Finck         *pulRegDataType = ulDataType;
2342*c2c66affSColin Finck 
2343*c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, BufferW);
2344*c2c66affSColin Finck     MyFree(pszPropertyNameW);
2345*c2c66affSColin Finck 
2346*c2c66affSColin Finck     return ret;
2347*c2c66affSColin Finck }
2348*c2c66affSColin Finck 
2349*c2c66affSColin Finck 
2350*c2c66affSColin Finck /***********************************************************************
2351*c2c66affSColin Finck  * CM_Get_DevNode_Custom_Property_ExW [SETUPAPI.@]
2352*c2c66affSColin Finck  */
2353*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_DevNode_Custom_Property_ExW(
2354*c2c66affSColin Finck     DEVINST dnDevInst, PCWSTR pszCustomPropertyName, PULONG pulRegDataType,
2355*c2c66affSColin Finck     PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2356*c2c66affSColin Finck {
2357*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
2358*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
2359*c2c66affSColin Finck     LPWSTR lpDevInst;
2360*c2c66affSColin Finck     ULONG ulDataType = REG_NONE;
2361*c2c66affSColin Finck     ULONG ulTransferLength;
2362*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
2363*c2c66affSColin Finck 
2364*c2c66affSColin Finck     TRACE("%lx %s %p %p %p %lx %p\n", dnDevInst,
2365*c2c66affSColin Finck           debugstr_w(pszCustomPropertyName), pulRegDataType, Buffer,
2366*c2c66affSColin Finck           pulLength, ulFlags, hMachine);
2367*c2c66affSColin Finck 
2368*c2c66affSColin Finck     if (dnDevInst == 0)
2369*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
2370*c2c66affSColin Finck 
2371*c2c66affSColin Finck     if (pszCustomPropertyName == NULL ||
2372*c2c66affSColin Finck         pulLength == NULL ||
2373*c2c66affSColin Finck         *pulLength == 0)
2374*c2c66affSColin Finck         return CR_INVALID_POINTER;
2375*c2c66affSColin Finck 
2376*c2c66affSColin Finck     if (ulFlags & ~CM_CUSTOMDEVPROP_BITS)
2377*c2c66affSColin Finck         return CR_INVALID_FLAG;
2378*c2c66affSColin Finck 
2379*c2c66affSColin Finck     if (hMachine != NULL)
2380*c2c66affSColin Finck     {
2381*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2382*c2c66affSColin Finck         if (BindingHandle == NULL)
2383*c2c66affSColin Finck             return CR_FAILURE;
2384*c2c66affSColin Finck 
2385*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2386*c2c66affSColin Finck         if (StringTable == 0)
2387*c2c66affSColin Finck             return CR_FAILURE;
2388*c2c66affSColin Finck     }
2389*c2c66affSColin Finck     else
2390*c2c66affSColin Finck     {
2391*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2392*c2c66affSColin Finck             return CR_FAILURE;
2393*c2c66affSColin Finck     }
2394*c2c66affSColin Finck 
2395*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2396*c2c66affSColin Finck     if (lpDevInst == NULL)
2397*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
2398*c2c66affSColin Finck 
2399*c2c66affSColin Finck     ulTransferLength = *pulLength;
2400*c2c66affSColin Finck 
2401*c2c66affSColin Finck     RpcTryExcept
2402*c2c66affSColin Finck     {
2403*c2c66affSColin Finck         ret = PNP_GetCustomDevProp(BindingHandle,
2404*c2c66affSColin Finck                                    lpDevInst,
2405*c2c66affSColin Finck                                    (LPWSTR)pszCustomPropertyName,
2406*c2c66affSColin Finck                                    &ulDataType,
2407*c2c66affSColin Finck                                    Buffer,
2408*c2c66affSColin Finck                                    &ulTransferLength,
2409*c2c66affSColin Finck                                    pulLength,
2410*c2c66affSColin Finck                                    ulFlags);
2411*c2c66affSColin Finck     }
2412*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2413*c2c66affSColin Finck     {
2414*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2415*c2c66affSColin Finck     }
2416*c2c66affSColin Finck     RpcEndExcept;
2417*c2c66affSColin Finck 
2418*c2c66affSColin Finck     if (ret == CR_SUCCESS)
2419*c2c66affSColin Finck     {
2420*c2c66affSColin Finck         if (pulRegDataType != NULL)
2421*c2c66affSColin Finck             *pulRegDataType = ulDataType;
2422*c2c66affSColin Finck     }
2423*c2c66affSColin Finck 
2424*c2c66affSColin Finck     return ret;
2425*c2c66affSColin Finck }
2426*c2c66affSColin Finck 
2427*c2c66affSColin Finck 
2428*c2c66affSColin Finck /***********************************************************************
2429*c2c66affSColin Finck  * CM_Get_DevNode_Registry_PropertyA [SETUPAPI.@]
2430*c2c66affSColin Finck  */
2431*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_DevNode_Registry_PropertyA(
2432*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
2433*c2c66affSColin Finck     PVOID Buffer, PULONG pulLength, ULONG ulFlags)
2434*c2c66affSColin Finck {
2435*c2c66affSColin Finck     TRACE("%lx %lu %p %p %p %lx\n",
2436*c2c66affSColin Finck           dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength, ulFlags);
2437*c2c66affSColin Finck 
2438*c2c66affSColin Finck     return CM_Get_DevNode_Registry_Property_ExA(dnDevInst, ulProperty,
2439*c2c66affSColin Finck                                                 pulRegDataType, Buffer,
2440*c2c66affSColin Finck                                                 pulLength, ulFlags, NULL);
2441*c2c66affSColin Finck }
2442*c2c66affSColin Finck 
2443*c2c66affSColin Finck 
2444*c2c66affSColin Finck /***********************************************************************
2445*c2c66affSColin Finck  * CM_Get_DevNode_Registry_PropertyW [SETUPAPI.@]
2446*c2c66affSColin Finck  */
2447*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_DevNode_Registry_PropertyW(
2448*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
2449*c2c66affSColin Finck     PVOID Buffer, PULONG pulLength, ULONG ulFlags)
2450*c2c66affSColin Finck {
2451*c2c66affSColin Finck     TRACE("%lx %lu %p %p %p %lx\n",
2452*c2c66affSColin Finck           dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength, ulFlags);
2453*c2c66affSColin Finck 
2454*c2c66affSColin Finck     return CM_Get_DevNode_Registry_Property_ExW(dnDevInst, ulProperty,
2455*c2c66affSColin Finck                                                 pulRegDataType, Buffer,
2456*c2c66affSColin Finck                                                 pulLength, ulFlags, NULL);
2457*c2c66affSColin Finck }
2458*c2c66affSColin Finck 
2459*c2c66affSColin Finck 
2460*c2c66affSColin Finck /***********************************************************************
2461*c2c66affSColin Finck  * CM_Get_DevNode_Registry_Property_ExA [SETUPAPI.@]
2462*c2c66affSColin Finck  */
2463*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_DevNode_Registry_Property_ExA(
2464*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
2465*c2c66affSColin Finck     PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2466*c2c66affSColin Finck {
2467*c2c66affSColin Finck     PVOID BufferW;
2468*c2c66affSColin Finck     ULONG LengthW;
2469*c2c66affSColin Finck     ULONG ulDataType = REG_NONE;
2470*c2c66affSColin Finck     CONFIGRET ret;
2471*c2c66affSColin Finck 
2472*c2c66affSColin Finck     TRACE("%lx %lu %p %p %p %lx %lx\n",
2473*c2c66affSColin Finck           dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength,
2474*c2c66affSColin Finck           ulFlags, hMachine);
2475*c2c66affSColin Finck 
2476*c2c66affSColin Finck     if (!pulLength)
2477*c2c66affSColin Finck         return CR_INVALID_POINTER;
2478*c2c66affSColin Finck 
2479*c2c66affSColin Finck     LengthW = *pulLength * sizeof(WCHAR);
2480*c2c66affSColin Finck     BufferW = HeapAlloc(GetProcessHeap(), 0, LengthW);
2481*c2c66affSColin Finck 
2482*c2c66affSColin Finck     if (!BufferW)
2483*c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
2484*c2c66affSColin Finck 
2485*c2c66affSColin Finck     ret = CM_Get_DevNode_Registry_Property_ExW(dnDevInst,
2486*c2c66affSColin Finck                                                ulProperty,
2487*c2c66affSColin Finck                                                &ulDataType,
2488*c2c66affSColin Finck                                                BufferW,
2489*c2c66affSColin Finck                                                &LengthW,
2490*c2c66affSColin Finck                                                ulFlags,
2491*c2c66affSColin Finck                                                hMachine);
2492*c2c66affSColin Finck 
2493*c2c66affSColin Finck     if (ret == CR_SUCCESS)
2494*c2c66affSColin Finck     {
2495*c2c66affSColin Finck         if (ulDataType == REG_SZ ||
2496*c2c66affSColin Finck             ulDataType == REG_EXPAND_SZ ||
2497*c2c66affSColin Finck             ulDataType == REG_MULTI_SZ)
2498*c2c66affSColin Finck         {
2499*c2c66affSColin Finck             /* Do W->A conversion */
2500*c2c66affSColin Finck             *pulLength = WideCharToMultiByte(CP_ACP,
2501*c2c66affSColin Finck                                              0,
2502*c2c66affSColin Finck                                              BufferW,
2503*c2c66affSColin Finck                                              lstrlenW(BufferW) + 1,
2504*c2c66affSColin Finck                                              Buffer,
2505*c2c66affSColin Finck                                              *pulLength,
2506*c2c66affSColin Finck                                              NULL,
2507*c2c66affSColin Finck                                              NULL);
2508*c2c66affSColin Finck             if (*pulLength == 0)
2509*c2c66affSColin Finck                 ret = CR_FAILURE;
2510*c2c66affSColin Finck         }
2511*c2c66affSColin Finck         else
2512*c2c66affSColin Finck         {
2513*c2c66affSColin Finck             /* Directly copy the value */
2514*c2c66affSColin Finck             if (LengthW <= *pulLength)
2515*c2c66affSColin Finck                 memcpy(Buffer, BufferW, LengthW);
2516*c2c66affSColin Finck             else
2517*c2c66affSColin Finck             {
2518*c2c66affSColin Finck                 *pulLength = LengthW;
2519*c2c66affSColin Finck                 ret = CR_BUFFER_SMALL;
2520*c2c66affSColin Finck             }
2521*c2c66affSColin Finck         }
2522*c2c66affSColin Finck     }
2523*c2c66affSColin Finck 
2524*c2c66affSColin Finck     if (pulRegDataType)
2525*c2c66affSColin Finck         *pulRegDataType = ulDataType;
2526*c2c66affSColin Finck 
2527*c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, BufferW);
2528*c2c66affSColin Finck 
2529*c2c66affSColin Finck     return ret;
2530*c2c66affSColin Finck }
2531*c2c66affSColin Finck 
2532*c2c66affSColin Finck 
2533*c2c66affSColin Finck /***********************************************************************
2534*c2c66affSColin Finck  * CM_Get_DevNode_Registry_Property_ExW [SETUPAPI.@]
2535*c2c66affSColin Finck  */
2536*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_DevNode_Registry_Property_ExW(
2537*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
2538*c2c66affSColin Finck     PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2539*c2c66affSColin Finck {
2540*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
2541*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
2542*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
2543*c2c66affSColin Finck     LPWSTR lpDevInst;
2544*c2c66affSColin Finck     ULONG ulDataType = REG_NONE;
2545*c2c66affSColin Finck     ULONG ulTransferLength = 0;
2546*c2c66affSColin Finck 
2547*c2c66affSColin Finck     TRACE("%lx %lu %p %p %p %lx %lx\n",
2548*c2c66affSColin Finck           dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength,
2549*c2c66affSColin Finck           ulFlags, hMachine);
2550*c2c66affSColin Finck 
2551*c2c66affSColin Finck     if (dnDevInst == 0)
2552*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
2553*c2c66affSColin Finck 
2554*c2c66affSColin Finck     if (ulProperty < CM_DRP_MIN || ulProperty > CM_DRP_MAX)
2555*c2c66affSColin Finck         return CR_INVALID_PROPERTY;
2556*c2c66affSColin Finck 
2557*c2c66affSColin Finck     /* pulRegDataType is optional */
2558*c2c66affSColin Finck 
2559*c2c66affSColin Finck     /* Buffer is optional */
2560*c2c66affSColin Finck 
2561*c2c66affSColin Finck     if (pulLength == NULL)
2562*c2c66affSColin Finck         return CR_INVALID_POINTER;
2563*c2c66affSColin Finck 
2564*c2c66affSColin Finck     if (*pulLength == 0)
2565*c2c66affSColin Finck         return CR_INVALID_POINTER;
2566*c2c66affSColin Finck 
2567*c2c66affSColin Finck     if (ulFlags != 0)
2568*c2c66affSColin Finck         return CR_INVALID_FLAG;
2569*c2c66affSColin Finck 
2570*c2c66affSColin Finck     if (hMachine != NULL)
2571*c2c66affSColin Finck     {
2572*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2573*c2c66affSColin Finck         if (BindingHandle == NULL)
2574*c2c66affSColin Finck             return CR_FAILURE;
2575*c2c66affSColin Finck 
2576*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2577*c2c66affSColin Finck         if (StringTable == 0)
2578*c2c66affSColin Finck             return CR_FAILURE;
2579*c2c66affSColin Finck     }
2580*c2c66affSColin Finck     else
2581*c2c66affSColin Finck     {
2582*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2583*c2c66affSColin Finck             return CR_FAILURE;
2584*c2c66affSColin Finck     }
2585*c2c66affSColin Finck 
2586*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2587*c2c66affSColin Finck     if (lpDevInst == NULL)
2588*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
2589*c2c66affSColin Finck 
2590*c2c66affSColin Finck     ulTransferLength = *pulLength;
2591*c2c66affSColin Finck 
2592*c2c66affSColin Finck     RpcTryExcept
2593*c2c66affSColin Finck     {
2594*c2c66affSColin Finck         ret = PNP_GetDeviceRegProp(BindingHandle,
2595*c2c66affSColin Finck                                    lpDevInst,
2596*c2c66affSColin Finck                                    ulProperty,
2597*c2c66affSColin Finck                                    &ulDataType,
2598*c2c66affSColin Finck                                    Buffer,
2599*c2c66affSColin Finck                                    &ulTransferLength,
2600*c2c66affSColin Finck                                    pulLength,
2601*c2c66affSColin Finck                                    ulFlags);
2602*c2c66affSColin Finck     }
2603*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2604*c2c66affSColin Finck     {
2605*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2606*c2c66affSColin Finck     }
2607*c2c66affSColin Finck     RpcEndExcept;
2608*c2c66affSColin Finck 
2609*c2c66affSColin Finck     if (ret == CR_SUCCESS)
2610*c2c66affSColin Finck     {
2611*c2c66affSColin Finck         if (pulRegDataType != NULL)
2612*c2c66affSColin Finck             *pulRegDataType = ulDataType;
2613*c2c66affSColin Finck     }
2614*c2c66affSColin Finck 
2615*c2c66affSColin Finck     return ret;
2616*c2c66affSColin Finck }
2617*c2c66affSColin Finck 
2618*c2c66affSColin Finck 
2619*c2c66affSColin Finck /***********************************************************************
2620*c2c66affSColin Finck  * CM_Get_DevNode_Status [SETUPAPI.@]
2621*c2c66affSColin Finck  */
2622*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_DevNode_Status(
2623*c2c66affSColin Finck     PULONG pulStatus, PULONG pulProblemNumber, DEVINST dnDevInst,
2624*c2c66affSColin Finck     ULONG ulFlags)
2625*c2c66affSColin Finck {
2626*c2c66affSColin Finck     TRACE("%p %p %lx %lx\n",
2627*c2c66affSColin Finck           pulStatus, pulProblemNumber, dnDevInst, ulFlags);
2628*c2c66affSColin Finck     return CM_Get_DevNode_Status_Ex(pulStatus, pulProblemNumber, dnDevInst,
2629*c2c66affSColin Finck                                     ulFlags, NULL);
2630*c2c66affSColin Finck }
2631*c2c66affSColin Finck 
2632*c2c66affSColin Finck 
2633*c2c66affSColin Finck /***********************************************************************
2634*c2c66affSColin Finck  * CM_Get_DevNode_Status_Ex [SETUPAPI.@]
2635*c2c66affSColin Finck  */
2636*c2c66affSColin Finck CONFIGRET WINAPI
2637*c2c66affSColin Finck CM_Get_DevNode_Status_Ex(
2638*c2c66affSColin Finck     PULONG pulStatus, PULONG pulProblemNumber, DEVINST dnDevInst,
2639*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
2640*c2c66affSColin Finck {
2641*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
2642*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
2643*c2c66affSColin Finck     LPWSTR lpDevInst;
2644*c2c66affSColin Finck     CONFIGRET ret;
2645*c2c66affSColin Finck 
2646*c2c66affSColin Finck     TRACE("%p %p %lx %lx %lx\n",
2647*c2c66affSColin Finck           pulStatus, pulProblemNumber, dnDevInst, ulFlags, hMachine);
2648*c2c66affSColin Finck 
2649*c2c66affSColin Finck     if (pulStatus == NULL || pulProblemNumber == NULL)
2650*c2c66affSColin Finck         return CR_INVALID_POINTER;
2651*c2c66affSColin Finck 
2652*c2c66affSColin Finck     if (dnDevInst == 0)
2653*c2c66affSColin Finck         return CR_INVALID_DEVINST;
2654*c2c66affSColin Finck 
2655*c2c66affSColin Finck     if (ulFlags != 0)
2656*c2c66affSColin Finck         return CR_INVALID_FLAG;
2657*c2c66affSColin Finck 
2658*c2c66affSColin Finck     if (hMachine != NULL)
2659*c2c66affSColin Finck     {
2660*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2661*c2c66affSColin Finck         if (BindingHandle == NULL)
2662*c2c66affSColin Finck             return CR_FAILURE;
2663*c2c66affSColin Finck 
2664*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2665*c2c66affSColin Finck         if (StringTable == 0)
2666*c2c66affSColin Finck             return CR_FAILURE;
2667*c2c66affSColin Finck     }
2668*c2c66affSColin Finck     else
2669*c2c66affSColin Finck     {
2670*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2671*c2c66affSColin Finck             return CR_FAILURE;
2672*c2c66affSColin Finck     }
2673*c2c66affSColin Finck 
2674*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2675*c2c66affSColin Finck     if (lpDevInst == NULL)
2676*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
2677*c2c66affSColin Finck 
2678*c2c66affSColin Finck     RpcTryExcept
2679*c2c66affSColin Finck     {
2680*c2c66affSColin Finck         ret = PNP_GetDeviceStatus(BindingHandle,
2681*c2c66affSColin Finck                                   lpDevInst,
2682*c2c66affSColin Finck                                   pulStatus,
2683*c2c66affSColin Finck                                   pulProblemNumber,
2684*c2c66affSColin Finck                                   ulFlags);
2685*c2c66affSColin Finck     }
2686*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2687*c2c66affSColin Finck     {
2688*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2689*c2c66affSColin Finck     }
2690*c2c66affSColin Finck     RpcEndExcept;
2691*c2c66affSColin Finck 
2692*c2c66affSColin Finck     return ret;
2693*c2c66affSColin Finck }
2694*c2c66affSColin Finck 
2695*c2c66affSColin Finck 
2696*c2c66affSColin Finck /***********************************************************************
2697*c2c66affSColin Finck  * CM_Get_Device_IDA [SETUPAPI.@]
2698*c2c66affSColin Finck  */
2699*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_IDA(
2700*c2c66affSColin Finck     DEVINST dnDevInst, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
2701*c2c66affSColin Finck {
2702*c2c66affSColin Finck     TRACE("%lx %p %ld %ld\n",
2703*c2c66affSColin Finck           dnDevInst, Buffer, BufferLen, ulFlags);
2704*c2c66affSColin Finck     return CM_Get_Device_ID_ExA(dnDevInst, Buffer, BufferLen, ulFlags, NULL);
2705*c2c66affSColin Finck }
2706*c2c66affSColin Finck 
2707*c2c66affSColin Finck 
2708*c2c66affSColin Finck /***********************************************************************
2709*c2c66affSColin Finck  * CM_Get_Device_IDW [SETUPAPI.@]
2710*c2c66affSColin Finck  */
2711*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_IDW(
2712*c2c66affSColin Finck     DEVINST dnDevInst, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
2713*c2c66affSColin Finck {
2714*c2c66affSColin Finck     TRACE("%lx %p %ld %ld\n",
2715*c2c66affSColin Finck           dnDevInst, Buffer, BufferLen, ulFlags);
2716*c2c66affSColin Finck     return CM_Get_Device_ID_ExW(dnDevInst, Buffer, BufferLen, ulFlags, NULL);
2717*c2c66affSColin Finck }
2718*c2c66affSColin Finck 
2719*c2c66affSColin Finck 
2720*c2c66affSColin Finck /***********************************************************************
2721*c2c66affSColin Finck  * CM_Get_Device_ID_ExA [SETUPAPI.@]
2722*c2c66affSColin Finck  */
2723*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_ID_ExA(
2724*c2c66affSColin Finck     DEVINST dnDevInst, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
2725*c2c66affSColin Finck     HMACHINE hMachine)
2726*c2c66affSColin Finck {
2727*c2c66affSColin Finck     WCHAR szBufferW[MAX_DEVICE_ID_LEN];
2728*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
2729*c2c66affSColin Finck 
2730*c2c66affSColin Finck     TRACE("%lx %p %ld %ld %lx\n",
2731*c2c66affSColin Finck           dnDevInst, Buffer, BufferLen, ulFlags, hMachine);
2732*c2c66affSColin Finck 
2733*c2c66affSColin Finck     if (Buffer == NULL)
2734*c2c66affSColin Finck         return CR_INVALID_POINTER;
2735*c2c66affSColin Finck 
2736*c2c66affSColin Finck     ret = CM_Get_Device_ID_ExW(dnDevInst,
2737*c2c66affSColin Finck                                szBufferW,
2738*c2c66affSColin Finck                                MAX_DEVICE_ID_LEN,
2739*c2c66affSColin Finck                                ulFlags,
2740*c2c66affSColin Finck                                hMachine);
2741*c2c66affSColin Finck     if (ret == CR_SUCCESS)
2742*c2c66affSColin Finck     {
2743*c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
2744*c2c66affSColin Finck                                 0,
2745*c2c66affSColin Finck                                 szBufferW,
2746*c2c66affSColin Finck                                 lstrlenW(szBufferW) + 1,
2747*c2c66affSColin Finck                                 Buffer,
2748*c2c66affSColin Finck                                 BufferLen,
2749*c2c66affSColin Finck                                 NULL,
2750*c2c66affSColin Finck                                 NULL) == 0)
2751*c2c66affSColin Finck             ret = CR_FAILURE;
2752*c2c66affSColin Finck     }
2753*c2c66affSColin Finck 
2754*c2c66affSColin Finck     return ret;
2755*c2c66affSColin Finck }
2756*c2c66affSColin Finck 
2757*c2c66affSColin Finck 
2758*c2c66affSColin Finck /***********************************************************************
2759*c2c66affSColin Finck  * CM_Get_Device_ID_ExW [SETUPAPI.@]
2760*c2c66affSColin Finck  */
2761*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_ID_ExW(
2762*c2c66affSColin Finck     DEVINST dnDevInst, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
2763*c2c66affSColin Finck     HMACHINE hMachine)
2764*c2c66affSColin Finck {
2765*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
2766*c2c66affSColin Finck 
2767*c2c66affSColin Finck     TRACE("%lx %p %ld %ld %lx\n",
2768*c2c66affSColin Finck           dnDevInst, Buffer, BufferLen, ulFlags, hMachine);
2769*c2c66affSColin Finck 
2770*c2c66affSColin Finck     if (dnDevInst == 0)
2771*c2c66affSColin Finck         return CR_INVALID_DEVINST;
2772*c2c66affSColin Finck 
2773*c2c66affSColin Finck     if (Buffer == NULL)
2774*c2c66affSColin Finck         return CR_INVALID_POINTER;
2775*c2c66affSColin Finck 
2776*c2c66affSColin Finck     if (ulFlags != 0)
2777*c2c66affSColin Finck         return CR_INVALID_FLAG;
2778*c2c66affSColin Finck 
2779*c2c66affSColin Finck     if (hMachine != NULL)
2780*c2c66affSColin Finck     {
2781*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2782*c2c66affSColin Finck         if (StringTable == NULL)
2783*c2c66affSColin Finck             return CR_FAILURE;
2784*c2c66affSColin Finck     }
2785*c2c66affSColin Finck     else
2786*c2c66affSColin Finck     {
2787*c2c66affSColin Finck         if (!PnpGetLocalHandles(NULL, &StringTable))
2788*c2c66affSColin Finck             return CR_FAILURE;
2789*c2c66affSColin Finck     }
2790*c2c66affSColin Finck 
2791*c2c66affSColin Finck     if (!pSetupStringTableStringFromIdEx(StringTable,
2792*c2c66affSColin Finck                                          dnDevInst,
2793*c2c66affSColin Finck                                          Buffer,
2794*c2c66affSColin Finck                                          &BufferLen))
2795*c2c66affSColin Finck         return CR_FAILURE;
2796*c2c66affSColin Finck 
2797*c2c66affSColin Finck     return CR_SUCCESS;
2798*c2c66affSColin Finck }
2799*c2c66affSColin Finck 
2800*c2c66affSColin Finck 
2801*c2c66affSColin Finck /***********************************************************************
2802*c2c66affSColin Finck  * CM_Get_Device_ID_ListA [SETUPAPI.@]
2803*c2c66affSColin Finck  */
2804*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_ID_ListA(
2805*c2c66affSColin Finck     PCSTR pszFilter, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
2806*c2c66affSColin Finck {
2807*c2c66affSColin Finck     TRACE("%p %p %ld %ld\n", pszFilter, Buffer, BufferLen, ulFlags);
2808*c2c66affSColin Finck     return CM_Get_Device_ID_List_ExA(pszFilter, Buffer, BufferLen,
2809*c2c66affSColin Finck                                      ulFlags, NULL);
2810*c2c66affSColin Finck }
2811*c2c66affSColin Finck 
2812*c2c66affSColin Finck 
2813*c2c66affSColin Finck /***********************************************************************
2814*c2c66affSColin Finck  * CM_Get_Device_ID_ListW [SETUPAPI.@]
2815*c2c66affSColin Finck  */
2816*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_ID_ListW(
2817*c2c66affSColin Finck     PCWSTR pszFilter, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
2818*c2c66affSColin Finck {
2819*c2c66affSColin Finck     TRACE("%p %p %ld %ld\n", pszFilter, Buffer, BufferLen, ulFlags);
2820*c2c66affSColin Finck     return CM_Get_Device_ID_List_ExW(pszFilter, Buffer, BufferLen,
2821*c2c66affSColin Finck                                      ulFlags, NULL);
2822*c2c66affSColin Finck }
2823*c2c66affSColin Finck 
2824*c2c66affSColin Finck 
2825*c2c66affSColin Finck /***********************************************************************
2826*c2c66affSColin Finck  * CM_Get_Device_ID_List_ExA [SETUPAPI.@]
2827*c2c66affSColin Finck  */
2828*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_ID_List_ExA(
2829*c2c66affSColin Finck     PCSTR pszFilter, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
2830*c2c66affSColin Finck     HMACHINE hMachine)
2831*c2c66affSColin Finck {
2832*c2c66affSColin Finck     LPWSTR BufferW = NULL;
2833*c2c66affSColin Finck     LPWSTR pszFilterW = NULL;
2834*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
2835*c2c66affSColin Finck 
2836*c2c66affSColin Finck     TRACE("%p %p %ld %ld %lx\n",
2837*c2c66affSColin Finck           pszFilter, Buffer, BufferLen, ulFlags, hMachine);
2838*c2c66affSColin Finck 
2839*c2c66affSColin Finck     BufferW = MyMalloc(BufferLen * sizeof(WCHAR));
2840*c2c66affSColin Finck     if (BufferW == NULL)
2841*c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
2842*c2c66affSColin Finck 
2843*c2c66affSColin Finck     if (pszFilter == NULL)
2844*c2c66affSColin Finck     {
2845*c2c66affSColin Finck         ret = CM_Get_Device_ID_List_ExW(NULL,
2846*c2c66affSColin Finck                                         BufferW,
2847*c2c66affSColin Finck                                         BufferLen,
2848*c2c66affSColin Finck                                         ulFlags,
2849*c2c66affSColin Finck                                         hMachine);
2850*c2c66affSColin Finck     }
2851*c2c66affSColin Finck     else
2852*c2c66affSColin Finck     {
2853*c2c66affSColin Finck         if (pSetupCaptureAndConvertAnsiArg(pszFilter, &pszFilterW))
2854*c2c66affSColin Finck         {
2855*c2c66affSColin Finck             ret = CR_INVALID_DEVICE_ID;
2856*c2c66affSColin Finck             goto Done;
2857*c2c66affSColin Finck         }
2858*c2c66affSColin Finck 
2859*c2c66affSColin Finck         ret = CM_Get_Device_ID_List_ExW(pszFilterW,
2860*c2c66affSColin Finck                                         BufferW,
2861*c2c66affSColin Finck                                         BufferLen,
2862*c2c66affSColin Finck                                         ulFlags,
2863*c2c66affSColin Finck                                         hMachine);
2864*c2c66affSColin Finck 
2865*c2c66affSColin Finck         MyFree(pszFilterW);
2866*c2c66affSColin Finck     }
2867*c2c66affSColin Finck 
2868*c2c66affSColin Finck     if (WideCharToMultiByte(CP_ACP,
2869*c2c66affSColin Finck                             0,
2870*c2c66affSColin Finck                             BufferW,
2871*c2c66affSColin Finck                             lstrlenW(BufferW) + 1,
2872*c2c66affSColin Finck                             Buffer,
2873*c2c66affSColin Finck                             BufferLen,
2874*c2c66affSColin Finck                             NULL,
2875*c2c66affSColin Finck                             NULL) == 0)
2876*c2c66affSColin Finck         ret = CR_FAILURE;
2877*c2c66affSColin Finck 
2878*c2c66affSColin Finck Done:
2879*c2c66affSColin Finck     MyFree(BufferW);
2880*c2c66affSColin Finck 
2881*c2c66affSColin Finck     return ret;
2882*c2c66affSColin Finck }
2883*c2c66affSColin Finck 
2884*c2c66affSColin Finck 
2885*c2c66affSColin Finck /***********************************************************************
2886*c2c66affSColin Finck  * CM_Get_Device_ID_List_ExW [SETUPAPI.@]
2887*c2c66affSColin Finck  */
2888*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_ID_List_ExW(
2889*c2c66affSColin Finck     PCWSTR pszFilter, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
2890*c2c66affSColin Finck     HMACHINE hMachine)
2891*c2c66affSColin Finck {
2892*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
2893*c2c66affSColin Finck     CONFIGRET ret;
2894*c2c66affSColin Finck 
2895*c2c66affSColin Finck     TRACE("%p %p %ld %ld %lx\n",
2896*c2c66affSColin Finck           pszFilter, Buffer, BufferLen, ulFlags, hMachine);
2897*c2c66affSColin Finck 
2898*c2c66affSColin Finck     if (Buffer == NULL || BufferLen == 0)
2899*c2c66affSColin Finck         return CR_INVALID_POINTER;
2900*c2c66affSColin Finck 
2901*c2c66affSColin Finck     if (ulFlags & ~CM_GETIDLIST_FILTER_BITS)
2902*c2c66affSColin Finck         return CR_INVALID_FLAG;
2903*c2c66affSColin Finck 
2904*c2c66affSColin Finck     if (hMachine != NULL)
2905*c2c66affSColin Finck     {
2906*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2907*c2c66affSColin Finck         if (BindingHandle == NULL)
2908*c2c66affSColin Finck             return CR_FAILURE;
2909*c2c66affSColin Finck     }
2910*c2c66affSColin Finck     else
2911*c2c66affSColin Finck     {
2912*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
2913*c2c66affSColin Finck             return CR_FAILURE;
2914*c2c66affSColin Finck     }
2915*c2c66affSColin Finck 
2916*c2c66affSColin Finck     *Buffer = 0;
2917*c2c66affSColin Finck 
2918*c2c66affSColin Finck     RpcTryExcept
2919*c2c66affSColin Finck     {
2920*c2c66affSColin Finck         ret = PNP_GetDeviceList(BindingHandle,
2921*c2c66affSColin Finck                                 (LPWSTR)pszFilter,
2922*c2c66affSColin Finck                                 Buffer,
2923*c2c66affSColin Finck                                 &BufferLen,
2924*c2c66affSColin Finck                                 ulFlags);
2925*c2c66affSColin Finck     }
2926*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2927*c2c66affSColin Finck     {
2928*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2929*c2c66affSColin Finck     }
2930*c2c66affSColin Finck     RpcEndExcept;
2931*c2c66affSColin Finck 
2932*c2c66affSColin Finck     return ret;
2933*c2c66affSColin Finck }
2934*c2c66affSColin Finck 
2935*c2c66affSColin Finck 
2936*c2c66affSColin Finck /***********************************************************************
2937*c2c66affSColin Finck  * CM_Get_Device_ID_List_SizeA [SETUPAPI.@]
2938*c2c66affSColin Finck  */
2939*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_ID_List_SizeA(
2940*c2c66affSColin Finck     PULONG pulLen, PCSTR pszFilter, ULONG ulFlags)
2941*c2c66affSColin Finck {
2942*c2c66affSColin Finck     TRACE("%p %s %ld\n", pulLen, pszFilter, ulFlags);
2943*c2c66affSColin Finck     return CM_Get_Device_ID_List_Size_ExA(pulLen, pszFilter, ulFlags, NULL);
2944*c2c66affSColin Finck }
2945*c2c66affSColin Finck 
2946*c2c66affSColin Finck 
2947*c2c66affSColin Finck /***********************************************************************
2948*c2c66affSColin Finck  * CM_Get_Device_ID_List_SizeW [SETUPAPI.@]
2949*c2c66affSColin Finck  */
2950*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_ID_List_SizeW(
2951*c2c66affSColin Finck     PULONG pulLen, PCWSTR pszFilter, ULONG ulFlags)
2952*c2c66affSColin Finck {
2953*c2c66affSColin Finck     TRACE("%p %s %ld\n", pulLen, debugstr_w(pszFilter), ulFlags);
2954*c2c66affSColin Finck     return CM_Get_Device_ID_List_Size_ExW(pulLen, pszFilter, ulFlags, NULL);
2955*c2c66affSColin Finck }
2956*c2c66affSColin Finck 
2957*c2c66affSColin Finck 
2958*c2c66affSColin Finck /***********************************************************************
2959*c2c66affSColin Finck  * CM_Get_Device_ID_List_Size_ExA [SETUPAPI.@]
2960*c2c66affSColin Finck  */
2961*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_ID_List_Size_ExA(
2962*c2c66affSColin Finck     PULONG pulLen, PCSTR pszFilter, ULONG ulFlags, HMACHINE hMachine)
2963*c2c66affSColin Finck {
2964*c2c66affSColin Finck     LPWSTR pszFilterW = NULL;
2965*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
2966*c2c66affSColin Finck 
2967*c2c66affSColin Finck     FIXME("%p %s %lx %lx\n", pulLen, pszFilter, ulFlags, hMachine);
2968*c2c66affSColin Finck 
2969*c2c66affSColin Finck     if (pszFilter == NULL)
2970*c2c66affSColin Finck     {
2971*c2c66affSColin Finck         ret = CM_Get_Device_ID_List_Size_ExW(pulLen,
2972*c2c66affSColin Finck                                              NULL,
2973*c2c66affSColin Finck                                              ulFlags,
2974*c2c66affSColin Finck                                              hMachine);
2975*c2c66affSColin Finck     }
2976*c2c66affSColin Finck     else
2977*c2c66affSColin Finck     {
2978*c2c66affSColin Finck         if (pSetupCaptureAndConvertAnsiArg(pszFilter, &pszFilterW))
2979*c2c66affSColin Finck             return CR_INVALID_DEVICE_ID;
2980*c2c66affSColin Finck 
2981*c2c66affSColin Finck         ret = CM_Get_Device_ID_List_Size_ExW(pulLen,
2982*c2c66affSColin Finck                                              pszFilterW,
2983*c2c66affSColin Finck                                              ulFlags,
2984*c2c66affSColin Finck                                              hMachine);
2985*c2c66affSColin Finck 
2986*c2c66affSColin Finck         MyFree(pszFilterW);
2987*c2c66affSColin Finck     }
2988*c2c66affSColin Finck 
2989*c2c66affSColin Finck     return ret;
2990*c2c66affSColin Finck }
2991*c2c66affSColin Finck 
2992*c2c66affSColin Finck 
2993*c2c66affSColin Finck /***********************************************************************
2994*c2c66affSColin Finck  * CM_Get_Device_ID_List_Size_ExW [SETUPAPI.@]
2995*c2c66affSColin Finck  */
2996*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_ID_List_Size_ExW(
2997*c2c66affSColin Finck     PULONG pulLen, PCWSTR pszFilter, ULONG ulFlags, HMACHINE hMachine)
2998*c2c66affSColin Finck {
2999*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3000*c2c66affSColin Finck     CONFIGRET ret;
3001*c2c66affSColin Finck 
3002*c2c66affSColin Finck     FIXME("%p %s %ld %lx\n", pulLen, debugstr_w(pszFilter), ulFlags, hMachine);
3003*c2c66affSColin Finck 
3004*c2c66affSColin Finck     if (pulLen == NULL)
3005*c2c66affSColin Finck         return CR_INVALID_POINTER;
3006*c2c66affSColin Finck 
3007*c2c66affSColin Finck     if (ulFlags & ~CM_GETIDLIST_FILTER_BITS)
3008*c2c66affSColin Finck         return CR_INVALID_FLAG;
3009*c2c66affSColin Finck 
3010*c2c66affSColin Finck     if (hMachine != NULL)
3011*c2c66affSColin Finck     {
3012*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3013*c2c66affSColin Finck         if (BindingHandle == NULL)
3014*c2c66affSColin Finck             return CR_FAILURE;
3015*c2c66affSColin Finck     }
3016*c2c66affSColin Finck     else
3017*c2c66affSColin Finck     {
3018*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
3019*c2c66affSColin Finck             return CR_FAILURE;
3020*c2c66affSColin Finck     }
3021*c2c66affSColin Finck 
3022*c2c66affSColin Finck     *pulLen = 0;
3023*c2c66affSColin Finck 
3024*c2c66affSColin Finck     RpcTryExcept
3025*c2c66affSColin Finck     {
3026*c2c66affSColin Finck         ret = PNP_GetDeviceListSize(BindingHandle,
3027*c2c66affSColin Finck                                     (LPWSTR)pszFilter,
3028*c2c66affSColin Finck                                     pulLen,
3029*c2c66affSColin Finck                                     ulFlags);
3030*c2c66affSColin Finck     }
3031*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3032*c2c66affSColin Finck     {
3033*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3034*c2c66affSColin Finck     }
3035*c2c66affSColin Finck     RpcEndExcept;
3036*c2c66affSColin Finck 
3037*c2c66affSColin Finck     return ret;
3038*c2c66affSColin Finck }
3039*c2c66affSColin Finck 
3040*c2c66affSColin Finck 
3041*c2c66affSColin Finck /***********************************************************************
3042*c2c66affSColin Finck  * CM_Get_Device_ID_Size [SETUPAPI.@]
3043*c2c66affSColin Finck  */
3044*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_ID_Size(
3045*c2c66affSColin Finck     PULONG pulLen, DEVINST dnDevInst, ULONG ulFlags)
3046*c2c66affSColin Finck {
3047*c2c66affSColin Finck     TRACE("%p %lx %lx\n", pulLen, dnDevInst, ulFlags);
3048*c2c66affSColin Finck     return CM_Get_Device_ID_Size_Ex(pulLen, dnDevInst, ulFlags, NULL);
3049*c2c66affSColin Finck }
3050*c2c66affSColin Finck 
3051*c2c66affSColin Finck 
3052*c2c66affSColin Finck /***********************************************************************
3053*c2c66affSColin Finck  * CM_Get_Device_ID_Size_Ex [SETUPAPI.@]
3054*c2c66affSColin Finck  */
3055*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_ID_Size_Ex(
3056*c2c66affSColin Finck     PULONG pulLen, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
3057*c2c66affSColin Finck {
3058*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
3059*c2c66affSColin Finck     LPWSTR DeviceId;
3060*c2c66affSColin Finck 
3061*c2c66affSColin Finck     TRACE("%p %lx %lx %lx\n", pulLen, dnDevInst, ulFlags, hMachine);
3062*c2c66affSColin Finck 
3063*c2c66affSColin Finck     if (pulLen == NULL)
3064*c2c66affSColin Finck         return CR_INVALID_POINTER;
3065*c2c66affSColin Finck 
3066*c2c66affSColin Finck     if (dnDevInst == 0)
3067*c2c66affSColin Finck         return CR_INVALID_DEVINST;
3068*c2c66affSColin Finck 
3069*c2c66affSColin Finck     if (ulFlags != 0)
3070*c2c66affSColin Finck         return CR_INVALID_FLAG;
3071*c2c66affSColin Finck 
3072*c2c66affSColin Finck     if (hMachine != NULL)
3073*c2c66affSColin Finck     {
3074*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3075*c2c66affSColin Finck         if (StringTable == NULL)
3076*c2c66affSColin Finck             return CR_FAILURE;
3077*c2c66affSColin Finck     }
3078*c2c66affSColin Finck     else
3079*c2c66affSColin Finck     {
3080*c2c66affSColin Finck         if (!PnpGetLocalHandles(NULL, &StringTable))
3081*c2c66affSColin Finck             return CR_FAILURE;
3082*c2c66affSColin Finck     }
3083*c2c66affSColin Finck 
3084*c2c66affSColin Finck     DeviceId = pSetupStringTableStringFromId(StringTable, dnDevInst);
3085*c2c66affSColin Finck     if (DeviceId == NULL)
3086*c2c66affSColin Finck     {
3087*c2c66affSColin Finck         *pulLen = 0;
3088*c2c66affSColin Finck         return CR_SUCCESS;
3089*c2c66affSColin Finck     }
3090*c2c66affSColin Finck 
3091*c2c66affSColin Finck     *pulLen = lstrlenW(DeviceId);
3092*c2c66affSColin Finck 
3093*c2c66affSColin Finck     return CR_SUCCESS;
3094*c2c66affSColin Finck }
3095*c2c66affSColin Finck 
3096*c2c66affSColin Finck 
3097*c2c66affSColin Finck /***********************************************************************
3098*c2c66affSColin Finck  * CM_Get_Device_Interface_AliasA [SETUPAPI.@]
3099*c2c66affSColin Finck  */
3100*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_Interface_AliasA(
3101*c2c66affSColin Finck     LPCSTR pszDeviceInterface, LPGUID AliasInterfaceGuid,
3102*c2c66affSColin Finck     LPSTR pszAliasDeviceInterface, PULONG pulLength, ULONG ulFlags)
3103*c2c66affSColin Finck {
3104*c2c66affSColin Finck     TRACE("%p %p %p %p %lu\n", pszDeviceInterface, AliasInterfaceGuid,
3105*c2c66affSColin Finck           pszAliasDeviceInterface, pulLength, ulFlags);
3106*c2c66affSColin Finck 
3107*c2c66affSColin Finck     return CM_Get_Device_Interface_Alias_ExA(pszDeviceInterface,
3108*c2c66affSColin Finck         AliasInterfaceGuid, pszAliasDeviceInterface, pulLength,
3109*c2c66affSColin Finck         ulFlags, NULL);
3110*c2c66affSColin Finck }
3111*c2c66affSColin Finck 
3112*c2c66affSColin Finck 
3113*c2c66affSColin Finck /***********************************************************************
3114*c2c66affSColin Finck  * CM_Get_Device_Interface_AliasW [SETUPAPI.@]
3115*c2c66affSColin Finck  */
3116*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_Interface_AliasW(
3117*c2c66affSColin Finck     LPCWSTR pszDeviceInterface, LPGUID AliasInterfaceGuid,
3118*c2c66affSColin Finck     LPWSTR pszAliasDeviceInterface, PULONG pulLength, ULONG ulFlags)
3119*c2c66affSColin Finck {
3120*c2c66affSColin Finck     TRACE("%p %p %p %p %lu\n", pszDeviceInterface, AliasInterfaceGuid,
3121*c2c66affSColin Finck           pszAliasDeviceInterface, pulLength, ulFlags);
3122*c2c66affSColin Finck 
3123*c2c66affSColin Finck     return CM_Get_Device_Interface_Alias_ExW(pszDeviceInterface,
3124*c2c66affSColin Finck         AliasInterfaceGuid, pszAliasDeviceInterface, pulLength,
3125*c2c66affSColin Finck         ulFlags, NULL);
3126*c2c66affSColin Finck }
3127*c2c66affSColin Finck 
3128*c2c66affSColin Finck 
3129*c2c66affSColin Finck /***********************************************************************
3130*c2c66affSColin Finck  * CM_Get_Device_Interface_Alias_ExA [SETUPAPI.@]
3131*c2c66affSColin Finck  */
3132*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_Interface_Alias_ExA(
3133*c2c66affSColin Finck     LPCSTR pszDeviceInterface, LPGUID AliasInterfaceGuid, LPSTR pszAliasDeviceInterface,
3134*c2c66affSColin Finck     PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
3135*c2c66affSColin Finck {
3136*c2c66affSColin Finck     FIXME("%p %p %p %p %lu %lx\n", pszDeviceInterface, AliasInterfaceGuid,
3137*c2c66affSColin Finck           pszAliasDeviceInterface, pulLength, ulFlags, hMachine);
3138*c2c66affSColin Finck 
3139*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
3140*c2c66affSColin Finck }
3141*c2c66affSColin Finck 
3142*c2c66affSColin Finck 
3143*c2c66affSColin Finck /***********************************************************************
3144*c2c66affSColin Finck  * CM_Get_Device_Interface_Alias_ExW [SETUPAPI.@]
3145*c2c66affSColin Finck  */
3146*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_Interface_Alias_ExW(
3147*c2c66affSColin Finck     LPCWSTR pszDeviceInterface, LPGUID AliasInterfaceGuid, LPWSTR pszAliasDeviceInterface,
3148*c2c66affSColin Finck     PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
3149*c2c66affSColin Finck {
3150*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3151*c2c66affSColin Finck     ULONG ulTransferLength;
3152*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
3153*c2c66affSColin Finck 
3154*c2c66affSColin Finck     TRACE("%p %p %p %p %lu %lx\n", pszDeviceInterface, AliasInterfaceGuid,
3155*c2c66affSColin Finck           pszAliasDeviceInterface, pulLength, ulFlags, hMachine);
3156*c2c66affSColin Finck 
3157*c2c66affSColin Finck     if (pszDeviceInterface == NULL ||
3158*c2c66affSColin Finck         AliasInterfaceGuid == NULL ||
3159*c2c66affSColin Finck         pszAliasDeviceInterface == NULL ||
3160*c2c66affSColin Finck         pulLength == NULL)
3161*c2c66affSColin Finck         return CR_INVALID_POINTER;
3162*c2c66affSColin Finck 
3163*c2c66affSColin Finck     if (ulFlags != 0)
3164*c2c66affSColin Finck         return CR_INVALID_FLAG;
3165*c2c66affSColin Finck 
3166*c2c66affSColin Finck     if (hMachine != NULL)
3167*c2c66affSColin Finck     {
3168*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3169*c2c66affSColin Finck         if (BindingHandle == NULL)
3170*c2c66affSColin Finck             return CR_FAILURE;
3171*c2c66affSColin Finck     }
3172*c2c66affSColin Finck     else
3173*c2c66affSColin Finck     {
3174*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
3175*c2c66affSColin Finck             return CR_FAILURE;
3176*c2c66affSColin Finck     }
3177*c2c66affSColin Finck 
3178*c2c66affSColin Finck     ulTransferLength = *pulLength;
3179*c2c66affSColin Finck 
3180*c2c66affSColin Finck     RpcTryExcept
3181*c2c66affSColin Finck     {
3182*c2c66affSColin Finck         ret = PNP_GetInterfaceDeviceAlias(BindingHandle,
3183*c2c66affSColin Finck                                           (LPWSTR)pszDeviceInterface,
3184*c2c66affSColin Finck                                           AliasInterfaceGuid,
3185*c2c66affSColin Finck                                           pszAliasDeviceInterface,
3186*c2c66affSColin Finck                                           pulLength,
3187*c2c66affSColin Finck                                           &ulTransferLength,
3188*c2c66affSColin Finck                                           0);
3189*c2c66affSColin Finck     }
3190*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3191*c2c66affSColin Finck     {
3192*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3193*c2c66affSColin Finck     }
3194*c2c66affSColin Finck     RpcEndExcept;
3195*c2c66affSColin Finck 
3196*c2c66affSColin Finck     return ret;
3197*c2c66affSColin Finck }
3198*c2c66affSColin Finck 
3199*c2c66affSColin Finck 
3200*c2c66affSColin Finck /***********************************************************************
3201*c2c66affSColin Finck  *      CM_Get_Device_Interface_ListA (SETUPAPI.@)
3202*c2c66affSColin Finck  */
3203*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_Interface_ListA(
3204*c2c66affSColin Finck     LPGUID InterfaceClassGuid, DEVINSTID_A pDeviceID, PCHAR Buffer,
3205*c2c66affSColin Finck     ULONG BufferLen, ULONG ulFlags)
3206*c2c66affSColin Finck {
3207*c2c66affSColin Finck     TRACE("%s %s %p %lu 0x%08lx\n", debugstr_guid(InterfaceClassGuid),
3208*c2c66affSColin Finck           pDeviceID, Buffer, BufferLen, ulFlags);
3209*c2c66affSColin Finck 
3210*c2c66affSColin Finck     return CM_Get_Device_Interface_List_ExA(InterfaceClassGuid, pDeviceID,
3211*c2c66affSColin Finck                                             Buffer, BufferLen, ulFlags, NULL);
3212*c2c66affSColin Finck }
3213*c2c66affSColin Finck 
3214*c2c66affSColin Finck 
3215*c2c66affSColin Finck /***********************************************************************
3216*c2c66affSColin Finck  *      CM_Get_Device_Interface_ListW (SETUPAPI.@)
3217*c2c66affSColin Finck  */
3218*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_Interface_ListW(
3219*c2c66affSColin Finck     LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceID, PWCHAR Buffer,
3220*c2c66affSColin Finck     ULONG BufferLen, ULONG ulFlags)
3221*c2c66affSColin Finck {
3222*c2c66affSColin Finck     TRACE("%s %s %p %lu 0x%08lx\n", debugstr_guid(InterfaceClassGuid),
3223*c2c66affSColin Finck           debugstr_w(pDeviceID), Buffer, BufferLen, ulFlags);
3224*c2c66affSColin Finck 
3225*c2c66affSColin Finck     return CM_Get_Device_Interface_List_ExW(InterfaceClassGuid, pDeviceID,
3226*c2c66affSColin Finck                                             Buffer, BufferLen, ulFlags, NULL);
3227*c2c66affSColin Finck }
3228*c2c66affSColin Finck 
3229*c2c66affSColin Finck 
3230*c2c66affSColin Finck /***********************************************************************
3231*c2c66affSColin Finck  *      CM_Get_Device_Interface_List_ExA (SETUPAPI.@)
3232*c2c66affSColin Finck  */
3233*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_Interface_List_ExA(
3234*c2c66affSColin Finck     LPGUID InterfaceClassGuid, DEVINSTID_A pDeviceID, PCHAR Buffer,
3235*c2c66affSColin Finck     ULONG BufferLen, ULONG ulFlags, HMACHINE hMachine)
3236*c2c66affSColin Finck {
3237*c2c66affSColin Finck     DEVINSTID_W pDeviceIdW = NULL;
3238*c2c66affSColin Finck     PWCHAR BufferW = NULL;
3239*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
3240*c2c66affSColin Finck 
3241*c2c66affSColin Finck     TRACE("%s %s %p %lu 0x%08lx %p\n", debugstr_guid(InterfaceClassGuid),
3242*c2c66affSColin Finck           pDeviceID, Buffer, BufferLen, ulFlags, hMachine);
3243*c2c66affSColin Finck 
3244*c2c66affSColin Finck     if (Buffer == NULL ||
3245*c2c66affSColin Finck         BufferLen == 0)
3246*c2c66affSColin Finck         return CR_INVALID_POINTER;
3247*c2c66affSColin Finck 
3248*c2c66affSColin Finck     if (pDeviceID != NULL)
3249*c2c66affSColin Finck     {
3250*c2c66affSColin Finck         if (!pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDeviceIdW))
3251*c2c66affSColin Finck             return CR_INVALID_DEVICE_ID;
3252*c2c66affSColin Finck     }
3253*c2c66affSColin Finck 
3254*c2c66affSColin Finck     BufferW = MyMalloc(BufferLen * sizeof(WCHAR));
3255*c2c66affSColin Finck     if (BufferW == NULL)
3256*c2c66affSColin Finck     {
3257*c2c66affSColin Finck         ret = CR_OUT_OF_MEMORY;
3258*c2c66affSColin Finck         goto Done;
3259*c2c66affSColin Finck     }
3260*c2c66affSColin Finck 
3261*c2c66affSColin Finck     ret = CM_Get_Device_Interface_List_ExW(InterfaceClassGuid, pDeviceIdW,
3262*c2c66affSColin Finck                                            BufferW, BufferLen, ulFlags,
3263*c2c66affSColin Finck                                            hMachine);
3264*c2c66affSColin Finck     if (ret != CR_SUCCESS)
3265*c2c66affSColin Finck         goto Done;
3266*c2c66affSColin Finck 
3267*c2c66affSColin Finck     if (WideCharToMultiByte(CP_ACP,
3268*c2c66affSColin Finck                             0,
3269*c2c66affSColin Finck                             BufferW,
3270*c2c66affSColin Finck                             lstrlenW(BufferW) + 1,
3271*c2c66affSColin Finck                             Buffer,
3272*c2c66affSColin Finck                             BufferLen,
3273*c2c66affSColin Finck                             NULL,
3274*c2c66affSColin Finck                             NULL) == 0)
3275*c2c66affSColin Finck         ret = CR_FAILURE;
3276*c2c66affSColin Finck 
3277*c2c66affSColin Finck Done:
3278*c2c66affSColin Finck     if (BufferW != NULL)
3279*c2c66affSColin Finck         MyFree(BufferW);
3280*c2c66affSColin Finck 
3281*c2c66affSColin Finck     if (pDeviceIdW != NULL)
3282*c2c66affSColin Finck         MyFree(pDeviceIdW);
3283*c2c66affSColin Finck 
3284*c2c66affSColin Finck     return ret;
3285*c2c66affSColin Finck }
3286*c2c66affSColin Finck 
3287*c2c66affSColin Finck 
3288*c2c66affSColin Finck /***********************************************************************
3289*c2c66affSColin Finck  *      CM_Get_Device_Interface_List_ExW (SETUPAPI.@)
3290*c2c66affSColin Finck  */
3291*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_Interface_List_ExW(
3292*c2c66affSColin Finck     LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceID, PWCHAR Buffer,
3293*c2c66affSColin Finck     ULONG BufferLen, ULONG ulFlags, HMACHINE hMachine)
3294*c2c66affSColin Finck {
3295*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3296*c2c66affSColin Finck     PNP_RPC_BUFFER_SIZE BufferSize = 0;
3297*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
3298*c2c66affSColin Finck 
3299*c2c66affSColin Finck     TRACE("%s %s %p %lu 0x%08lx %p\n", debugstr_guid(InterfaceClassGuid),
3300*c2c66affSColin Finck           debugstr_w(pDeviceID), Buffer, BufferLen, ulFlags, hMachine);
3301*c2c66affSColin Finck 
3302*c2c66affSColin Finck     if (Buffer == NULL ||
3303*c2c66affSColin Finck         BufferLen == 0)
3304*c2c66affSColin Finck         return CR_INVALID_POINTER;
3305*c2c66affSColin Finck 
3306*c2c66affSColin Finck     if (ulFlags & ~CM_GET_DEVICE_INTERFACE_LIST_BITS)
3307*c2c66affSColin Finck         return CR_INVALID_FLAG;
3308*c2c66affSColin Finck 
3309*c2c66affSColin Finck     if (hMachine != NULL)
3310*c2c66affSColin Finck     {
3311*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3312*c2c66affSColin Finck         if (BindingHandle == NULL)
3313*c2c66affSColin Finck             return CR_FAILURE;
3314*c2c66affSColin Finck     }
3315*c2c66affSColin Finck     else
3316*c2c66affSColin Finck     {
3317*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
3318*c2c66affSColin Finck             return CR_FAILURE;
3319*c2c66affSColin Finck     }
3320*c2c66affSColin Finck 
3321*c2c66affSColin Finck     *Buffer = 0;
3322*c2c66affSColin Finck     BufferSize = BufferLen;
3323*c2c66affSColin Finck 
3324*c2c66affSColin Finck     RpcTryExcept
3325*c2c66affSColin Finck     {
3326*c2c66affSColin Finck         ret = PNP_GetInterfaceDeviceList(BindingHandle,
3327*c2c66affSColin Finck                                          InterfaceClassGuid,
3328*c2c66affSColin Finck                                          pDeviceID,
3329*c2c66affSColin Finck                                          (LPBYTE)Buffer,
3330*c2c66affSColin Finck                                          &BufferSize,
3331*c2c66affSColin Finck                                          ulFlags);
3332*c2c66affSColin Finck     }
3333*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3334*c2c66affSColin Finck     {
3335*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3336*c2c66affSColin Finck     }
3337*c2c66affSColin Finck     RpcEndExcept;
3338*c2c66affSColin Finck 
3339*c2c66affSColin Finck     return ret;
3340*c2c66affSColin Finck }
3341*c2c66affSColin Finck 
3342*c2c66affSColin Finck 
3343*c2c66affSColin Finck /***********************************************************************
3344*c2c66affSColin Finck  *      CM_Get_Device_Interface_List_SizeA (SETUPAPI.@)
3345*c2c66affSColin Finck  */
3346*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_Interface_List_SizeA(
3347*c2c66affSColin Finck     PULONG pulLen, LPGUID InterfaceClassGuid, DEVINSTID_A pDeviceId,
3348*c2c66affSColin Finck     ULONG ulFlags)
3349*c2c66affSColin Finck {
3350*c2c66affSColin Finck     TRACE("%p %p %s 0x%08lx\n", pulLen, InterfaceClassGuid,
3351*c2c66affSColin Finck           pDeviceId, ulFlags);
3352*c2c66affSColin Finck 
3353*c2c66affSColin Finck     return CM_Get_Device_Interface_List_Size_ExA(pulLen, InterfaceClassGuid,
3354*c2c66affSColin Finck                                                  pDeviceId, ulFlags, NULL);
3355*c2c66affSColin Finck }
3356*c2c66affSColin Finck 
3357*c2c66affSColin Finck 
3358*c2c66affSColin Finck /***********************************************************************
3359*c2c66affSColin Finck  *      CM_Get_Device_Interface_List_SizeW (SETUPAPI.@)
3360*c2c66affSColin Finck  */
3361*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_Interface_List_SizeW(
3362*c2c66affSColin Finck     PULONG pulLen, LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceId,
3363*c2c66affSColin Finck     ULONG ulFlags)
3364*c2c66affSColin Finck {
3365*c2c66affSColin Finck     TRACE("%p %p %s 0x%08lx\n", pulLen, InterfaceClassGuid,
3366*c2c66affSColin Finck           debugstr_w(pDeviceId), ulFlags);
3367*c2c66affSColin Finck 
3368*c2c66affSColin Finck     return CM_Get_Device_Interface_List_Size_ExW(pulLen, InterfaceClassGuid,
3369*c2c66affSColin Finck                                                  pDeviceId, ulFlags, NULL);
3370*c2c66affSColin Finck }
3371*c2c66affSColin Finck 
3372*c2c66affSColin Finck 
3373*c2c66affSColin Finck /***********************************************************************
3374*c2c66affSColin Finck  *      CM_Get_Device_Interface_List_Size_ExA (SETUPAPI.@)
3375*c2c66affSColin Finck  */
3376*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_Interface_List_Size_ExA(
3377*c2c66affSColin Finck     PULONG pulLen, LPGUID InterfaceClassGuid, DEVINSTID_A pDeviceId,
3378*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
3379*c2c66affSColin Finck {
3380*c2c66affSColin Finck     DEVINSTID_W pDeviceIdW = NULL;
3381*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
3382*c2c66affSColin Finck 
3383*c2c66affSColin Finck     TRACE("%p %p %s 0x%08lx %p\n", pulLen, InterfaceClassGuid,
3384*c2c66affSColin Finck           pDeviceId, ulFlags, hMachine);
3385*c2c66affSColin Finck 
3386*c2c66affSColin Finck     if (pulLen == NULL)
3387*c2c66affSColin Finck         return CR_INVALID_POINTER;
3388*c2c66affSColin Finck 
3389*c2c66affSColin Finck     if (pDeviceId != NULL)
3390*c2c66affSColin Finck     {
3391*c2c66affSColin Finck         if (!pSetupCaptureAndConvertAnsiArg(pDeviceId, &pDeviceIdW))
3392*c2c66affSColin Finck             return CR_INVALID_DEVICE_ID;
3393*c2c66affSColin Finck     }
3394*c2c66affSColin Finck 
3395*c2c66affSColin Finck     *pulLen = 0;
3396*c2c66affSColin Finck 
3397*c2c66affSColin Finck     ret = CM_Get_Device_Interface_List_Size_ExW(pulLen, InterfaceClassGuid,
3398*c2c66affSColin Finck                                                 pDeviceIdW, ulFlags, hMachine);
3399*c2c66affSColin Finck 
3400*c2c66affSColin Finck     if (pDeviceIdW != NULL)
3401*c2c66affSColin Finck         MyFree(pDeviceIdW);
3402*c2c66affSColin Finck 
3403*c2c66affSColin Finck     return ret;
3404*c2c66affSColin Finck }
3405*c2c66affSColin Finck 
3406*c2c66affSColin Finck 
3407*c2c66affSColin Finck /***********************************************************************
3408*c2c66affSColin Finck  *      CM_Get_Device_Interface_List_Size_ExW (SETUPAPI.@)
3409*c2c66affSColin Finck  */
3410*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Device_Interface_List_Size_ExW(
3411*c2c66affSColin Finck     PULONG pulLen, LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceId,
3412*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
3413*c2c66affSColin Finck {
3414*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3415*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
3416*c2c66affSColin Finck 
3417*c2c66affSColin Finck     TRACE("%p %p %s 0x%08lx %p\n", pulLen, InterfaceClassGuid,
3418*c2c66affSColin Finck           debugstr_w(pDeviceId), ulFlags, hMachine);
3419*c2c66affSColin Finck 
3420*c2c66affSColin Finck     if (pulLen == NULL)
3421*c2c66affSColin Finck         return CR_INVALID_POINTER;
3422*c2c66affSColin Finck 
3423*c2c66affSColin Finck     if (ulFlags & ~CM_GET_DEVICE_INTERFACE_LIST_BITS)
3424*c2c66affSColin Finck         return CR_INVALID_FLAG;
3425*c2c66affSColin Finck 
3426*c2c66affSColin Finck     if (hMachine != NULL)
3427*c2c66affSColin Finck     {
3428*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3429*c2c66affSColin Finck         if (BindingHandle == NULL)
3430*c2c66affSColin Finck             return CR_FAILURE;
3431*c2c66affSColin Finck     }
3432*c2c66affSColin Finck     else
3433*c2c66affSColin Finck     {
3434*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
3435*c2c66affSColin Finck             return CR_FAILURE;
3436*c2c66affSColin Finck     }
3437*c2c66affSColin Finck 
3438*c2c66affSColin Finck     *pulLen = 0;
3439*c2c66affSColin Finck 
3440*c2c66affSColin Finck     RpcTryExcept
3441*c2c66affSColin Finck     {
3442*c2c66affSColin Finck         ret = PNP_GetInterfaceDeviceListSize(BindingHandle,
3443*c2c66affSColin Finck                                              pulLen,
3444*c2c66affSColin Finck                                              InterfaceClassGuid,
3445*c2c66affSColin Finck                                              pDeviceId,
3446*c2c66affSColin Finck                                              ulFlags);
3447*c2c66affSColin Finck     }
3448*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3449*c2c66affSColin Finck     {
3450*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3451*c2c66affSColin Finck     }
3452*c2c66affSColin Finck     RpcEndExcept;
3453*c2c66affSColin Finck 
3454*c2c66affSColin Finck     return ret;
3455*c2c66affSColin Finck }
3456*c2c66affSColin Finck 
3457*c2c66affSColin Finck 
3458*c2c66affSColin Finck /***********************************************************************
3459*c2c66affSColin Finck  * CM_Get_First_Log_Conf [SETUPAPI.@]
3460*c2c66affSColin Finck  */
3461*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_First_Log_Conf(
3462*c2c66affSColin Finck     PLOG_CONF plcLogConf, DEVINST dnDevInst, ULONG ulFlags)
3463*c2c66affSColin Finck {
3464*c2c66affSColin Finck     TRACE("%p %lx %lx\n", plcLogConf, dnDevInst, ulFlags);
3465*c2c66affSColin Finck     return CM_Get_First_Log_Conf_Ex(plcLogConf, dnDevInst, ulFlags, NULL);
3466*c2c66affSColin Finck }
3467*c2c66affSColin Finck 
3468*c2c66affSColin Finck 
3469*c2c66affSColin Finck /***********************************************************************
3470*c2c66affSColin Finck  * CM_Get_First_Log_Conf_Ex [SETUPAPI.@]
3471*c2c66affSColin Finck  */
3472*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_First_Log_Conf_Ex(
3473*c2c66affSColin Finck     PLOG_CONF plcLogConf, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
3474*c2c66affSColin Finck {
3475*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3476*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
3477*c2c66affSColin Finck     LPWSTR lpDevInst = NULL;
3478*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
3479*c2c66affSColin Finck     ULONG ulTag;
3480*c2c66affSColin Finck     PLOG_CONF_INFO pLogConfInfo;
3481*c2c66affSColin Finck 
3482*c2c66affSColin Finck     FIXME("%p %lx %lx %lx\n", plcLogConf, dnDevInst, ulFlags, hMachine);
3483*c2c66affSColin Finck 
3484*c2c66affSColin Finck     if (dnDevInst == 0)
3485*c2c66affSColin Finck         return CR_INVALID_DEVINST;
3486*c2c66affSColin Finck 
3487*c2c66affSColin Finck     if (ulFlags & ~LOG_CONF_BITS)
3488*c2c66affSColin Finck         return CR_INVALID_FLAG;
3489*c2c66affSColin Finck 
3490*c2c66affSColin Finck     if (plcLogConf)
3491*c2c66affSColin Finck         *plcLogConf = 0;
3492*c2c66affSColin Finck 
3493*c2c66affSColin Finck     if (hMachine != NULL)
3494*c2c66affSColin Finck     {
3495*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3496*c2c66affSColin Finck         if (BindingHandle == NULL)
3497*c2c66affSColin Finck             return CR_FAILURE;
3498*c2c66affSColin Finck 
3499*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3500*c2c66affSColin Finck         if (StringTable == 0)
3501*c2c66affSColin Finck             return CR_FAILURE;
3502*c2c66affSColin Finck     }
3503*c2c66affSColin Finck     else
3504*c2c66affSColin Finck     {
3505*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
3506*c2c66affSColin Finck             return CR_FAILURE;
3507*c2c66affSColin Finck     }
3508*c2c66affSColin Finck 
3509*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
3510*c2c66affSColin Finck     if (lpDevInst == NULL)
3511*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
3512*c2c66affSColin Finck 
3513*c2c66affSColin Finck     RpcTryExcept
3514*c2c66affSColin Finck     {
3515*c2c66affSColin Finck         ret = PNP_GetFirstLogConf(BindingHandle,
3516*c2c66affSColin Finck                                   lpDevInst,
3517*c2c66affSColin Finck                                   ulFlags,
3518*c2c66affSColin Finck                                   &ulTag,
3519*c2c66affSColin Finck                                   ulFlags);
3520*c2c66affSColin Finck     }
3521*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3522*c2c66affSColin Finck     {
3523*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3524*c2c66affSColin Finck     }
3525*c2c66affSColin Finck     RpcEndExcept;
3526*c2c66affSColin Finck 
3527*c2c66affSColin Finck     if (ret != CR_SUCCESS)
3528*c2c66affSColin Finck         return ret;
3529*c2c66affSColin Finck 
3530*c2c66affSColin Finck     if (plcLogConf)
3531*c2c66affSColin Finck     {
3532*c2c66affSColin Finck         pLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
3533*c2c66affSColin Finck         if (pLogConfInfo == NULL)
3534*c2c66affSColin Finck             return CR_OUT_OF_MEMORY;
3535*c2c66affSColin Finck 
3536*c2c66affSColin Finck         pLogConfInfo->ulMagic = LOG_CONF_MAGIC;
3537*c2c66affSColin Finck         pLogConfInfo->dnDevInst = dnDevInst;
3538*c2c66affSColin Finck         pLogConfInfo->ulFlags = ulFlags;
3539*c2c66affSColin Finck         pLogConfInfo->ulTag = ulTag;
3540*c2c66affSColin Finck 
3541*c2c66affSColin Finck         *plcLogConf = (LOG_CONF)pLogConfInfo;
3542*c2c66affSColin Finck     }
3543*c2c66affSColin Finck 
3544*c2c66affSColin Finck     return CR_SUCCESS;
3545*c2c66affSColin Finck }
3546*c2c66affSColin Finck 
3547*c2c66affSColin Finck 
3548*c2c66affSColin Finck /***********************************************************************
3549*c2c66affSColin Finck  * CM_Get_Global_State [SETUPAPI.@]
3550*c2c66affSColin Finck  */
3551*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Global_State(
3552*c2c66affSColin Finck     PULONG pulState, ULONG ulFlags)
3553*c2c66affSColin Finck {
3554*c2c66affSColin Finck     TRACE("%p %lx\n", pulState, ulFlags);
3555*c2c66affSColin Finck     return CM_Get_Global_State_Ex(pulState, ulFlags, NULL);
3556*c2c66affSColin Finck }
3557*c2c66affSColin Finck 
3558*c2c66affSColin Finck 
3559*c2c66affSColin Finck /***********************************************************************
3560*c2c66affSColin Finck  * CM_Get_Global_State_Ex [SETUPAPI.@]
3561*c2c66affSColin Finck  */
3562*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Global_State_Ex(
3563*c2c66affSColin Finck     PULONG pulState, ULONG ulFlags, HMACHINE hMachine)
3564*c2c66affSColin Finck {
3565*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3566*c2c66affSColin Finck     CONFIGRET ret;
3567*c2c66affSColin Finck 
3568*c2c66affSColin Finck     TRACE("%p %lx %lx\n", pulState, ulFlags, hMachine);
3569*c2c66affSColin Finck 
3570*c2c66affSColin Finck     if (pulState == NULL)
3571*c2c66affSColin Finck         return CR_INVALID_POINTER;
3572*c2c66affSColin Finck 
3573*c2c66affSColin Finck     if (ulFlags != 0)
3574*c2c66affSColin Finck         return CR_INVALID_FLAG;
3575*c2c66affSColin Finck 
3576*c2c66affSColin Finck     if (hMachine != NULL)
3577*c2c66affSColin Finck     {
3578*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3579*c2c66affSColin Finck         if (BindingHandle == NULL)
3580*c2c66affSColin Finck             return CR_FAILURE;
3581*c2c66affSColin Finck     }
3582*c2c66affSColin Finck     else
3583*c2c66affSColin Finck     {
3584*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
3585*c2c66affSColin Finck             return CR_FAILURE;
3586*c2c66affSColin Finck     }
3587*c2c66affSColin Finck 
3588*c2c66affSColin Finck     RpcTryExcept
3589*c2c66affSColin Finck     {
3590*c2c66affSColin Finck         ret = PNP_GetGlobalState(BindingHandle, pulState, ulFlags);
3591*c2c66affSColin Finck     }
3592*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3593*c2c66affSColin Finck     {
3594*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3595*c2c66affSColin Finck     }
3596*c2c66affSColin Finck     RpcEndExcept;
3597*c2c66affSColin Finck 
3598*c2c66affSColin Finck     return ret;
3599*c2c66affSColin Finck }
3600*c2c66affSColin Finck 
3601*c2c66affSColin Finck 
3602*c2c66affSColin Finck /***********************************************************************
3603*c2c66affSColin Finck  * CM_Get_HW_Prof_FlagsA [SETUPAPI.@]
3604*c2c66affSColin Finck  */
3605*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_HW_Prof_FlagsA(
3606*c2c66affSColin Finck     DEVINSTID_A szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
3607*c2c66affSColin Finck     ULONG ulFlags)
3608*c2c66affSColin Finck {
3609*c2c66affSColin Finck     TRACE("%s %lu %p %lx\n", szDevInstName,
3610*c2c66affSColin Finck           ulHardwareProfile, pulValue, ulFlags);
3611*c2c66affSColin Finck 
3612*c2c66affSColin Finck     return CM_Get_HW_Prof_Flags_ExA(szDevInstName, ulHardwareProfile,
3613*c2c66affSColin Finck                                     pulValue, ulFlags, NULL);
3614*c2c66affSColin Finck }
3615*c2c66affSColin Finck 
3616*c2c66affSColin Finck 
3617*c2c66affSColin Finck /***********************************************************************
3618*c2c66affSColin Finck  * CM_Get_HW_Prof_FlagsW [SETUPAPI.@]
3619*c2c66affSColin Finck  */
3620*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_HW_Prof_FlagsW(
3621*c2c66affSColin Finck     DEVINSTID_W szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
3622*c2c66affSColin Finck     ULONG ulFlags)
3623*c2c66affSColin Finck {
3624*c2c66affSColin Finck     TRACE("%s %lu %p %lx\n", debugstr_w(szDevInstName),
3625*c2c66affSColin Finck           ulHardwareProfile, pulValue, ulFlags);
3626*c2c66affSColin Finck 
3627*c2c66affSColin Finck     return CM_Get_HW_Prof_Flags_ExW(szDevInstName, ulHardwareProfile,
3628*c2c66affSColin Finck                                     pulValue, ulFlags, NULL);
3629*c2c66affSColin Finck }
3630*c2c66affSColin Finck 
3631*c2c66affSColin Finck 
3632*c2c66affSColin Finck /***********************************************************************
3633*c2c66affSColin Finck  * CM_Get_HW_Prof_Flags_ExA [SETUPAPI.@]
3634*c2c66affSColin Finck  */
3635*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_HW_Prof_Flags_ExA(
3636*c2c66affSColin Finck     DEVINSTID_A szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
3637*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
3638*c2c66affSColin Finck {
3639*c2c66affSColin Finck     DEVINSTID_W pszDevIdW = NULL;
3640*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
3641*c2c66affSColin Finck 
3642*c2c66affSColin Finck     TRACE("%s %lu %p %lx %lx\n", szDevInstName,
3643*c2c66affSColin Finck           ulHardwareProfile, pulValue, ulFlags, hMachine);
3644*c2c66affSColin Finck 
3645*c2c66affSColin Finck     if (szDevInstName != NULL)
3646*c2c66affSColin Finck     {
3647*c2c66affSColin Finck        if (pSetupCaptureAndConvertAnsiArg(szDevInstName, &pszDevIdW))
3648*c2c66affSColin Finck          return CR_INVALID_DEVICE_ID;
3649*c2c66affSColin Finck     }
3650*c2c66affSColin Finck 
3651*c2c66affSColin Finck     ret = CM_Get_HW_Prof_Flags_ExW(pszDevIdW, ulHardwareProfile,
3652*c2c66affSColin Finck                                    pulValue, ulFlags, hMachine);
3653*c2c66affSColin Finck 
3654*c2c66affSColin Finck     if (pszDevIdW != NULL)
3655*c2c66affSColin Finck         MyFree(pszDevIdW);
3656*c2c66affSColin Finck 
3657*c2c66affSColin Finck     return ret;
3658*c2c66affSColin Finck }
3659*c2c66affSColin Finck 
3660*c2c66affSColin Finck 
3661*c2c66affSColin Finck /***********************************************************************
3662*c2c66affSColin Finck  * CM_Get_HW_Prof_Flags_ExW [SETUPAPI.@]
3663*c2c66affSColin Finck  */
3664*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_HW_Prof_Flags_ExW(
3665*c2c66affSColin Finck     DEVINSTID_W szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
3666*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
3667*c2c66affSColin Finck {
3668*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3669*c2c66affSColin Finck     CONFIGRET ret;
3670*c2c66affSColin Finck 
3671*c2c66affSColin Finck     FIXME("%s %lu %p %lx %lx\n", debugstr_w(szDevInstName),
3672*c2c66affSColin Finck           ulHardwareProfile, pulValue, ulFlags, hMachine);
3673*c2c66affSColin Finck 
3674*c2c66affSColin Finck     if ((szDevInstName == NULL) || (pulValue == NULL))
3675*c2c66affSColin Finck         return CR_INVALID_POINTER;
3676*c2c66affSColin Finck 
3677*c2c66affSColin Finck     if (ulFlags != 0)
3678*c2c66affSColin Finck         return CR_INVALID_FLAG;
3679*c2c66affSColin Finck 
3680*c2c66affSColin Finck     /* FIXME: Check whether szDevInstName is valid */
3681*c2c66affSColin Finck 
3682*c2c66affSColin Finck     if (hMachine != NULL)
3683*c2c66affSColin Finck     {
3684*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3685*c2c66affSColin Finck         if (BindingHandle == NULL)
3686*c2c66affSColin Finck             return CR_FAILURE;
3687*c2c66affSColin Finck     }
3688*c2c66affSColin Finck     else
3689*c2c66affSColin Finck     {
3690*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
3691*c2c66affSColin Finck             return CR_FAILURE;
3692*c2c66affSColin Finck     }
3693*c2c66affSColin Finck 
3694*c2c66affSColin Finck     RpcTryExcept
3695*c2c66affSColin Finck     {
3696*c2c66affSColin Finck         ret = PNP_HwProfFlags(BindingHandle, PNP_GET_HWPROFFLAGS, szDevInstName,
3697*c2c66affSColin Finck                               ulHardwareProfile, pulValue, NULL, NULL, 0, 0);
3698*c2c66affSColin Finck     }
3699*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3700*c2c66affSColin Finck     {
3701*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3702*c2c66affSColin Finck     }
3703*c2c66affSColin Finck     RpcEndExcept;
3704*c2c66affSColin Finck 
3705*c2c66affSColin Finck     return ret;
3706*c2c66affSColin Finck }
3707*c2c66affSColin Finck 
3708*c2c66affSColin Finck 
3709*c2c66affSColin Finck /***********************************************************************
3710*c2c66affSColin Finck  * CM_Get_Hardware_Profile_InfoA [SETUPAPI.@]
3711*c2c66affSColin Finck  */
3712*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Hardware_Profile_InfoA(
3713*c2c66affSColin Finck     ULONG ulIndex, PHWPROFILEINFO_A pHWProfileInfo, ULONG ulFlags)
3714*c2c66affSColin Finck {
3715*c2c66affSColin Finck     TRACE("%lu %p %lx\n", ulIndex, pHWProfileInfo, ulFlags);
3716*c2c66affSColin Finck 
3717*c2c66affSColin Finck     return CM_Get_Hardware_Profile_Info_ExA(ulIndex, pHWProfileInfo,
3718*c2c66affSColin Finck                                             ulFlags, NULL);
3719*c2c66affSColin Finck }
3720*c2c66affSColin Finck 
3721*c2c66affSColin Finck 
3722*c2c66affSColin Finck /***********************************************************************
3723*c2c66affSColin Finck  * CM_Get_Hardware_Profile_InfoW [SETUPAPI.@]
3724*c2c66affSColin Finck  */
3725*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Hardware_Profile_InfoW(
3726*c2c66affSColin Finck     ULONG ulIndex, PHWPROFILEINFO_W pHWProfileInfo, ULONG ulFlags)
3727*c2c66affSColin Finck {
3728*c2c66affSColin Finck     TRACE("%lu %p %lx\n", ulIndex, pHWProfileInfo, ulFlags);
3729*c2c66affSColin Finck 
3730*c2c66affSColin Finck     return CM_Get_Hardware_Profile_Info_ExW(ulIndex, pHWProfileInfo,
3731*c2c66affSColin Finck                                             ulFlags, NULL);
3732*c2c66affSColin Finck }
3733*c2c66affSColin Finck 
3734*c2c66affSColin Finck 
3735*c2c66affSColin Finck /***********************************************************************
3736*c2c66affSColin Finck  * CM_Get_Hardware_Profile_Info_ExA [SETUPAPI.@]
3737*c2c66affSColin Finck  */
3738*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Hardware_Profile_Info_ExA(
3739*c2c66affSColin Finck     ULONG ulIndex, PHWPROFILEINFO_A pHWProfileInfo, ULONG ulFlags,
3740*c2c66affSColin Finck     HMACHINE hMachine)
3741*c2c66affSColin Finck {
3742*c2c66affSColin Finck     HWPROFILEINFO_W LocalProfileInfo;
3743*c2c66affSColin Finck     CONFIGRET ret;
3744*c2c66affSColin Finck 
3745*c2c66affSColin Finck     TRACE("%lu %p %lx %lx\n", ulIndex, pHWProfileInfo, ulFlags, hMachine);
3746*c2c66affSColin Finck 
3747*c2c66affSColin Finck     if (pHWProfileInfo == NULL)
3748*c2c66affSColin Finck         return CR_INVALID_POINTER;
3749*c2c66affSColin Finck 
3750*c2c66affSColin Finck     ret = CM_Get_Hardware_Profile_Info_ExW(ulIndex, &LocalProfileInfo,
3751*c2c66affSColin Finck                                            ulFlags, hMachine);
3752*c2c66affSColin Finck     if (ret == CR_SUCCESS)
3753*c2c66affSColin Finck     {
3754*c2c66affSColin Finck         pHWProfileInfo->HWPI_ulHWProfile = LocalProfileInfo.HWPI_ulHWProfile;
3755*c2c66affSColin Finck         pHWProfileInfo->HWPI_dwFlags = LocalProfileInfo.HWPI_dwFlags;
3756*c2c66affSColin Finck 
3757*c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
3758*c2c66affSColin Finck                                 0,
3759*c2c66affSColin Finck                                 LocalProfileInfo.HWPI_szFriendlyName,
3760*c2c66affSColin Finck                                 lstrlenW(LocalProfileInfo.HWPI_szFriendlyName) + 1,
3761*c2c66affSColin Finck                                 pHWProfileInfo->HWPI_szFriendlyName,
3762*c2c66affSColin Finck                                 MAX_PROFILE_LEN,
3763*c2c66affSColin Finck                                 NULL,
3764*c2c66affSColin Finck                                 NULL) == 0)
3765*c2c66affSColin Finck             ret = CR_FAILURE;
3766*c2c66affSColin Finck     }
3767*c2c66affSColin Finck 
3768*c2c66affSColin Finck     return ret;
3769*c2c66affSColin Finck }
3770*c2c66affSColin Finck 
3771*c2c66affSColin Finck 
3772*c2c66affSColin Finck /***********************************************************************
3773*c2c66affSColin Finck  * CM_Get_Hardware_Profile_Info_ExW [SETUPAPI.@]
3774*c2c66affSColin Finck  */
3775*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Hardware_Profile_Info_ExW(
3776*c2c66affSColin Finck     ULONG ulIndex, PHWPROFILEINFO_W pHWProfileInfo, ULONG ulFlags,
3777*c2c66affSColin Finck     HMACHINE hMachine)
3778*c2c66affSColin Finck {
3779*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3780*c2c66affSColin Finck     CONFIGRET ret;
3781*c2c66affSColin Finck 
3782*c2c66affSColin Finck     TRACE("%lu %p %lx %lx\n", ulIndex, pHWProfileInfo, ulFlags, hMachine);
3783*c2c66affSColin Finck 
3784*c2c66affSColin Finck     if (pHWProfileInfo == NULL)
3785*c2c66affSColin Finck         return CR_INVALID_POINTER;
3786*c2c66affSColin Finck 
3787*c2c66affSColin Finck     if (ulFlags != 0)
3788*c2c66affSColin Finck         return CR_INVALID_FLAG;
3789*c2c66affSColin Finck 
3790*c2c66affSColin Finck     if (hMachine != NULL)
3791*c2c66affSColin Finck     {
3792*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3793*c2c66affSColin Finck         if (BindingHandle == NULL)
3794*c2c66affSColin Finck             return CR_FAILURE;
3795*c2c66affSColin Finck     }
3796*c2c66affSColin Finck     else
3797*c2c66affSColin Finck     {
3798*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
3799*c2c66affSColin Finck             return CR_FAILURE;
3800*c2c66affSColin Finck     }
3801*c2c66affSColin Finck 
3802*c2c66affSColin Finck     RpcTryExcept
3803*c2c66affSColin Finck     {
3804*c2c66affSColin Finck         ret = PNP_GetHwProfInfo(BindingHandle, ulIndex, pHWProfileInfo,
3805*c2c66affSColin Finck                                 sizeof(HWPROFILEINFO_W), 0);
3806*c2c66affSColin Finck     }
3807*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3808*c2c66affSColin Finck     {
3809*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3810*c2c66affSColin Finck     }
3811*c2c66affSColin Finck     RpcEndExcept;
3812*c2c66affSColin Finck 
3813*c2c66affSColin Finck     return ret;
3814*c2c66affSColin Finck }
3815*c2c66affSColin Finck 
3816*c2c66affSColin Finck 
3817*c2c66affSColin Finck /***********************************************************************
3818*c2c66affSColin Finck  * CM_Get_Log_Conf_Priority [SETUPAPI.@]
3819*c2c66affSColin Finck  */
3820*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Log_Conf_Priority(
3821*c2c66affSColin Finck     LOG_CONF lcLogConf, PPRIORITY pPriority, ULONG ulFlags)
3822*c2c66affSColin Finck {
3823*c2c66affSColin Finck     TRACE("%p %p %lx\n", lcLogConf, pPriority, ulFlags);
3824*c2c66affSColin Finck     return CM_Get_Log_Conf_Priority_Ex(lcLogConf, pPriority, ulFlags, NULL);
3825*c2c66affSColin Finck }
3826*c2c66affSColin Finck 
3827*c2c66affSColin Finck 
3828*c2c66affSColin Finck /***********************************************************************
3829*c2c66affSColin Finck  * CM_Get_Log_Conf_Priority_Ex [SETUPAPI.@]
3830*c2c66affSColin Finck  */
3831*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Log_Conf_Priority_Ex(
3832*c2c66affSColin Finck     LOG_CONF lcLogConf, PPRIORITY pPriority, ULONG ulFlags,
3833*c2c66affSColin Finck     HMACHINE hMachine)
3834*c2c66affSColin Finck {
3835*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3836*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
3837*c2c66affSColin Finck     PLOG_CONF_INFO pLogConfInfo;
3838*c2c66affSColin Finck     LPWSTR lpDevInst;
3839*c2c66affSColin Finck     CONFIGRET ret;
3840*c2c66affSColin Finck 
3841*c2c66affSColin Finck     FIXME("%p %p %lx %lx\n", lcLogConf, pPriority, ulFlags, hMachine);
3842*c2c66affSColin Finck 
3843*c2c66affSColin Finck     pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
3844*c2c66affSColin Finck     if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
3845*c2c66affSColin Finck         return CR_INVALID_LOG_CONF;
3846*c2c66affSColin Finck 
3847*c2c66affSColin Finck     if (pPriority == NULL)
3848*c2c66affSColin Finck         return CR_INVALID_POINTER;
3849*c2c66affSColin Finck 
3850*c2c66affSColin Finck     if (ulFlags != 0)
3851*c2c66affSColin Finck         return CR_INVALID_FLAG;
3852*c2c66affSColin Finck 
3853*c2c66affSColin Finck     if (hMachine != NULL)
3854*c2c66affSColin Finck     {
3855*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3856*c2c66affSColin Finck         if (BindingHandle == NULL)
3857*c2c66affSColin Finck             return CR_FAILURE;
3858*c2c66affSColin Finck 
3859*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3860*c2c66affSColin Finck         if (StringTable == 0)
3861*c2c66affSColin Finck             return CR_FAILURE;
3862*c2c66affSColin Finck     }
3863*c2c66affSColin Finck     else
3864*c2c66affSColin Finck     {
3865*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
3866*c2c66affSColin Finck             return CR_FAILURE;
3867*c2c66affSColin Finck     }
3868*c2c66affSColin Finck 
3869*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
3870*c2c66affSColin Finck     if (lpDevInst == NULL)
3871*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
3872*c2c66affSColin Finck 
3873*c2c66affSColin Finck     RpcTryExcept
3874*c2c66affSColin Finck     {
3875*c2c66affSColin Finck         ret = PNP_GetLogConfPriority(BindingHandle,
3876*c2c66affSColin Finck                                      lpDevInst,
3877*c2c66affSColin Finck                                      pLogConfInfo->ulFlags,
3878*c2c66affSColin Finck                                      pLogConfInfo->ulTag,
3879*c2c66affSColin Finck                                      pPriority,
3880*c2c66affSColin Finck                                      0);
3881*c2c66affSColin Finck     }
3882*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3883*c2c66affSColin Finck     {
3884*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3885*c2c66affSColin Finck     }
3886*c2c66affSColin Finck     RpcEndExcept;
3887*c2c66affSColin Finck 
3888*c2c66affSColin Finck     return ret;
3889*c2c66affSColin Finck }
3890*c2c66affSColin Finck 
3891*c2c66affSColin Finck 
3892*c2c66affSColin Finck /***********************************************************************
3893*c2c66affSColin Finck  * CM_Get_Next_Log_Conf [SETUPAPI.@]
3894*c2c66affSColin Finck  */
3895*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Next_Log_Conf(
3896*c2c66affSColin Finck     PLOG_CONF plcLogConf, LOG_CONF lcLogConf, ULONG ulFlags)
3897*c2c66affSColin Finck {
3898*c2c66affSColin Finck     TRACE("%p %p %lx\n", plcLogConf, lcLogConf, ulFlags);
3899*c2c66affSColin Finck     return CM_Get_Next_Log_Conf_Ex(plcLogConf, lcLogConf, ulFlags, NULL);
3900*c2c66affSColin Finck }
3901*c2c66affSColin Finck 
3902*c2c66affSColin Finck 
3903*c2c66affSColin Finck /***********************************************************************
3904*c2c66affSColin Finck  * CM_Get_Next_Log_Conf_Ex [SETUPAPI.@]
3905*c2c66affSColin Finck  */
3906*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Next_Log_Conf_Ex(
3907*c2c66affSColin Finck     PLOG_CONF plcLogConf, LOG_CONF lcLogConf, ULONG ulFlags,
3908*c2c66affSColin Finck     HMACHINE hMachine)
3909*c2c66affSColin Finck {
3910*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3911*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
3912*c2c66affSColin Finck     PLOG_CONF_INFO pLogConfInfo;
3913*c2c66affSColin Finck     PLOG_CONF_INFO pNewLogConfInfo;
3914*c2c66affSColin Finck     ULONG ulNewTag;
3915*c2c66affSColin Finck     LPWSTR lpDevInst;
3916*c2c66affSColin Finck     CONFIGRET ret;
3917*c2c66affSColin Finck 
3918*c2c66affSColin Finck     FIXME("%p %p %lx %lx\n", plcLogConf, lcLogConf, ulFlags, hMachine);
3919*c2c66affSColin Finck 
3920*c2c66affSColin Finck     if (plcLogConf)
3921*c2c66affSColin Finck         *plcLogConf = 0;
3922*c2c66affSColin Finck 
3923*c2c66affSColin Finck     pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
3924*c2c66affSColin Finck     if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
3925*c2c66affSColin Finck         return CR_INVALID_LOG_CONF;
3926*c2c66affSColin Finck 
3927*c2c66affSColin Finck     if (ulFlags != 0)
3928*c2c66affSColin Finck         return CR_INVALID_FLAG;
3929*c2c66affSColin Finck 
3930*c2c66affSColin Finck     if (hMachine != NULL)
3931*c2c66affSColin Finck     {
3932*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3933*c2c66affSColin Finck         if (BindingHandle == NULL)
3934*c2c66affSColin Finck             return CR_FAILURE;
3935*c2c66affSColin Finck 
3936*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3937*c2c66affSColin Finck         if (StringTable == 0)
3938*c2c66affSColin Finck             return CR_FAILURE;
3939*c2c66affSColin Finck     }
3940*c2c66affSColin Finck     else
3941*c2c66affSColin Finck     {
3942*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
3943*c2c66affSColin Finck             return CR_FAILURE;
3944*c2c66affSColin Finck     }
3945*c2c66affSColin Finck 
3946*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
3947*c2c66affSColin Finck     if (lpDevInst == NULL)
3948*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
3949*c2c66affSColin Finck 
3950*c2c66affSColin Finck     RpcTryExcept
3951*c2c66affSColin Finck     {
3952*c2c66affSColin Finck         ret = PNP_GetNextLogConf(BindingHandle,
3953*c2c66affSColin Finck                                  lpDevInst,
3954*c2c66affSColin Finck                                  pLogConfInfo->ulFlags,
3955*c2c66affSColin Finck                                  pLogConfInfo->ulTag,
3956*c2c66affSColin Finck                                  &ulNewTag,
3957*c2c66affSColin Finck                                  0);
3958*c2c66affSColin Finck     }
3959*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3960*c2c66affSColin Finck     {
3961*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3962*c2c66affSColin Finck     }
3963*c2c66affSColin Finck     RpcEndExcept;
3964*c2c66affSColin Finck 
3965*c2c66affSColin Finck     if (ret != CR_SUCCESS)
3966*c2c66affSColin Finck         return ret;
3967*c2c66affSColin Finck 
3968*c2c66affSColin Finck     if (plcLogConf)
3969*c2c66affSColin Finck     {
3970*c2c66affSColin Finck         pNewLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
3971*c2c66affSColin Finck         if (pNewLogConfInfo == NULL)
3972*c2c66affSColin Finck             return CR_OUT_OF_MEMORY;
3973*c2c66affSColin Finck 
3974*c2c66affSColin Finck         pNewLogConfInfo->ulMagic = LOG_CONF_MAGIC;
3975*c2c66affSColin Finck         pNewLogConfInfo->dnDevInst = pLogConfInfo->dnDevInst;
3976*c2c66affSColin Finck         pNewLogConfInfo->ulFlags = pLogConfInfo->ulFlags;
3977*c2c66affSColin Finck         pNewLogConfInfo->ulTag = ulNewTag;
3978*c2c66affSColin Finck 
3979*c2c66affSColin Finck         *plcLogConf = (LOG_CONF)pNewLogConfInfo;
3980*c2c66affSColin Finck     }
3981*c2c66affSColin Finck 
3982*c2c66affSColin Finck     return CR_SUCCESS;
3983*c2c66affSColin Finck }
3984*c2c66affSColin Finck 
3985*c2c66affSColin Finck 
3986*c2c66affSColin Finck /***********************************************************************
3987*c2c66affSColin Finck  * CM_Get_Next_Re_Des [SETUPAPI.@]
3988*c2c66affSColin Finck  */
3989*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Next_Res_Des(
3990*c2c66affSColin Finck     PRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ForResource,
3991*c2c66affSColin Finck     PRESOURCEID pResourceID, ULONG ulFlags)
3992*c2c66affSColin Finck {
3993*c2c66affSColin Finck     TRACE("%p %p %lu %p %lx\n", prdResDes, rdResDes, ForResource,
3994*c2c66affSColin Finck           pResourceID, ulFlags);
3995*c2c66affSColin Finck     return CM_Get_Next_Res_Des_Ex(prdResDes, rdResDes, ForResource,
3996*c2c66affSColin Finck                                   pResourceID, ulFlags, NULL);
3997*c2c66affSColin Finck }
3998*c2c66affSColin Finck 
3999*c2c66affSColin Finck 
4000*c2c66affSColin Finck /***********************************************************************
4001*c2c66affSColin Finck  * CM_Get_Next_Re_Des_Ex [SETUPAPI.@]
4002*c2c66affSColin Finck  */
4003*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Next_Res_Des_Ex(
4004*c2c66affSColin Finck     PRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ForResource,
4005*c2c66affSColin Finck     PRESOURCEID pResourceID, ULONG ulFlags, HMACHINE hMachine)
4006*c2c66affSColin Finck {
4007*c2c66affSColin Finck     FIXME("%p %p %lu %p %lx %lx\n", prdResDes, rdResDes, ForResource,
4008*c2c66affSColin Finck           pResourceID, ulFlags, hMachine);
4009*c2c66affSColin Finck 
4010*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
4011*c2c66affSColin Finck }
4012*c2c66affSColin Finck 
4013*c2c66affSColin Finck 
4014*c2c66affSColin Finck /***********************************************************************
4015*c2c66affSColin Finck  * CM_Get_Parent [SETUPAPI.@]
4016*c2c66affSColin Finck  */
4017*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Parent(
4018*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags)
4019*c2c66affSColin Finck {
4020*c2c66affSColin Finck     TRACE("%p %p %lx\n", pdnDevInst, dnDevInst, ulFlags);
4021*c2c66affSColin Finck     return CM_Get_Parent_Ex(pdnDevInst, dnDevInst, ulFlags, NULL);
4022*c2c66affSColin Finck }
4023*c2c66affSColin Finck 
4024*c2c66affSColin Finck 
4025*c2c66affSColin Finck /***********************************************************************
4026*c2c66affSColin Finck  * CM_Get_Parent_Ex [SETUPAPI.@]
4027*c2c66affSColin Finck  */
4028*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Parent_Ex(
4029*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
4030*c2c66affSColin Finck {
4031*c2c66affSColin Finck     WCHAR szRelatedDevInst[MAX_DEVICE_ID_LEN];
4032*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4033*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
4034*c2c66affSColin Finck     LPWSTR lpDevInst;
4035*c2c66affSColin Finck     DWORD dwIndex, dwLength = MAX_DEVICE_ID_LEN;
4036*c2c66affSColin Finck     CONFIGRET ret;
4037*c2c66affSColin Finck 
4038*c2c66affSColin Finck     TRACE("%p %lx %lx %lx\n", pdnDevInst, dnDevInst, ulFlags, hMachine);
4039*c2c66affSColin Finck 
4040*c2c66affSColin Finck     if (pdnDevInst == NULL)
4041*c2c66affSColin Finck         return CR_INVALID_POINTER;
4042*c2c66affSColin Finck 
4043*c2c66affSColin Finck     if (dnDevInst == 0)
4044*c2c66affSColin Finck         return CR_INVALID_DEVINST;
4045*c2c66affSColin Finck 
4046*c2c66affSColin Finck     if (ulFlags != 0)
4047*c2c66affSColin Finck         return CR_INVALID_FLAG;
4048*c2c66affSColin Finck 
4049*c2c66affSColin Finck     *pdnDevInst = -1;
4050*c2c66affSColin Finck 
4051*c2c66affSColin Finck     if (hMachine != NULL)
4052*c2c66affSColin Finck     {
4053*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4054*c2c66affSColin Finck         if (BindingHandle == NULL)
4055*c2c66affSColin Finck             return CR_FAILURE;
4056*c2c66affSColin Finck 
4057*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
4058*c2c66affSColin Finck         if (StringTable == 0)
4059*c2c66affSColin Finck             return CR_FAILURE;
4060*c2c66affSColin Finck     }
4061*c2c66affSColin Finck     else
4062*c2c66affSColin Finck     {
4063*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
4064*c2c66affSColin Finck             return CR_FAILURE;
4065*c2c66affSColin Finck     }
4066*c2c66affSColin Finck 
4067*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
4068*c2c66affSColin Finck     if (lpDevInst == NULL)
4069*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
4070*c2c66affSColin Finck 
4071*c2c66affSColin Finck     RpcTryExcept
4072*c2c66affSColin Finck     {
4073*c2c66affSColin Finck         ret = PNP_GetRelatedDeviceInstance(BindingHandle,
4074*c2c66affSColin Finck                                            PNP_GET_PARENT_DEVICE_INSTANCE,
4075*c2c66affSColin Finck                                            lpDevInst,
4076*c2c66affSColin Finck                                            szRelatedDevInst,
4077*c2c66affSColin Finck                                            &dwLength,
4078*c2c66affSColin Finck                                            0);
4079*c2c66affSColin Finck     }
4080*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4081*c2c66affSColin Finck     {
4082*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4083*c2c66affSColin Finck     }
4084*c2c66affSColin Finck     RpcEndExcept;
4085*c2c66affSColin Finck 
4086*c2c66affSColin Finck     if (ret != CR_SUCCESS)
4087*c2c66affSColin Finck         return ret;
4088*c2c66affSColin Finck 
4089*c2c66affSColin Finck     TRACE("szRelatedDevInst: %s\n", debugstr_w(szRelatedDevInst));
4090*c2c66affSColin Finck 
4091*c2c66affSColin Finck     dwIndex = pSetupStringTableAddString(StringTable, szRelatedDevInst, 1);
4092*c2c66affSColin Finck     if (dwIndex == -1)
4093*c2c66affSColin Finck         return CR_FAILURE;
4094*c2c66affSColin Finck 
4095*c2c66affSColin Finck     *pdnDevInst = dwIndex;
4096*c2c66affSColin Finck 
4097*c2c66affSColin Finck     return CR_SUCCESS;
4098*c2c66affSColin Finck }
4099*c2c66affSColin Finck 
4100*c2c66affSColin Finck 
4101*c2c66affSColin Finck /***********************************************************************
4102*c2c66affSColin Finck  * CM_Get_Res_Des_Data [SETUPAPI.@]
4103*c2c66affSColin Finck  */
4104*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Res_Des_Data(
4105*c2c66affSColin Finck     RES_DES rdResDes, PVOID Buffer, ULONG BufferLen, ULONG ulFlags)
4106*c2c66affSColin Finck {
4107*c2c66affSColin Finck     TRACE("%p %p %l %lx\n", rdResDes, Buffer, BufferLen, ulFlags);
4108*c2c66affSColin Finck     return CM_Get_Res_Des_Data_Ex(rdResDes, Buffer, BufferLen, ulFlags, NULL);
4109*c2c66affSColin Finck }
4110*c2c66affSColin Finck 
4111*c2c66affSColin Finck 
4112*c2c66affSColin Finck /***********************************************************************
4113*c2c66affSColin Finck  * CM_Get_Res_Des_Data_Ex [SETUPAPI.@]
4114*c2c66affSColin Finck  */
4115*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Res_Des_Data_Ex(
4116*c2c66affSColin Finck     RES_DES rdResDes, PVOID Buffer, ULONG BufferLen, ULONG ulFlags,
4117*c2c66affSColin Finck     HMACHINE hMachine)
4118*c2c66affSColin Finck {
4119*c2c66affSColin Finck     FIXME("%p %p %l %lx %lx\n", rdResDes, Buffer, BufferLen, ulFlags, hMachine);
4120*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
4121*c2c66affSColin Finck }
4122*c2c66affSColin Finck 
4123*c2c66affSColin Finck 
4124*c2c66affSColin Finck /***********************************************************************
4125*c2c66affSColin Finck  * CM_Get_Res_Des_Size [SETUPAPI.@]
4126*c2c66affSColin Finck  */
4127*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Res_Des_Data_Size(
4128*c2c66affSColin Finck     PULONG pulSize, RES_DES rdResDes, ULONG ulFlags)
4129*c2c66affSColin Finck {
4130*c2c66affSColin Finck     TRACE("%p %p %lx\n", pulSize, rdResDes, ulFlags);
4131*c2c66affSColin Finck     return CM_Get_Res_Des_Data_Size_Ex(pulSize, rdResDes, ulFlags, NULL);
4132*c2c66affSColin Finck }
4133*c2c66affSColin Finck 
4134*c2c66affSColin Finck 
4135*c2c66affSColin Finck /***********************************************************************
4136*c2c66affSColin Finck  * CM_Get_Res_Des_Size_Ex [SETUPAPI.@]
4137*c2c66affSColin Finck  */
4138*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Res_Des_Data_Size_Ex(
4139*c2c66affSColin Finck     PULONG pulSize, RES_DES rdResDes, ULONG ulFlags, HMACHINE hMachine)
4140*c2c66affSColin Finck {
4141*c2c66affSColin Finck     TRACE("%p %p %lx %lx\n", pulSize, rdResDes, ulFlags, hMachine);
4142*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
4143*c2c66affSColin Finck }
4144*c2c66affSColin Finck 
4145*c2c66affSColin Finck 
4146*c2c66affSColin Finck /***********************************************************************
4147*c2c66affSColin Finck  * CM_Get_Sibling [SETUPAPI.@]
4148*c2c66affSColin Finck  */
4149*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Sibling(
4150*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags)
4151*c2c66affSColin Finck {
4152*c2c66affSColin Finck     TRACE("%p %p %lx\n", pdnDevInst, dnDevInst, ulFlags);
4153*c2c66affSColin Finck     return CM_Get_Sibling_Ex(pdnDevInst, dnDevInst, ulFlags, NULL);
4154*c2c66affSColin Finck }
4155*c2c66affSColin Finck 
4156*c2c66affSColin Finck 
4157*c2c66affSColin Finck /***********************************************************************
4158*c2c66affSColin Finck  * CM_Get_Sibling_Ex [SETUPAPI.@]
4159*c2c66affSColin Finck  */
4160*c2c66affSColin Finck CONFIGRET WINAPI CM_Get_Sibling_Ex(
4161*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
4162*c2c66affSColin Finck {
4163*c2c66affSColin Finck     WCHAR szRelatedDevInst[MAX_DEVICE_ID_LEN];
4164*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4165*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
4166*c2c66affSColin Finck     LPWSTR lpDevInst;
4167*c2c66affSColin Finck     DWORD dwIndex, dwLength = MAX_DEVICE_ID_LEN;
4168*c2c66affSColin Finck     CONFIGRET ret;
4169*c2c66affSColin Finck 
4170*c2c66affSColin Finck     TRACE("%p %lx %lx %lx\n", pdnDevInst, dnDevInst, ulFlags, hMachine);
4171*c2c66affSColin Finck 
4172*c2c66affSColin Finck     if (pdnDevInst == NULL)
4173*c2c66affSColin Finck         return CR_INVALID_POINTER;
4174*c2c66affSColin Finck 
4175*c2c66affSColin Finck     if (dnDevInst == 0)
4176*c2c66affSColin Finck         return CR_INVALID_DEVINST;
4177*c2c66affSColin Finck 
4178*c2c66affSColin Finck     if (ulFlags != 0)
4179*c2c66affSColin Finck         return CR_INVALID_FLAG;
4180*c2c66affSColin Finck 
4181*c2c66affSColin Finck     *pdnDevInst = -1;
4182*c2c66affSColin Finck 
4183*c2c66affSColin Finck     if (hMachine != NULL)
4184*c2c66affSColin Finck     {
4185*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4186*c2c66affSColin Finck         if (BindingHandle == NULL)
4187*c2c66affSColin Finck             return CR_FAILURE;
4188*c2c66affSColin Finck 
4189*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
4190*c2c66affSColin Finck         if (StringTable == 0)
4191*c2c66affSColin Finck             return CR_FAILURE;
4192*c2c66affSColin Finck     }
4193*c2c66affSColin Finck     else
4194*c2c66affSColin Finck     {
4195*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
4196*c2c66affSColin Finck             return CR_FAILURE;
4197*c2c66affSColin Finck     }
4198*c2c66affSColin Finck 
4199*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
4200*c2c66affSColin Finck     if (lpDevInst == NULL)
4201*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
4202*c2c66affSColin Finck 
4203*c2c66affSColin Finck     RpcTryExcept
4204*c2c66affSColin Finck     {
4205*c2c66affSColin Finck         ret = PNP_GetRelatedDeviceInstance(BindingHandle,
4206*c2c66affSColin Finck                                            PNP_GET_SIBLING_DEVICE_INSTANCE,
4207*c2c66affSColin Finck                                            lpDevInst,
4208*c2c66affSColin Finck                                            szRelatedDevInst,
4209*c2c66affSColin Finck                                            &dwLength,
4210*c2c66affSColin Finck                                            0);
4211*c2c66affSColin Finck     }
4212*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4213*c2c66affSColin Finck     {
4214*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4215*c2c66affSColin Finck     }
4216*c2c66affSColin Finck     RpcEndExcept;
4217*c2c66affSColin Finck 
4218*c2c66affSColin Finck     if (ret != CR_SUCCESS)
4219*c2c66affSColin Finck         return ret;
4220*c2c66affSColin Finck 
4221*c2c66affSColin Finck     TRACE("szRelatedDevInst: %s\n", debugstr_w(szRelatedDevInst));
4222*c2c66affSColin Finck 
4223*c2c66affSColin Finck     dwIndex = pSetupStringTableAddString(StringTable, szRelatedDevInst, 1);
4224*c2c66affSColin Finck     if (dwIndex == -1)
4225*c2c66affSColin Finck         return CR_FAILURE;
4226*c2c66affSColin Finck 
4227*c2c66affSColin Finck     *pdnDevInst = dwIndex;
4228*c2c66affSColin Finck 
4229*c2c66affSColin Finck     return CR_SUCCESS;
4230*c2c66affSColin Finck }
4231*c2c66affSColin Finck 
4232*c2c66affSColin Finck 
4233*c2c66affSColin Finck /***********************************************************************
4234*c2c66affSColin Finck  * CM_Get_Version [SETUPAPI.@]
4235*c2c66affSColin Finck  */
4236*c2c66affSColin Finck WORD WINAPI CM_Get_Version(VOID)
4237*c2c66affSColin Finck {
4238*c2c66affSColin Finck     TRACE("\n");
4239*c2c66affSColin Finck     return CM_Get_Version_Ex(NULL);
4240*c2c66affSColin Finck }
4241*c2c66affSColin Finck 
4242*c2c66affSColin Finck 
4243*c2c66affSColin Finck /***********************************************************************
4244*c2c66affSColin Finck  * CM_Get_Version_Ex [SETUPAPI.@]
4245*c2c66affSColin Finck  */
4246*c2c66affSColin Finck WORD WINAPI CM_Get_Version_Ex(HMACHINE hMachine)
4247*c2c66affSColin Finck {
4248*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4249*c2c66affSColin Finck     WORD Version = 0;
4250*c2c66affSColin Finck     CONFIGRET ret;
4251*c2c66affSColin Finck 
4252*c2c66affSColin Finck     TRACE("%lx\n", hMachine);
4253*c2c66affSColin Finck 
4254*c2c66affSColin Finck     if (hMachine != NULL)
4255*c2c66affSColin Finck     {
4256*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4257*c2c66affSColin Finck         if (BindingHandle == NULL)
4258*c2c66affSColin Finck             return 0;
4259*c2c66affSColin Finck     }
4260*c2c66affSColin Finck     else
4261*c2c66affSColin Finck     {
4262*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
4263*c2c66affSColin Finck             return CR_FAILURE;
4264*c2c66affSColin Finck     }
4265*c2c66affSColin Finck 
4266*c2c66affSColin Finck     RpcTryExcept
4267*c2c66affSColin Finck     {
4268*c2c66affSColin Finck         ret = PNP_GetVersion(BindingHandle, &Version);
4269*c2c66affSColin Finck     }
4270*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4271*c2c66affSColin Finck     {
4272*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4273*c2c66affSColin Finck     }
4274*c2c66affSColin Finck     RpcEndExcept;
4275*c2c66affSColin Finck 
4276*c2c66affSColin Finck     if (ret != CR_SUCCESS)
4277*c2c66affSColin Finck         return 0;
4278*c2c66affSColin Finck 
4279*c2c66affSColin Finck     return Version;
4280*c2c66affSColin Finck }
4281*c2c66affSColin Finck 
4282*c2c66affSColin Finck 
4283*c2c66affSColin Finck /***********************************************************************
4284*c2c66affSColin Finck  * CM_Intersect_Range_List [SETUPAPI.@]
4285*c2c66affSColin Finck  */
4286*c2c66affSColin Finck CONFIGRET
4287*c2c66affSColin Finck WINAPI
4288*c2c66affSColin Finck CM_Intersect_Range_List(
4289*c2c66affSColin Finck     _In_ RANGE_LIST rlhOld1,
4290*c2c66affSColin Finck     _In_ RANGE_LIST rlhOld2,
4291*c2c66affSColin Finck     _In_ RANGE_LIST rlhNew,
4292*c2c66affSColin Finck     _In_ ULONG ulFlags)
4293*c2c66affSColin Finck {
4294*c2c66affSColin Finck     FIXME("CM_Intersect_Range_List(%p %p %p %lx)\n",
4295*c2c66affSColin Finck           rlhOld1, rlhOld2, rlhNew, ulFlags);
4296*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
4297*c2c66affSColin Finck }
4298*c2c66affSColin Finck 
4299*c2c66affSColin Finck 
4300*c2c66affSColin Finck /***********************************************************************
4301*c2c66affSColin Finck  * CM_Invert_Range_List [SETUPAPI.@]
4302*c2c66affSColin Finck  */
4303*c2c66affSColin Finck CONFIGRET
4304*c2c66affSColin Finck WINAPI
4305*c2c66affSColin Finck CM_Invert_Range_List(
4306*c2c66affSColin Finck     _In_ RANGE_LIST rlhOld,
4307*c2c66affSColin Finck     _In_ RANGE_LIST rlhNew,
4308*c2c66affSColin Finck     _In_ DWORDLONG ullMaxValue,
4309*c2c66affSColin Finck     _In_ ULONG ulFlags)
4310*c2c66affSColin Finck {
4311*c2c66affSColin Finck     FIXME("CM_Invert_Range_List(%p %p %I64u %lx)\n",
4312*c2c66affSColin Finck           rlhOld, rlhNew, ullMaxValue, ulFlags);
4313*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
4314*c2c66affSColin Finck }
4315*c2c66affSColin Finck 
4316*c2c66affSColin Finck 
4317*c2c66affSColin Finck /***********************************************************************
4318*c2c66affSColin Finck  * CM_Is_Dock_Station_Present [SETUPAPI.@]
4319*c2c66affSColin Finck  */
4320*c2c66affSColin Finck CONFIGRET WINAPI CM_Is_Dock_Station_Present(
4321*c2c66affSColin Finck     PBOOL pbPresent)
4322*c2c66affSColin Finck {
4323*c2c66affSColin Finck     TRACE("%p\n", pbPresent);
4324*c2c66affSColin Finck     return CM_Is_Dock_Station_Present_Ex(pbPresent, NULL);
4325*c2c66affSColin Finck }
4326*c2c66affSColin Finck 
4327*c2c66affSColin Finck 
4328*c2c66affSColin Finck /***********************************************************************
4329*c2c66affSColin Finck  * CM_Is_Dock_Station_Present_Ex [SETUPAPI.@]
4330*c2c66affSColin Finck  */
4331*c2c66affSColin Finck CONFIGRET WINAPI CM_Is_Dock_Station_Present_Ex(
4332*c2c66affSColin Finck     PBOOL pbPresent, HMACHINE hMachine)
4333*c2c66affSColin Finck {
4334*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4335*c2c66affSColin Finck     CONFIGRET ret;
4336*c2c66affSColin Finck 
4337*c2c66affSColin Finck     TRACE("%p %lx\n", pbPresent, hMachine);
4338*c2c66affSColin Finck 
4339*c2c66affSColin Finck     if (pbPresent == NULL)
4340*c2c66affSColin Finck         return CR_INVALID_POINTER;
4341*c2c66affSColin Finck 
4342*c2c66affSColin Finck     *pbPresent = FALSE;
4343*c2c66affSColin Finck 
4344*c2c66affSColin Finck     if (hMachine != NULL)
4345*c2c66affSColin Finck     {
4346*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4347*c2c66affSColin Finck         if (BindingHandle == NULL)
4348*c2c66affSColin Finck             return CR_FAILURE;
4349*c2c66affSColin Finck     }
4350*c2c66affSColin Finck     else
4351*c2c66affSColin Finck     {
4352*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
4353*c2c66affSColin Finck             return CR_FAILURE;
4354*c2c66affSColin Finck     }
4355*c2c66affSColin Finck 
4356*c2c66affSColin Finck     RpcTryExcept
4357*c2c66affSColin Finck     {
4358*c2c66affSColin Finck         ret = PNP_IsDockStationPresent(BindingHandle,
4359*c2c66affSColin Finck                                        pbPresent);
4360*c2c66affSColin Finck     }
4361*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4362*c2c66affSColin Finck     {
4363*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4364*c2c66affSColin Finck     }
4365*c2c66affSColin Finck     RpcEndExcept;
4366*c2c66affSColin Finck 
4367*c2c66affSColin Finck     return ret;
4368*c2c66affSColin Finck }
4369*c2c66affSColin Finck 
4370*c2c66affSColin Finck 
4371*c2c66affSColin Finck /***********************************************************************
4372*c2c66affSColin Finck  * CM_Is_Version_Available_Ex [SETUPAPI.@]
4373*c2c66affSColin Finck  */
4374*c2c66affSColin Finck BOOL WINAPI CM_Is_Version_Available(
4375*c2c66affSColin Finck      WORD wVersion)
4376*c2c66affSColin Finck {
4377*c2c66affSColin Finck     TRACE("%hu\n", wVersion);
4378*c2c66affSColin Finck     return CM_Is_Version_Available_Ex(wVersion, NULL);
4379*c2c66affSColin Finck }
4380*c2c66affSColin Finck 
4381*c2c66affSColin Finck 
4382*c2c66affSColin Finck /***********************************************************************
4383*c2c66affSColin Finck  * CM_Is_Version_Available_Ex [SETUPAPI.@]
4384*c2c66affSColin Finck  */
4385*c2c66affSColin Finck BOOL WINAPI CM_Is_Version_Available_Ex(
4386*c2c66affSColin Finck     WORD wVersion, HMACHINE hMachine)
4387*c2c66affSColin Finck {
4388*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4389*c2c66affSColin Finck     WORD wServerVersion;
4390*c2c66affSColin Finck     CONFIGRET ret;
4391*c2c66affSColin Finck 
4392*c2c66affSColin Finck     TRACE("%hu %lx\n", wVersion, hMachine);
4393*c2c66affSColin Finck 
4394*c2c66affSColin Finck     if (wVersion <= 0x400)
4395*c2c66affSColin Finck         return TRUE;
4396*c2c66affSColin Finck 
4397*c2c66affSColin Finck     if (hMachine != NULL)
4398*c2c66affSColin Finck     {
4399*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4400*c2c66affSColin Finck         if (BindingHandle == NULL)
4401*c2c66affSColin Finck             return FALSE;
4402*c2c66affSColin Finck     }
4403*c2c66affSColin Finck     else
4404*c2c66affSColin Finck     {
4405*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
4406*c2c66affSColin Finck             return FALSE;
4407*c2c66affSColin Finck     }
4408*c2c66affSColin Finck 
4409*c2c66affSColin Finck     RpcTryExcept
4410*c2c66affSColin Finck     {
4411*c2c66affSColin Finck         ret = PNP_GetVersion(BindingHandle, &wServerVersion);
4412*c2c66affSColin Finck     }
4413*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4414*c2c66affSColin Finck     {
4415*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4416*c2c66affSColin Finck     }
4417*c2c66affSColin Finck     RpcEndExcept;
4418*c2c66affSColin Finck 
4419*c2c66affSColin Finck     if (ret != CR_SUCCESS)
4420*c2c66affSColin Finck         return FALSE;
4421*c2c66affSColin Finck 
4422*c2c66affSColin Finck     return (wServerVersion >= wVersion);
4423*c2c66affSColin Finck }
4424*c2c66affSColin Finck 
4425*c2c66affSColin Finck 
4426*c2c66affSColin Finck /***********************************************************************
4427*c2c66affSColin Finck  * CM_Locate_DevNodeA [SETUPAPI.@]
4428*c2c66affSColin Finck  */
4429*c2c66affSColin Finck CONFIGRET WINAPI CM_Locate_DevNodeA(
4430*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags)
4431*c2c66affSColin Finck {
4432*c2c66affSColin Finck     TRACE("%p %s %lu\n", pdnDevInst, pDeviceID, ulFlags);
4433*c2c66affSColin Finck     return CM_Locate_DevNode_ExA(pdnDevInst, pDeviceID, ulFlags, NULL);
4434*c2c66affSColin Finck }
4435*c2c66affSColin Finck 
4436*c2c66affSColin Finck 
4437*c2c66affSColin Finck /***********************************************************************
4438*c2c66affSColin Finck  * CM_Locate_DevNodeW [SETUPAPI.@]
4439*c2c66affSColin Finck  */
4440*c2c66affSColin Finck CONFIGRET WINAPI CM_Locate_DevNodeW(
4441*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINSTID_W pDeviceID, ULONG ulFlags)
4442*c2c66affSColin Finck {
4443*c2c66affSColin Finck     TRACE("%p %s %lu\n", pdnDevInst, debugstr_w(pDeviceID), ulFlags);
4444*c2c66affSColin Finck     return CM_Locate_DevNode_ExW(pdnDevInst, pDeviceID, ulFlags, NULL);
4445*c2c66affSColin Finck }
4446*c2c66affSColin Finck 
4447*c2c66affSColin Finck 
4448*c2c66affSColin Finck /***********************************************************************
4449*c2c66affSColin Finck  * CM_Locate_DevNode_ExA [SETUPAPI.@]
4450*c2c66affSColin Finck  */
4451*c2c66affSColin Finck CONFIGRET WINAPI CM_Locate_DevNode_ExA(
4452*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags, HMACHINE hMachine)
4453*c2c66affSColin Finck {
4454*c2c66affSColin Finck     DEVINSTID_W pDevIdW = NULL;
4455*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
4456*c2c66affSColin Finck 
4457*c2c66affSColin Finck     TRACE("%p %s %lu %lx\n", pdnDevInst, pDeviceID, ulFlags, hMachine);
4458*c2c66affSColin Finck 
4459*c2c66affSColin Finck     if (pDeviceID != NULL)
4460*c2c66affSColin Finck     {
4461*c2c66affSColin Finck        if (pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDevIdW))
4462*c2c66affSColin Finck          return CR_INVALID_DEVICE_ID;
4463*c2c66affSColin Finck     }
4464*c2c66affSColin Finck 
4465*c2c66affSColin Finck     ret = CM_Locate_DevNode_ExW(pdnDevInst, pDevIdW, ulFlags, hMachine);
4466*c2c66affSColin Finck 
4467*c2c66affSColin Finck     if (pDevIdW != NULL)
4468*c2c66affSColin Finck         MyFree(pDevIdW);
4469*c2c66affSColin Finck 
4470*c2c66affSColin Finck     return ret;
4471*c2c66affSColin Finck }
4472*c2c66affSColin Finck 
4473*c2c66affSColin Finck 
4474*c2c66affSColin Finck /***********************************************************************
4475*c2c66affSColin Finck  * CM_Locate_DevNode_ExW [SETUPAPI.@]
4476*c2c66affSColin Finck  */
4477*c2c66affSColin Finck CONFIGRET WINAPI CM_Locate_DevNode_ExW(
4478*c2c66affSColin Finck     PDEVINST pdnDevInst, DEVINSTID_W pDeviceID, ULONG ulFlags, HMACHINE hMachine)
4479*c2c66affSColin Finck {
4480*c2c66affSColin Finck     WCHAR DeviceIdBuffer[MAX_DEVICE_ID_LEN];
4481*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4482*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
4483*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
4484*c2c66affSColin Finck 
4485*c2c66affSColin Finck     TRACE("%p %s %lu %lx\n", pdnDevInst, debugstr_w(pDeviceID), ulFlags, hMachine);
4486*c2c66affSColin Finck 
4487*c2c66affSColin Finck     if (pdnDevInst == NULL)
4488*c2c66affSColin Finck         return CR_INVALID_POINTER;
4489*c2c66affSColin Finck 
4490*c2c66affSColin Finck     if (ulFlags & ~CM_LOCATE_DEVNODE_BITS)
4491*c2c66affSColin Finck         return CR_INVALID_FLAG;
4492*c2c66affSColin Finck 
4493*c2c66affSColin Finck     if (hMachine != NULL)
4494*c2c66affSColin Finck     {
4495*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4496*c2c66affSColin Finck         if (BindingHandle == NULL)
4497*c2c66affSColin Finck             return CR_FAILURE;
4498*c2c66affSColin Finck 
4499*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
4500*c2c66affSColin Finck         if (StringTable == 0)
4501*c2c66affSColin Finck             return CR_FAILURE;
4502*c2c66affSColin Finck     }
4503*c2c66affSColin Finck     else
4504*c2c66affSColin Finck     {
4505*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
4506*c2c66affSColin Finck             return CR_FAILURE;
4507*c2c66affSColin Finck     }
4508*c2c66affSColin Finck 
4509*c2c66affSColin Finck     if (pDeviceID != NULL && lstrlenW(pDeviceID) != 0)
4510*c2c66affSColin Finck     {
4511*c2c66affSColin Finck         lstrcpyW(DeviceIdBuffer, pDeviceID);
4512*c2c66affSColin Finck     }
4513*c2c66affSColin Finck     else
4514*c2c66affSColin Finck     {
4515*c2c66affSColin Finck         RpcTryExcept
4516*c2c66affSColin Finck         {
4517*c2c66affSColin Finck             /* Get the root device ID */
4518*c2c66affSColin Finck             ret = PNP_GetRootDeviceInstance(BindingHandle,
4519*c2c66affSColin Finck                                             DeviceIdBuffer,
4520*c2c66affSColin Finck                                             MAX_DEVICE_ID_LEN);
4521*c2c66affSColin Finck         }
4522*c2c66affSColin Finck         RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4523*c2c66affSColin Finck         {
4524*c2c66affSColin Finck             ret = RpcStatusToCmStatus(RpcExceptionCode());
4525*c2c66affSColin Finck         }
4526*c2c66affSColin Finck         RpcEndExcept;
4527*c2c66affSColin Finck 
4528*c2c66affSColin Finck         if (ret != CR_SUCCESS)
4529*c2c66affSColin Finck             return CR_FAILURE;
4530*c2c66affSColin Finck     }
4531*c2c66affSColin Finck     TRACE("DeviceIdBuffer: %s\n", debugstr_w(DeviceIdBuffer));
4532*c2c66affSColin Finck 
4533*c2c66affSColin Finck     RpcTryExcept
4534*c2c66affSColin Finck     {
4535*c2c66affSColin Finck         /* Validate the device ID */
4536*c2c66affSColin Finck         ret = PNP_ValidateDeviceInstance(BindingHandle,
4537*c2c66affSColin Finck                                          DeviceIdBuffer,
4538*c2c66affSColin Finck                                          ulFlags);
4539*c2c66affSColin Finck     }
4540*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4541*c2c66affSColin Finck     {
4542*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4543*c2c66affSColin Finck     }
4544*c2c66affSColin Finck     RpcEndExcept;
4545*c2c66affSColin Finck 
4546*c2c66affSColin Finck     if (ret == CR_SUCCESS)
4547*c2c66affSColin Finck     {
4548*c2c66affSColin Finck         *pdnDevInst = pSetupStringTableAddString(StringTable, DeviceIdBuffer, 1);
4549*c2c66affSColin Finck         if (*pdnDevInst == -1)
4550*c2c66affSColin Finck             ret = CR_FAILURE;
4551*c2c66affSColin Finck     }
4552*c2c66affSColin Finck 
4553*c2c66affSColin Finck     return ret;
4554*c2c66affSColin Finck }
4555*c2c66affSColin Finck 
4556*c2c66affSColin Finck 
4557*c2c66affSColin Finck /***********************************************************************
4558*c2c66affSColin Finck  * CM_Merge_Range_List [SETUPAPI.@]
4559*c2c66affSColin Finck  */
4560*c2c66affSColin Finck CONFIGRET
4561*c2c66affSColin Finck WINAPI
4562*c2c66affSColin Finck CM_Merge_Range_List(
4563*c2c66affSColin Finck     _In_ RANGE_LIST rlhOld1,
4564*c2c66affSColin Finck     _In_ RANGE_LIST rlhOld2,
4565*c2c66affSColin Finck     _In_ RANGE_LIST rlhNew,
4566*c2c66affSColin Finck     _In_ ULONG ulFlags)
4567*c2c66affSColin Finck {
4568*c2c66affSColin Finck     FIXME("CM_Merge_Range_List(%p %p %p %lx)\n",
4569*c2c66affSColin Finck           rlhOld1, rlhOld2, rlhNew, ulFlags);
4570*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
4571*c2c66affSColin Finck }
4572*c2c66affSColin Finck 
4573*c2c66affSColin Finck 
4574*c2c66affSColin Finck /***********************************************************************
4575*c2c66affSColin Finck  * CM_Modify_Res_Des [SETUPAPI.@]
4576*c2c66affSColin Finck  */
4577*c2c66affSColin Finck CONFIGRET WINAPI CM_Modify_Res_Des(
4578*c2c66affSColin Finck     PRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ResourceID,
4579*c2c66affSColin Finck     PCVOID ResourceData, ULONG ResourceLen, ULONG ulFlags)
4580*c2c66affSColin Finck {
4581*c2c66affSColin Finck     TRACE("%p %p %lx %p %lu %lx", prdResDes, rdResDes, ResourceID, ResourceData,
4582*c2c66affSColin Finck           ResourceLen, ulFlags);
4583*c2c66affSColin Finck     return CM_Modify_Res_Des_Ex(prdResDes, rdResDes, ResourceID, ResourceData,
4584*c2c66affSColin Finck                                 ResourceLen, ulFlags, NULL);
4585*c2c66affSColin Finck }
4586*c2c66affSColin Finck 
4587*c2c66affSColin Finck 
4588*c2c66affSColin Finck /***********************************************************************
4589*c2c66affSColin Finck  * CM_Modify_Res_Des_Ex [SETUPAPI.@]
4590*c2c66affSColin Finck  */
4591*c2c66affSColin Finck CONFIGRET WINAPI CM_Modify_Res_Des_Ex(
4592*c2c66affSColin Finck     PRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ResourceID, PCVOID ResourceData,
4593*c2c66affSColin Finck     ULONG ResourceLen, ULONG ulFlags, HMACHINE hMachine)
4594*c2c66affSColin Finck {
4595*c2c66affSColin Finck     FIXME("%p %p %lx %p %lu %lx %lx", prdResDes, rdResDes, ResourceID, ResourceData,
4596*c2c66affSColin Finck           ResourceLen, ulFlags, hMachine);
4597*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
4598*c2c66affSColin Finck }
4599*c2c66affSColin Finck 
4600*c2c66affSColin Finck 
4601*c2c66affSColin Finck /***********************************************************************
4602*c2c66affSColin Finck  * CM_Move_DevNode [SETUPAPI.@]
4603*c2c66affSColin Finck  */
4604*c2c66affSColin Finck CONFIGRET WINAPI CM_Move_DevNode(
4605*c2c66affSColin Finck     DEVINST dnFromDevInst, DEVINST dnToDevInst, ULONG ulFlags)
4606*c2c66affSColin Finck {
4607*c2c66affSColin Finck     TRACE("%lx %lx %lx\n", dnFromDevInst, dnToDevInst, ulFlags);
4608*c2c66affSColin Finck     return CM_Move_DevNode_Ex(dnFromDevInst, dnToDevInst, ulFlags, NULL);
4609*c2c66affSColin Finck }
4610*c2c66affSColin Finck 
4611*c2c66affSColin Finck 
4612*c2c66affSColin Finck /***********************************************************************
4613*c2c66affSColin Finck  * CM_Move_DevNode_Ex [SETUPAPI.@]
4614*c2c66affSColin Finck  */
4615*c2c66affSColin Finck CONFIGRET WINAPI CM_Move_DevNode_Ex(
4616*c2c66affSColin Finck     DEVINST dnFromDevInst, DEVINST dnToDevInst, ULONG ulFlags,
4617*c2c66affSColin Finck     HMACHINE hMachine)
4618*c2c66affSColin Finck {
4619*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4620*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
4621*c2c66affSColin Finck     LPWSTR lpFromDevInst;
4622*c2c66affSColin Finck     LPWSTR lpToDevInst;
4623*c2c66affSColin Finck     CONFIGRET ret;
4624*c2c66affSColin Finck 
4625*c2c66affSColin Finck     FIXME("%lx %lx %lx %lx\n",
4626*c2c66affSColin Finck           dnFromDevInst, dnToDevInst, ulFlags, hMachine);
4627*c2c66affSColin Finck 
4628*c2c66affSColin Finck     if (!pSetupIsUserAdmin())
4629*c2c66affSColin Finck         return CR_ACCESS_DENIED;
4630*c2c66affSColin Finck 
4631*c2c66affSColin Finck     if (dnFromDevInst == 0 || dnToDevInst == 0)
4632*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
4633*c2c66affSColin Finck 
4634*c2c66affSColin Finck     if (ulFlags != 0)
4635*c2c66affSColin Finck         return CR_INVALID_FLAG;
4636*c2c66affSColin Finck 
4637*c2c66affSColin Finck     if (hMachine != NULL)
4638*c2c66affSColin Finck     {
4639*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4640*c2c66affSColin Finck         if (BindingHandle == NULL)
4641*c2c66affSColin Finck             return CR_FAILURE;
4642*c2c66affSColin Finck 
4643*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
4644*c2c66affSColin Finck         if (StringTable == 0)
4645*c2c66affSColin Finck             return CR_FAILURE;
4646*c2c66affSColin Finck     }
4647*c2c66affSColin Finck     else
4648*c2c66affSColin Finck     {
4649*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
4650*c2c66affSColin Finck             return CR_FAILURE;
4651*c2c66affSColin Finck     }
4652*c2c66affSColin Finck 
4653*c2c66affSColin Finck     lpFromDevInst = pSetupStringTableStringFromId(StringTable, dnFromDevInst);
4654*c2c66affSColin Finck     if (lpFromDevInst == NULL)
4655*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
4656*c2c66affSColin Finck 
4657*c2c66affSColin Finck     lpToDevInst = pSetupStringTableStringFromId(StringTable, dnToDevInst);
4658*c2c66affSColin Finck     if (lpToDevInst == NULL)
4659*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
4660*c2c66affSColin Finck 
4661*c2c66affSColin Finck     RpcTryExcept
4662*c2c66affSColin Finck     {
4663*c2c66affSColin Finck         ret = PNP_DeviceInstanceAction(BindingHandle,
4664*c2c66affSColin Finck                                        PNP_DEVINST_MOVE,
4665*c2c66affSColin Finck                                        ulFlags,
4666*c2c66affSColin Finck                                        lpFromDevInst,
4667*c2c66affSColin Finck                                        lpToDevInst);
4668*c2c66affSColin Finck     }
4669*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4670*c2c66affSColin Finck     {
4671*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4672*c2c66affSColin Finck     }
4673*c2c66affSColin Finck     RpcEndExcept;
4674*c2c66affSColin Finck 
4675*c2c66affSColin Finck     return ret;
4676*c2c66affSColin Finck }
4677*c2c66affSColin Finck 
4678*c2c66affSColin Finck 
4679*c2c66affSColin Finck /***********************************************************************
4680*c2c66affSColin Finck  * CM_Next_Range [SETUPAPI.@]
4681*c2c66affSColin Finck  */
4682*c2c66affSColin Finck CONFIGRET
4683*c2c66affSColin Finck WINAPI
4684*c2c66affSColin Finck CM_Next_Range(
4685*c2c66affSColin Finck     _Inout_ PRANGE_ELEMENT preElement,
4686*c2c66affSColin Finck     _Out_ PDWORDLONG pullStart,
4687*c2c66affSColin Finck     _Out_ PDWORDLONG pullEnd,
4688*c2c66affSColin Finck     _In_ ULONG ulFlags)
4689*c2c66affSColin Finck {
4690*c2c66affSColin Finck     FIXME("CM_Next_Range(%p %p %p %lx)\n",
4691*c2c66affSColin Finck           preElement, pullStart, pullEnd, ulFlags);
4692*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
4693*c2c66affSColin Finck }
4694*c2c66affSColin Finck 
4695*c2c66affSColin Finck 
4696*c2c66affSColin Finck /***********************************************************************
4697*c2c66affSColin Finck  * CM_Open_Class_KeyA [SETUPAPI.@]
4698*c2c66affSColin Finck  */
4699*c2c66affSColin Finck CONFIGRET WINAPI CM_Open_Class_KeyA(
4700*c2c66affSColin Finck     LPGUID pClassGuid, LPCSTR pszClassName, REGSAM samDesired,
4701*c2c66affSColin Finck     REGDISPOSITION Disposition, PHKEY phkClass, ULONG ulFlags)
4702*c2c66affSColin Finck {
4703*c2c66affSColin Finck     TRACE("%p %s %lx %lx %p %lx\n",
4704*c2c66affSColin Finck           debugstr_guid(pClassGuid), pszClassName,
4705*c2c66affSColin Finck           samDesired, Disposition, phkClass, ulFlags);
4706*c2c66affSColin Finck 
4707*c2c66affSColin Finck     return CM_Open_Class_Key_ExA(pClassGuid, pszClassName, samDesired,
4708*c2c66affSColin Finck                                  Disposition, phkClass, ulFlags, NULL);
4709*c2c66affSColin Finck }
4710*c2c66affSColin Finck 
4711*c2c66affSColin Finck 
4712*c2c66affSColin Finck /***********************************************************************
4713*c2c66affSColin Finck  * CM_Open_Class_KeyW [SETUPAPI.@]
4714*c2c66affSColin Finck  */
4715*c2c66affSColin Finck CONFIGRET WINAPI CM_Open_Class_KeyW(
4716*c2c66affSColin Finck     LPGUID pClassGuid, LPCWSTR pszClassName, REGSAM samDesired,
4717*c2c66affSColin Finck     REGDISPOSITION Disposition, PHKEY phkClass, ULONG ulFlags)
4718*c2c66affSColin Finck {
4719*c2c66affSColin Finck     TRACE("%p %s %lx %lx %p %lx\n",
4720*c2c66affSColin Finck           debugstr_guid(pClassGuid), debugstr_w(pszClassName),
4721*c2c66affSColin Finck           samDesired, Disposition, phkClass, ulFlags);
4722*c2c66affSColin Finck 
4723*c2c66affSColin Finck     return CM_Open_Class_Key_ExW(pClassGuid, pszClassName, samDesired,
4724*c2c66affSColin Finck                                  Disposition, phkClass, ulFlags, NULL);
4725*c2c66affSColin Finck }
4726*c2c66affSColin Finck 
4727*c2c66affSColin Finck 
4728*c2c66affSColin Finck /***********************************************************************
4729*c2c66affSColin Finck  * CM_Open_Class_Key_ExA [SETUPAPI.@]
4730*c2c66affSColin Finck  */
4731*c2c66affSColin Finck CONFIGRET WINAPI CM_Open_Class_Key_ExA(
4732*c2c66affSColin Finck     LPGUID pClassGuid, LPCSTR pszClassName, REGSAM samDesired,
4733*c2c66affSColin Finck     REGDISPOSITION Disposition, PHKEY phkClass, ULONG ulFlags,
4734*c2c66affSColin Finck     HMACHINE hMachine)
4735*c2c66affSColin Finck {
4736*c2c66affSColin Finck     LPWSTR pszClassNameW = NULL;
4737*c2c66affSColin Finck     CONFIGRET ret;
4738*c2c66affSColin Finck 
4739*c2c66affSColin Finck     TRACE("%p %s %lx %lx %p %lx %lx\n",
4740*c2c66affSColin Finck           debugstr_guid(pClassGuid), pszClassName,
4741*c2c66affSColin Finck           samDesired, Disposition, phkClass, ulFlags, hMachine);
4742*c2c66affSColin Finck 
4743*c2c66affSColin Finck     if (pszClassName != NULL)
4744*c2c66affSColin Finck     {
4745*c2c66affSColin Finck        if (pSetupCaptureAndConvertAnsiArg(pszClassName, &pszClassNameW))
4746*c2c66affSColin Finck          return CR_INVALID_DATA;
4747*c2c66affSColin Finck     }
4748*c2c66affSColin Finck 
4749*c2c66affSColin Finck     ret = CM_Open_Class_Key_ExW(pClassGuid, pszClassNameW, samDesired,
4750*c2c66affSColin Finck                                 Disposition, phkClass, ulFlags, hMachine);
4751*c2c66affSColin Finck 
4752*c2c66affSColin Finck     if (pszClassNameW != NULL)
4753*c2c66affSColin Finck         MyFree(pszClassNameW);
4754*c2c66affSColin Finck 
4755*c2c66affSColin Finck     return ret;
4756*c2c66affSColin Finck }
4757*c2c66affSColin Finck 
4758*c2c66affSColin Finck 
4759*c2c66affSColin Finck /***********************************************************************
4760*c2c66affSColin Finck  * CM_Open_Class_Key_ExW [SETUPAPI.@]
4761*c2c66affSColin Finck  */
4762*c2c66affSColin Finck CONFIGRET WINAPI CM_Open_Class_Key_ExW(
4763*c2c66affSColin Finck     LPGUID pClassGuid, LPCWSTR pszClassName, REGSAM samDesired,
4764*c2c66affSColin Finck     REGDISPOSITION Disposition, PHKEY phkClass, ULONG ulFlags,
4765*c2c66affSColin Finck     HMACHINE hMachine)
4766*c2c66affSColin Finck {
4767*c2c66affSColin Finck     WCHAR szKeyName[MAX_PATH];
4768*c2c66affSColin Finck     LPWSTR lpGuidString;
4769*c2c66affSColin Finck     DWORD dwDisposition;
4770*c2c66affSColin Finck     DWORD dwError;
4771*c2c66affSColin Finck     HKEY hKey;
4772*c2c66affSColin Finck 
4773*c2c66affSColin Finck     TRACE("%p %s %lx %lx %p %lx %lx\n",
4774*c2c66affSColin Finck           debugstr_guid(pClassGuid), debugstr_w(pszClassName),
4775*c2c66affSColin Finck           samDesired, Disposition, phkClass, ulFlags, hMachine);
4776*c2c66affSColin Finck 
4777*c2c66affSColin Finck     /* Check Disposition and ulFlags */
4778*c2c66affSColin Finck     if ((Disposition & ~RegDisposition_Bits) ||
4779*c2c66affSColin Finck         (ulFlags & ~CM_OPEN_CLASS_KEY_BITS))
4780*c2c66affSColin Finck         return CR_INVALID_FLAG;
4781*c2c66affSColin Finck 
4782*c2c66affSColin Finck     /* Check phkClass */
4783*c2c66affSColin Finck     if (phkClass == NULL)
4784*c2c66affSColin Finck         return CR_INVALID_POINTER;
4785*c2c66affSColin Finck 
4786*c2c66affSColin Finck     *phkClass = NULL;
4787*c2c66affSColin Finck 
4788*c2c66affSColin Finck     if (ulFlags == CM_OPEN_CLASS_KEY_INTERFACE &&
4789*c2c66affSColin Finck         pszClassName != NULL)
4790*c2c66affSColin Finck         return CR_INVALID_DATA;
4791*c2c66affSColin Finck 
4792*c2c66affSColin Finck     if (hMachine == NULL)
4793*c2c66affSColin Finck     {
4794*c2c66affSColin Finck         hKey = HKEY_LOCAL_MACHINE;
4795*c2c66affSColin Finck     }
4796*c2c66affSColin Finck     else
4797*c2c66affSColin Finck     {
4798*c2c66affSColin Finck        if (RegConnectRegistryW(((PMACHINE_INFO)hMachine)->szMachineName,
4799*c2c66affSColin Finck                                HKEY_LOCAL_MACHINE, &hKey))
4800*c2c66affSColin Finck            return CR_REGISTRY_ERROR;
4801*c2c66affSColin Finck     }
4802*c2c66affSColin Finck 
4803*c2c66affSColin Finck     if (ulFlags & CM_OPEN_CLASS_KEY_INTERFACE)
4804*c2c66affSColin Finck     {
4805*c2c66affSColin Finck         lstrcpyW(szKeyName, DeviceClasses);
4806*c2c66affSColin Finck     }
4807*c2c66affSColin Finck     else
4808*c2c66affSColin Finck     {
4809*c2c66affSColin Finck         lstrcpyW(szKeyName, ControlClass);
4810*c2c66affSColin Finck     }
4811*c2c66affSColin Finck 
4812*c2c66affSColin Finck     if (pClassGuid != NULL)
4813*c2c66affSColin Finck     {
4814*c2c66affSColin Finck         if (UuidToStringW((UUID*)pClassGuid, &lpGuidString) != RPC_S_OK)
4815*c2c66affSColin Finck         {
4816*c2c66affSColin Finck             RegCloseKey(hKey);
4817*c2c66affSColin Finck             return CR_INVALID_DATA;
4818*c2c66affSColin Finck         }
4819*c2c66affSColin Finck 
4820*c2c66affSColin Finck         lstrcatW(szKeyName, Backslash);
4821*c2c66affSColin Finck         lstrcatW(szKeyName, lpGuidString);
4822*c2c66affSColin Finck     }
4823*c2c66affSColin Finck 
4824*c2c66affSColin Finck     if (Disposition == RegDisposition_OpenAlways)
4825*c2c66affSColin Finck     {
4826*c2c66affSColin Finck         dwError = RegCreateKeyExW(hKey, szKeyName, 0, NULL, 0, samDesired,
4827*c2c66affSColin Finck                                   NULL, phkClass, &dwDisposition);
4828*c2c66affSColin Finck     }
4829*c2c66affSColin Finck     else
4830*c2c66affSColin Finck     {
4831*c2c66affSColin Finck         dwError = RegOpenKeyExW(hKey, szKeyName, 0, samDesired, phkClass);
4832*c2c66affSColin Finck     }
4833*c2c66affSColin Finck 
4834*c2c66affSColin Finck     RegCloseKey(hKey);
4835*c2c66affSColin Finck 
4836*c2c66affSColin Finck     if (pClassGuid != NULL)
4837*c2c66affSColin Finck         RpcStringFreeW(&lpGuidString);
4838*c2c66affSColin Finck 
4839*c2c66affSColin Finck     if (dwError != ERROR_SUCCESS)
4840*c2c66affSColin Finck     {
4841*c2c66affSColin Finck         *phkClass = NULL;
4842*c2c66affSColin Finck         return CR_NO_SUCH_REGISTRY_KEY;
4843*c2c66affSColin Finck     }
4844*c2c66affSColin Finck 
4845*c2c66affSColin Finck     if (pszClassName != NULL)
4846*c2c66affSColin Finck     {
4847*c2c66affSColin Finck         RegSetValueExW(*phkClass, Class, 0, REG_SZ, (LPBYTE)pszClassName,
4848*c2c66affSColin Finck                        (lstrlenW(pszClassName) + 1) * sizeof(WCHAR));
4849*c2c66affSColin Finck     }
4850*c2c66affSColin Finck 
4851*c2c66affSColin Finck     return CR_SUCCESS;
4852*c2c66affSColin Finck }
4853*c2c66affSColin Finck 
4854*c2c66affSColin Finck 
4855*c2c66affSColin Finck /***********************************************************************
4856*c2c66affSColin Finck  * CM_Open_DevNode_Key [SETUPAPI.@]
4857*c2c66affSColin Finck  */
4858*c2c66affSColin Finck CONFIGRET WINAPI CM_Open_DevNode_Key(
4859*c2c66affSColin Finck     DEVINST dnDevNode, REGSAM samDesired, ULONG ulHardwareProfile,
4860*c2c66affSColin Finck     REGDISPOSITION Disposition, PHKEY phkDevice, ULONG ulFlags)
4861*c2c66affSColin Finck {
4862*c2c66affSColin Finck     TRACE("%lx %lx %lu %lx %p %lx\n", dnDevNode, samDesired,
4863*c2c66affSColin Finck           ulHardwareProfile, Disposition, phkDevice, ulFlags);
4864*c2c66affSColin Finck     return CM_Open_DevNode_Key_Ex(dnDevNode, samDesired, ulHardwareProfile,
4865*c2c66affSColin Finck                                   Disposition, phkDevice, ulFlags, NULL);
4866*c2c66affSColin Finck }
4867*c2c66affSColin Finck 
4868*c2c66affSColin Finck 
4869*c2c66affSColin Finck /***********************************************************************
4870*c2c66affSColin Finck  * CM_Open_DevNode_Key_Ex [SETUPAPI.@]
4871*c2c66affSColin Finck  */
4872*c2c66affSColin Finck CONFIGRET WINAPI CM_Open_DevNode_Key_Ex(
4873*c2c66affSColin Finck     DEVINST dnDevNode, REGSAM samDesired, ULONG ulHardwareProfile,
4874*c2c66affSColin Finck     REGDISPOSITION Disposition, PHKEY phkDevice, ULONG ulFlags,
4875*c2c66affSColin Finck     HMACHINE hMachine)
4876*c2c66affSColin Finck {
4877*c2c66affSColin Finck     FIXME("%lx %lx %lu %lx %p %lx %lx\n", dnDevNode, samDesired,
4878*c2c66affSColin Finck           ulHardwareProfile, Disposition, phkDevice, ulFlags, hMachine);
4879*c2c66affSColin Finck 
4880*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
4881*c2c66affSColin Finck }
4882*c2c66affSColin Finck 
4883*c2c66affSColin Finck 
4884*c2c66affSColin Finck /***********************************************************************
4885*c2c66affSColin Finck  * CM_Query_And_Remove_SubTreeA [SETUPAPI.@]
4886*c2c66affSColin Finck  */
4887*c2c66affSColin Finck CONFIGRET WINAPI CM_Query_And_Remove_SubTreeA(
4888*c2c66affSColin Finck     DEVINST dnAncestor, PPNP_VETO_TYPE pVetoType, LPSTR pszVetoName,
4889*c2c66affSColin Finck     ULONG ulNameLength, ULONG ulFlags)
4890*c2c66affSColin Finck {
4891*c2c66affSColin Finck     TRACE("%lx %p %s %lu %lx\n", dnAncestor, pVetoType, pszVetoName,
4892*c2c66affSColin Finck           ulNameLength, ulFlags);
4893*c2c66affSColin Finck 
4894*c2c66affSColin Finck     return CM_Query_And_Remove_SubTree_ExA(dnAncestor, pVetoType, pszVetoName,
4895*c2c66affSColin Finck                                            ulNameLength, ulFlags, NULL);
4896*c2c66affSColin Finck }
4897*c2c66affSColin Finck 
4898*c2c66affSColin Finck 
4899*c2c66affSColin Finck /***********************************************************************
4900*c2c66affSColin Finck  * CM_Query_And_Remove_SubTreeW [SETUPAPI.@]
4901*c2c66affSColin Finck  */
4902*c2c66affSColin Finck CONFIGRET WINAPI CM_Query_And_Remove_SubTreeW(
4903*c2c66affSColin Finck     DEVINST dnAncestor, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName,
4904*c2c66affSColin Finck     ULONG ulNameLength, ULONG ulFlags)
4905*c2c66affSColin Finck {
4906*c2c66affSColin Finck     TRACE("%lx %p %s %lu %lx\n", dnAncestor, pVetoType,
4907*c2c66affSColin Finck           debugstr_w(pszVetoName), ulNameLength, ulFlags);
4908*c2c66affSColin Finck 
4909*c2c66affSColin Finck     return CM_Query_And_Remove_SubTree_ExW(dnAncestor, pVetoType, pszVetoName,
4910*c2c66affSColin Finck                                            ulNameLength, ulFlags, NULL);
4911*c2c66affSColin Finck }
4912*c2c66affSColin Finck 
4913*c2c66affSColin Finck 
4914*c2c66affSColin Finck /***********************************************************************
4915*c2c66affSColin Finck  * CM_Query_And_Remove_SubTree_ExA [SETUPAPI.@]
4916*c2c66affSColin Finck  */
4917*c2c66affSColin Finck CONFIGRET WINAPI CM_Query_And_Remove_SubTree_ExA(
4918*c2c66affSColin Finck     DEVINST dnAncestor, PPNP_VETO_TYPE pVetoType, LPSTR pszVetoName,
4919*c2c66affSColin Finck     ULONG ulNameLength, ULONG ulFlags, HMACHINE hMachine)
4920*c2c66affSColin Finck {
4921*c2c66affSColin Finck     LPWSTR lpLocalVetoName;
4922*c2c66affSColin Finck     CONFIGRET ret;
4923*c2c66affSColin Finck 
4924*c2c66affSColin Finck     TRACE("%lx %p %s %lu %lx %lx\n", dnAncestor, pVetoType, pszVetoName,
4925*c2c66affSColin Finck           ulNameLength, ulFlags, hMachine);
4926*c2c66affSColin Finck 
4927*c2c66affSColin Finck     if (pszVetoName == NULL && ulNameLength == 0)
4928*c2c66affSColin Finck         return CR_INVALID_POINTER;
4929*c2c66affSColin Finck 
4930*c2c66affSColin Finck     lpLocalVetoName = HeapAlloc(GetProcessHeap(), 0, ulNameLength * sizeof(WCHAR));
4931*c2c66affSColin Finck     if (lpLocalVetoName == NULL)
4932*c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
4933*c2c66affSColin Finck 
4934*c2c66affSColin Finck     ret = CM_Query_And_Remove_SubTree_ExW(dnAncestor, pVetoType, lpLocalVetoName,
4935*c2c66affSColin Finck                                           ulNameLength, ulFlags, hMachine);
4936*c2c66affSColin Finck     if (ret == CR_REMOVE_VETOED)
4937*c2c66affSColin Finck     {
4938*c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
4939*c2c66affSColin Finck                                 0,
4940*c2c66affSColin Finck                                 lpLocalVetoName,
4941*c2c66affSColin Finck                                 ulNameLength,
4942*c2c66affSColin Finck                                 pszVetoName,
4943*c2c66affSColin Finck                                 ulNameLength,
4944*c2c66affSColin Finck                                 NULL,
4945*c2c66affSColin Finck                                 NULL) == 0)
4946*c2c66affSColin Finck             ret = CR_FAILURE;
4947*c2c66affSColin Finck     }
4948*c2c66affSColin Finck 
4949*c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, lpLocalVetoName);
4950*c2c66affSColin Finck 
4951*c2c66affSColin Finck     return ret;
4952*c2c66affSColin Finck }
4953*c2c66affSColin Finck 
4954*c2c66affSColin Finck 
4955*c2c66affSColin Finck /***********************************************************************
4956*c2c66affSColin Finck  * CM_Query_And_Remove_SubTree_ExW [SETUPAPI.@]
4957*c2c66affSColin Finck  */
4958*c2c66affSColin Finck CONFIGRET WINAPI CM_Query_And_Remove_SubTree_ExW(
4959*c2c66affSColin Finck     DEVINST dnAncestor, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName,
4960*c2c66affSColin Finck     ULONG ulNameLength, ULONG ulFlags, HMACHINE hMachine)
4961*c2c66affSColin Finck {
4962*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4963*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
4964*c2c66affSColin Finck     LPWSTR lpDevInst;
4965*c2c66affSColin Finck     CONFIGRET ret;
4966*c2c66affSColin Finck 
4967*c2c66affSColin Finck     TRACE("%lx %p %s %lu %lx %lx\n", dnAncestor, pVetoType,
4968*c2c66affSColin Finck           debugstr_w(pszVetoName), ulNameLength, ulFlags, hMachine);
4969*c2c66affSColin Finck 
4970*c2c66affSColin Finck     if (dnAncestor == 0)
4971*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
4972*c2c66affSColin Finck 
4973*c2c66affSColin Finck     if (ulFlags & ~CM_REMOVE_BITS)
4974*c2c66affSColin Finck         return CR_INVALID_FLAG;
4975*c2c66affSColin Finck 
4976*c2c66affSColin Finck     if (pszVetoName == NULL && ulNameLength == 0)
4977*c2c66affSColin Finck         return CR_INVALID_POINTER;
4978*c2c66affSColin Finck 
4979*c2c66affSColin Finck     if (hMachine != NULL)
4980*c2c66affSColin Finck     {
4981*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4982*c2c66affSColin Finck         if (BindingHandle == NULL)
4983*c2c66affSColin Finck             return CR_FAILURE;
4984*c2c66affSColin Finck 
4985*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
4986*c2c66affSColin Finck         if (StringTable == 0)
4987*c2c66affSColin Finck             return CR_FAILURE;
4988*c2c66affSColin Finck     }
4989*c2c66affSColin Finck     else
4990*c2c66affSColin Finck     {
4991*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
4992*c2c66affSColin Finck             return CR_FAILURE;
4993*c2c66affSColin Finck     }
4994*c2c66affSColin Finck 
4995*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnAncestor);
4996*c2c66affSColin Finck     if (lpDevInst == NULL)
4997*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
4998*c2c66affSColin Finck 
4999*c2c66affSColin Finck     RpcTryExcept
5000*c2c66affSColin Finck     {
5001*c2c66affSColin Finck         ret = PNP_QueryRemove(BindingHandle,
5002*c2c66affSColin Finck                               lpDevInst,
5003*c2c66affSColin Finck                               pVetoType,
5004*c2c66affSColin Finck                               pszVetoName,
5005*c2c66affSColin Finck                               ulNameLength,
5006*c2c66affSColin Finck                               ulFlags);
5007*c2c66affSColin Finck     }
5008*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5009*c2c66affSColin Finck     {
5010*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5011*c2c66affSColin Finck     }
5012*c2c66affSColin Finck     RpcEndExcept;
5013*c2c66affSColin Finck 
5014*c2c66affSColin Finck     return ret;
5015*c2c66affSColin Finck }
5016*c2c66affSColin Finck 
5017*c2c66affSColin Finck 
5018*c2c66affSColin Finck /***********************************************************************
5019*c2c66affSColin Finck  * CM_Query_Arbitrator_Free_Data [SETUPAPI.@]
5020*c2c66affSColin Finck  */
5021*c2c66affSColin Finck CONFIGRET WINAPI CM_Query_Arbitrator_Free_Data(
5022*c2c66affSColin Finck     PVOID pData, ULONG DataLen, DEVINST dnDevInst, RESOURCEID ResourceID,
5023*c2c66affSColin Finck     ULONG ulFlags)
5024*c2c66affSColin Finck {
5025*c2c66affSColin Finck     TRACE("%p %lu %lx %lu 0x%08lx\n", pData, DataLen, dnDevInst,
5026*c2c66affSColin Finck           ResourceID, ulFlags);
5027*c2c66affSColin Finck 
5028*c2c66affSColin Finck     return CM_Query_Arbitrator_Free_Data_Ex(pData, DataLen, dnDevInst,
5029*c2c66affSColin Finck                                             ResourceID, ulFlags, NULL);
5030*c2c66affSColin Finck }
5031*c2c66affSColin Finck 
5032*c2c66affSColin Finck 
5033*c2c66affSColin Finck /***********************************************************************
5034*c2c66affSColin Finck  * CM_Query_Arbitrator_Free_Data_Ex [SETUPAPI.@]
5035*c2c66affSColin Finck  */
5036*c2c66affSColin Finck CONFIGRET WINAPI CM_Query_Arbitrator_Free_Data_Ex(
5037*c2c66affSColin Finck   OUT PVOID pData,
5038*c2c66affSColin Finck   IN ULONG DataLen,
5039*c2c66affSColin Finck   IN DEVINST dnDevInst,
5040*c2c66affSColin Finck   IN RESOURCEID ResourceID,
5041*c2c66affSColin Finck   IN ULONG ulFlags,
5042*c2c66affSColin Finck   IN HMACHINE hMachine)
5043*c2c66affSColin Finck {
5044*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5045*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
5046*c2c66affSColin Finck     LPWSTR lpDevInst;
5047*c2c66affSColin Finck     CONFIGRET ret;
5048*c2c66affSColin Finck 
5049*c2c66affSColin Finck     TRACE("%p %lu %lx %lu 0x%08lx %p\n", pData, DataLen, dnDevInst,
5050*c2c66affSColin Finck           ResourceID, ulFlags, hMachine);
5051*c2c66affSColin Finck 
5052*c2c66affSColin Finck     if (pData == NULL || DataLen == 0)
5053*c2c66affSColin Finck         return CR_INVALID_POINTER;
5054*c2c66affSColin Finck 
5055*c2c66affSColin Finck     if (dnDevInst == 0)
5056*c2c66affSColin Finck         return CR_INVALID_DEVINST;
5057*c2c66affSColin Finck 
5058*c2c66affSColin Finck     if (ulFlags & ~CM_QUERY_ARBITRATOR_BITS)
5059*c2c66affSColin Finck         return CR_INVALID_FLAG;
5060*c2c66affSColin Finck 
5061*c2c66affSColin Finck     if (hMachine != NULL)
5062*c2c66affSColin Finck     {
5063*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5064*c2c66affSColin Finck         if (BindingHandle == NULL)
5065*c2c66affSColin Finck             return CR_FAILURE;
5066*c2c66affSColin Finck 
5067*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
5068*c2c66affSColin Finck         if (StringTable == 0)
5069*c2c66affSColin Finck             return CR_FAILURE;
5070*c2c66affSColin Finck     }
5071*c2c66affSColin Finck     else
5072*c2c66affSColin Finck     {
5073*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
5074*c2c66affSColin Finck             return CR_FAILURE;
5075*c2c66affSColin Finck     }
5076*c2c66affSColin Finck 
5077*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
5078*c2c66affSColin Finck     if (lpDevInst == NULL)
5079*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5080*c2c66affSColin Finck 
5081*c2c66affSColin Finck     RpcTryExcept
5082*c2c66affSColin Finck     {
5083*c2c66affSColin Finck         ret = PNP_QueryArbitratorFreeData(BindingHandle,
5084*c2c66affSColin Finck                                           pData,
5085*c2c66affSColin Finck                                           DataLen,
5086*c2c66affSColin Finck                                           lpDevInst,
5087*c2c66affSColin Finck                                           ResourceID,
5088*c2c66affSColin Finck                                           ulFlags);
5089*c2c66affSColin Finck     }
5090*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5091*c2c66affSColin Finck     {
5092*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5093*c2c66affSColin Finck     }
5094*c2c66affSColin Finck     RpcEndExcept;
5095*c2c66affSColin Finck 
5096*c2c66affSColin Finck     return ret;
5097*c2c66affSColin Finck }
5098*c2c66affSColin Finck 
5099*c2c66affSColin Finck 
5100*c2c66affSColin Finck /***********************************************************************
5101*c2c66affSColin Finck  * CM_Query_Arbitrator_Free_Size [SETUPAPI.@]
5102*c2c66affSColin Finck  */
5103*c2c66affSColin Finck CONFIGRET WINAPI CM_Query_Arbitrator_Free_Size(
5104*c2c66affSColin Finck     PULONG pulSize, DEVINST dnDevInst, RESOURCEID ResourceID, ULONG ulFlags)
5105*c2c66affSColin Finck {
5106*c2c66affSColin Finck     TRACE("%p %lu %lx 0x%08lx\n", pulSize, dnDevInst,ResourceID, ulFlags);
5107*c2c66affSColin Finck 
5108*c2c66affSColin Finck     return CM_Query_Arbitrator_Free_Size_Ex(pulSize, dnDevInst, ResourceID,
5109*c2c66affSColin Finck                                             ulFlags, NULL);
5110*c2c66affSColin Finck }
5111*c2c66affSColin Finck 
5112*c2c66affSColin Finck 
5113*c2c66affSColin Finck /***********************************************************************
5114*c2c66affSColin Finck  * CM_Query_Arbitrator_Free_Size_Ex [SETUPAPI.@]
5115*c2c66affSColin Finck  */
5116*c2c66affSColin Finck CONFIGRET WINAPI CM_Query_Arbitrator_Free_Size_Ex(
5117*c2c66affSColin Finck       PULONG pulSize, DEVINST dnDevInst, RESOURCEID ResourceID,
5118*c2c66affSColin Finck       ULONG ulFlags, HMACHINE hMachine)
5119*c2c66affSColin Finck {
5120*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5121*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
5122*c2c66affSColin Finck     LPWSTR lpDevInst;
5123*c2c66affSColin Finck     CONFIGRET ret;
5124*c2c66affSColin Finck 
5125*c2c66affSColin Finck     TRACE("%p %lu %lx 0x%08lx %p\n", pulSize, dnDevInst,ResourceID, ulFlags,
5126*c2c66affSColin Finck           hMachine);
5127*c2c66affSColin Finck 
5128*c2c66affSColin Finck     if (pulSize == NULL)
5129*c2c66affSColin Finck         return CR_INVALID_POINTER;
5130*c2c66affSColin Finck 
5131*c2c66affSColin Finck     if (dnDevInst == 0)
5132*c2c66affSColin Finck         return CR_INVALID_DEVINST;
5133*c2c66affSColin Finck 
5134*c2c66affSColin Finck     if (ulFlags & ~CM_QUERY_ARBITRATOR_BITS)
5135*c2c66affSColin Finck         return CR_INVALID_FLAG;
5136*c2c66affSColin Finck 
5137*c2c66affSColin Finck     if (hMachine != NULL)
5138*c2c66affSColin Finck     {
5139*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5140*c2c66affSColin Finck         if (BindingHandle == NULL)
5141*c2c66affSColin Finck             return CR_FAILURE;
5142*c2c66affSColin Finck 
5143*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
5144*c2c66affSColin Finck         if (StringTable == 0)
5145*c2c66affSColin Finck             return CR_FAILURE;
5146*c2c66affSColin Finck     }
5147*c2c66affSColin Finck     else
5148*c2c66affSColin Finck     {
5149*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
5150*c2c66affSColin Finck             return CR_FAILURE;
5151*c2c66affSColin Finck     }
5152*c2c66affSColin Finck 
5153*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
5154*c2c66affSColin Finck     if (lpDevInst == NULL)
5155*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5156*c2c66affSColin Finck 
5157*c2c66affSColin Finck     RpcTryExcept
5158*c2c66affSColin Finck     {
5159*c2c66affSColin Finck         ret = PNP_QueryArbitratorFreeSize(BindingHandle,
5160*c2c66affSColin Finck                                           pulSize,
5161*c2c66affSColin Finck                                           lpDevInst,
5162*c2c66affSColin Finck                                           ResourceID,
5163*c2c66affSColin Finck                                           ulFlags);
5164*c2c66affSColin Finck     }
5165*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5166*c2c66affSColin Finck     {
5167*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5168*c2c66affSColin Finck     }
5169*c2c66affSColin Finck     RpcEndExcept;
5170*c2c66affSColin Finck 
5171*c2c66affSColin Finck     return ret;
5172*c2c66affSColin Finck }
5173*c2c66affSColin Finck 
5174*c2c66affSColin Finck 
5175*c2c66affSColin Finck /***********************************************************************
5176*c2c66affSColin Finck  * CM_Query_Remove_SubTree [SETUPAPI.@]
5177*c2c66affSColin Finck  *
5178*c2c66affSColin Finck  * This function is obsolete in Windows XP and above.
5179*c2c66affSColin Finck  */
5180*c2c66affSColin Finck CONFIGRET WINAPI CM_Query_Remove_SubTree(
5181*c2c66affSColin Finck     DEVINST dnAncestor, ULONG ulFlags)
5182*c2c66affSColin Finck {
5183*c2c66affSColin Finck     TRACE("%lx %lx\n", dnAncestor, ulFlags);
5184*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
5185*c2c66affSColin Finck }
5186*c2c66affSColin Finck 
5187*c2c66affSColin Finck 
5188*c2c66affSColin Finck /***********************************************************************
5189*c2c66affSColin Finck  * CM_Query_Remove_SubTree_Ex [SETUPAPI.@]
5190*c2c66affSColin Finck  *
5191*c2c66affSColin Finck  * This function is obsolete in Windows XP and above.
5192*c2c66affSColin Finck  */
5193*c2c66affSColin Finck CONFIGRET WINAPI CM_Query_Remove_SubTree_Ex(
5194*c2c66affSColin Finck     DEVINST dnAncestor, ULONG ulFlags, HMACHINE hMachine)
5195*c2c66affSColin Finck {
5196*c2c66affSColin Finck     TRACE("%lx %lx %lx\n", dnAncestor, ulFlags, hMachine);
5197*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
5198*c2c66affSColin Finck }
5199*c2c66affSColin Finck 
5200*c2c66affSColin Finck 
5201*c2c66affSColin Finck /***********************************************************************
5202*c2c66affSColin Finck  * CM_Reenumerate_DevNode [SETUPAPI.@]
5203*c2c66affSColin Finck  */
5204*c2c66affSColin Finck CONFIGRET WINAPI CM_Reenumerate_DevNode(
5205*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulFlags)
5206*c2c66affSColin Finck {
5207*c2c66affSColin Finck     TRACE("%lx %lx\n", dnDevInst, ulFlags);
5208*c2c66affSColin Finck     return CM_Reenumerate_DevNode_Ex(dnDevInst, ulFlags, NULL);
5209*c2c66affSColin Finck }
5210*c2c66affSColin Finck 
5211*c2c66affSColin Finck 
5212*c2c66affSColin Finck /***********************************************************************
5213*c2c66affSColin Finck  * CM_Reenumerate_DevNode_Ex [SETUPAPI.@]
5214*c2c66affSColin Finck  */
5215*c2c66affSColin Finck CONFIGRET WINAPI
5216*c2c66affSColin Finck CM_Reenumerate_DevNode_Ex(
5217*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
5218*c2c66affSColin Finck {
5219*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5220*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
5221*c2c66affSColin Finck     LPWSTR lpDevInst;
5222*c2c66affSColin Finck     CONFIGRET ret;
5223*c2c66affSColin Finck 
5224*c2c66affSColin Finck     FIXME("%lx %lx %lx\n", dnDevInst, ulFlags, hMachine);
5225*c2c66affSColin Finck 
5226*c2c66affSColin Finck     if (dnDevInst == 0)
5227*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5228*c2c66affSColin Finck 
5229*c2c66affSColin Finck     if (ulFlags & ~CM_REENUMERATE_BITS)
5230*c2c66affSColin Finck         return CR_INVALID_FLAG;
5231*c2c66affSColin Finck 
5232*c2c66affSColin Finck     if (hMachine != NULL)
5233*c2c66affSColin Finck     {
5234*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5235*c2c66affSColin Finck         if (BindingHandle == NULL)
5236*c2c66affSColin Finck             return CR_FAILURE;
5237*c2c66affSColin Finck 
5238*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
5239*c2c66affSColin Finck         if (StringTable == 0)
5240*c2c66affSColin Finck             return CR_FAILURE;
5241*c2c66affSColin Finck     }
5242*c2c66affSColin Finck     else
5243*c2c66affSColin Finck     {
5244*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
5245*c2c66affSColin Finck             return CR_FAILURE;
5246*c2c66affSColin Finck     }
5247*c2c66affSColin Finck 
5248*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
5249*c2c66affSColin Finck     if (lpDevInst == NULL)
5250*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5251*c2c66affSColin Finck 
5252*c2c66affSColin Finck     RpcTryExcept
5253*c2c66affSColin Finck     {
5254*c2c66affSColin Finck         ret = PNP_DeviceInstanceAction(BindingHandle,
5255*c2c66affSColin Finck                                        PNP_DEVINST_REENUMERATE,
5256*c2c66affSColin Finck                                        ulFlags,
5257*c2c66affSColin Finck                                        lpDevInst,
5258*c2c66affSColin Finck                                        NULL);
5259*c2c66affSColin Finck     }
5260*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5261*c2c66affSColin Finck     {
5262*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5263*c2c66affSColin Finck     }
5264*c2c66affSColin Finck     RpcEndExcept;
5265*c2c66affSColin Finck 
5266*c2c66affSColin Finck     return ret;
5267*c2c66affSColin Finck }
5268*c2c66affSColin Finck 
5269*c2c66affSColin Finck 
5270*c2c66affSColin Finck /***********************************************************************
5271*c2c66affSColin Finck  * CM_Register_Device_InterfaceA [SETUPAPI.@]
5272*c2c66affSColin Finck  */
5273*c2c66affSColin Finck CONFIGRET WINAPI CM_Register_Device_InterfaceA(
5274*c2c66affSColin Finck     DEVINST dnDevInst, LPGUID InterfaceClassGuid, LPCSTR pszReference,
5275*c2c66affSColin Finck     LPSTR pszDeviceInterface, PULONG pulLength, ULONG ulFlags)
5276*c2c66affSColin Finck {
5277*c2c66affSColin Finck     TRACE("%lx %s %s %p %p %lx\n", dnDevInst, debugstr_guid(InterfaceClassGuid),
5278*c2c66affSColin Finck           pszReference, pszDeviceInterface, pulLength, ulFlags);
5279*c2c66affSColin Finck 
5280*c2c66affSColin Finck     return CM_Register_Device_Interface_ExA(dnDevInst, InterfaceClassGuid,
5281*c2c66affSColin Finck                                             pszReference, pszDeviceInterface,
5282*c2c66affSColin Finck                                             pulLength, ulFlags, NULL);
5283*c2c66affSColin Finck }
5284*c2c66affSColin Finck 
5285*c2c66affSColin Finck 
5286*c2c66affSColin Finck /***********************************************************************
5287*c2c66affSColin Finck  * CM_Register_Device_InterfaceW [SETUPAPI.@]
5288*c2c66affSColin Finck  */
5289*c2c66affSColin Finck CONFIGRET WINAPI CM_Register_Device_InterfaceW(
5290*c2c66affSColin Finck     DEVINST dnDevInst, LPGUID InterfaceClassGuid, LPCWSTR pszReference,
5291*c2c66affSColin Finck     LPWSTR pszDeviceInterface, PULONG pulLength, ULONG ulFlags)
5292*c2c66affSColin Finck {
5293*c2c66affSColin Finck     TRACE("%lx %s %s %p %p %lx\n", dnDevInst, debugstr_guid(InterfaceClassGuid),
5294*c2c66affSColin Finck           debugstr_w(pszReference), pszDeviceInterface, pulLength, ulFlags);
5295*c2c66affSColin Finck 
5296*c2c66affSColin Finck     return CM_Register_Device_Interface_ExW(dnDevInst, InterfaceClassGuid,
5297*c2c66affSColin Finck                                             pszReference, pszDeviceInterface,
5298*c2c66affSColin Finck                                             pulLength, ulFlags, NULL);
5299*c2c66affSColin Finck }
5300*c2c66affSColin Finck 
5301*c2c66affSColin Finck 
5302*c2c66affSColin Finck /***********************************************************************
5303*c2c66affSColin Finck  * CM_Register_Device_Interface_ExA [SETUPAPI.@]
5304*c2c66affSColin Finck  */
5305*c2c66affSColin Finck CONFIGRET WINAPI CM_Register_Device_Interface_ExA(
5306*c2c66affSColin Finck     DEVINST dnDevInst, LPGUID InterfaceClassGuid, LPCSTR pszReference,
5307*c2c66affSColin Finck     LPSTR pszDeviceInterface, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
5308*c2c66affSColin Finck {
5309*c2c66affSColin Finck     LPWSTR pszReferenceW = NULL;
5310*c2c66affSColin Finck     LPWSTR pszDeviceInterfaceW = NULL;
5311*c2c66affSColin Finck     ULONG ulLength;
5312*c2c66affSColin Finck     CONFIGRET ret;
5313*c2c66affSColin Finck 
5314*c2c66affSColin Finck     TRACE("%lx %s %s %p %p %lx %lx\n", dnDevInst, debugstr_guid(InterfaceClassGuid),
5315*c2c66affSColin Finck           pszReference, pszDeviceInterface, pulLength, ulFlags, hMachine);
5316*c2c66affSColin Finck 
5317*c2c66affSColin Finck     if (pulLength == NULL || pszDeviceInterface == NULL)
5318*c2c66affSColin Finck         return CR_INVALID_POINTER;
5319*c2c66affSColin Finck 
5320*c2c66affSColin Finck     if (pszReference != NULL)
5321*c2c66affSColin Finck     {
5322*c2c66affSColin Finck         if (pSetupCaptureAndConvertAnsiArg(pszReference, &pszReferenceW))
5323*c2c66affSColin Finck             return CR_INVALID_DATA;
5324*c2c66affSColin Finck     }
5325*c2c66affSColin Finck 
5326*c2c66affSColin Finck     ulLength = *pulLength;
5327*c2c66affSColin Finck 
5328*c2c66affSColin Finck     pszDeviceInterfaceW = HeapAlloc(GetProcessHeap(), 0, ulLength * sizeof(WCHAR));
5329*c2c66affSColin Finck     if (pszDeviceInterfaceW == NULL)
5330*c2c66affSColin Finck     {
5331*c2c66affSColin Finck         ret = CR_OUT_OF_MEMORY;
5332*c2c66affSColin Finck         goto Done;
5333*c2c66affSColin Finck     }
5334*c2c66affSColin Finck 
5335*c2c66affSColin Finck     ret = CM_Register_Device_Interface_ExW(dnDevInst,
5336*c2c66affSColin Finck                                            InterfaceClassGuid,
5337*c2c66affSColin Finck                                            pszReferenceW,
5338*c2c66affSColin Finck                                            pszDeviceInterfaceW,
5339*c2c66affSColin Finck                                            &ulLength,
5340*c2c66affSColin Finck                                            ulFlags,
5341*c2c66affSColin Finck                                            hMachine);
5342*c2c66affSColin Finck     if (ret == CR_SUCCESS)
5343*c2c66affSColin Finck     {
5344*c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
5345*c2c66affSColin Finck                                 0,
5346*c2c66affSColin Finck                                 pszDeviceInterfaceW,
5347*c2c66affSColin Finck                                 ulLength,
5348*c2c66affSColin Finck                                 pszDeviceInterface,
5349*c2c66affSColin Finck                                 *pulLength,
5350*c2c66affSColin Finck                                 NULL,
5351*c2c66affSColin Finck                                 NULL) == 0)
5352*c2c66affSColin Finck             ret = CR_FAILURE;
5353*c2c66affSColin Finck     }
5354*c2c66affSColin Finck 
5355*c2c66affSColin Finck     *pulLength = ulLength;
5356*c2c66affSColin Finck 
5357*c2c66affSColin Finck Done:
5358*c2c66affSColin Finck     if (pszDeviceInterfaceW != NULL)
5359*c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, pszDeviceInterfaceW);
5360*c2c66affSColin Finck 
5361*c2c66affSColin Finck     if (pszReferenceW != NULL)
5362*c2c66affSColin Finck         MyFree(pszReferenceW);
5363*c2c66affSColin Finck 
5364*c2c66affSColin Finck     return ret;
5365*c2c66affSColin Finck }
5366*c2c66affSColin Finck 
5367*c2c66affSColin Finck 
5368*c2c66affSColin Finck /***********************************************************************
5369*c2c66affSColin Finck  * CM_Register_Device_Interface_ExW [SETUPAPI.@]
5370*c2c66affSColin Finck  */
5371*c2c66affSColin Finck CONFIGRET WINAPI CM_Register_Device_Interface_ExW(
5372*c2c66affSColin Finck     DEVINST dnDevInst, LPGUID InterfaceClassGuid, LPCWSTR pszReference,
5373*c2c66affSColin Finck     LPWSTR pszDeviceInterface, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
5374*c2c66affSColin Finck {
5375*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5376*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
5377*c2c66affSColin Finck     LPWSTR lpDevInst;
5378*c2c66affSColin Finck     ULONG ulTransferLength;
5379*c2c66affSColin Finck     CONFIGRET ret;
5380*c2c66affSColin Finck 
5381*c2c66affSColin Finck     TRACE("%lx %s %s %p %p %lx %lx\n", dnDevInst, debugstr_guid(InterfaceClassGuid),
5382*c2c66affSColin Finck           debugstr_w(pszReference), pszDeviceInterface, pulLength, ulFlags, hMachine);
5383*c2c66affSColin Finck 
5384*c2c66affSColin Finck     if (dnDevInst == 0)
5385*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5386*c2c66affSColin Finck 
5387*c2c66affSColin Finck     if (InterfaceClassGuid == NULL ||
5388*c2c66affSColin Finck         pszDeviceInterface == NULL ||
5389*c2c66affSColin Finck         pulLength == NULL)
5390*c2c66affSColin Finck         return CR_INVALID_POINTER;
5391*c2c66affSColin Finck 
5392*c2c66affSColin Finck     if (ulFlags != 0)
5393*c2c66affSColin Finck         return CR_INVALID_FLAG;
5394*c2c66affSColin Finck 
5395*c2c66affSColin Finck     if (hMachine != NULL)
5396*c2c66affSColin Finck     {
5397*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5398*c2c66affSColin Finck         if (BindingHandle == NULL)
5399*c2c66affSColin Finck             return CR_FAILURE;
5400*c2c66affSColin Finck 
5401*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
5402*c2c66affSColin Finck         if (StringTable == 0)
5403*c2c66affSColin Finck             return CR_FAILURE;
5404*c2c66affSColin Finck     }
5405*c2c66affSColin Finck     else
5406*c2c66affSColin Finck     {
5407*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
5408*c2c66affSColin Finck             return CR_FAILURE;
5409*c2c66affSColin Finck     }
5410*c2c66affSColin Finck 
5411*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
5412*c2c66affSColin Finck     if (lpDevInst == NULL)
5413*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5414*c2c66affSColin Finck 
5415*c2c66affSColin Finck     ulTransferLength = *pulLength;
5416*c2c66affSColin Finck 
5417*c2c66affSColin Finck     RpcTryExcept
5418*c2c66affSColin Finck     {
5419*c2c66affSColin Finck         ret = PNP_RegisterDeviceClassAssociation(BindingHandle,
5420*c2c66affSColin Finck                                                  lpDevInst,
5421*c2c66affSColin Finck                                                  InterfaceClassGuid,
5422*c2c66affSColin Finck                                                  (LPWSTR)pszReference,
5423*c2c66affSColin Finck                                                  pszDeviceInterface,
5424*c2c66affSColin Finck                                                  pulLength,
5425*c2c66affSColin Finck                                                  &ulTransferLength,
5426*c2c66affSColin Finck                                                  0);
5427*c2c66affSColin Finck     }
5428*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5429*c2c66affSColin Finck     {
5430*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5431*c2c66affSColin Finck     }
5432*c2c66affSColin Finck     RpcEndExcept;
5433*c2c66affSColin Finck 
5434*c2c66affSColin Finck     return ret;
5435*c2c66affSColin Finck }
5436*c2c66affSColin Finck 
5437*c2c66affSColin Finck 
5438*c2c66affSColin Finck /***********************************************************************
5439*c2c66affSColin Finck  * CM_Register_Device_Driver [SETUPAPI.@]
5440*c2c66affSColin Finck  */
5441*c2c66affSColin Finck CONFIGRET WINAPI CM_Register_Device_Driver(
5442*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulFlags)
5443*c2c66affSColin Finck {
5444*c2c66affSColin Finck     TRACE("%lx 0x%08lx\n", dnDevInst, ulFlags);
5445*c2c66affSColin Finck     return CM_Register_Device_Driver_Ex(dnDevInst, ulFlags, NULL);
5446*c2c66affSColin Finck }
5447*c2c66affSColin Finck 
5448*c2c66affSColin Finck 
5449*c2c66affSColin Finck /***********************************************************************
5450*c2c66affSColin Finck  * CM_Register_Device_Driver [SETUPAPI.@]
5451*c2c66affSColin Finck  */
5452*c2c66affSColin Finck CONFIGRET WINAPI CM_Register_Device_Driver_Ex(
5453*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
5454*c2c66affSColin Finck {
5455*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5456*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
5457*c2c66affSColin Finck     LPWSTR lpDevInst;
5458*c2c66affSColin Finck     CONFIGRET ret;
5459*c2c66affSColin Finck 
5460*c2c66affSColin Finck     TRACE("%lx 0x%08lx %p\n", dnDevInst, ulFlags, hMachine);
5461*c2c66affSColin Finck 
5462*c2c66affSColin Finck     if (dnDevInst == 0)
5463*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5464*c2c66affSColin Finck 
5465*c2c66affSColin Finck     if (ulFlags & ~CM_REGISTER_DEVICE_DRIVER_BITS)
5466*c2c66affSColin Finck         return CR_INVALID_FLAG;
5467*c2c66affSColin Finck 
5468*c2c66affSColin Finck     if (hMachine != NULL)
5469*c2c66affSColin Finck     {
5470*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5471*c2c66affSColin Finck         if (BindingHandle == NULL)
5472*c2c66affSColin Finck             return CR_FAILURE;
5473*c2c66affSColin Finck 
5474*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
5475*c2c66affSColin Finck         if (StringTable == 0)
5476*c2c66affSColin Finck             return CR_FAILURE;
5477*c2c66affSColin Finck     }
5478*c2c66affSColin Finck     else
5479*c2c66affSColin Finck     {
5480*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
5481*c2c66affSColin Finck             return CR_FAILURE;
5482*c2c66affSColin Finck     }
5483*c2c66affSColin Finck 
5484*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
5485*c2c66affSColin Finck     if (lpDevInst == NULL)
5486*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5487*c2c66affSColin Finck 
5488*c2c66affSColin Finck     RpcTryExcept
5489*c2c66affSColin Finck     {
5490*c2c66affSColin Finck         ret = PNP_RegisterDriver(BindingHandle,
5491*c2c66affSColin Finck                                  lpDevInst,
5492*c2c66affSColin Finck                                  ulFlags);
5493*c2c66affSColin Finck     }
5494*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5495*c2c66affSColin Finck     {
5496*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5497*c2c66affSColin Finck     }
5498*c2c66affSColin Finck     RpcEndExcept;
5499*c2c66affSColin Finck 
5500*c2c66affSColin Finck     return ret;
5501*c2c66affSColin Finck }
5502*c2c66affSColin Finck 
5503*c2c66affSColin Finck 
5504*c2c66affSColin Finck /***********************************************************************
5505*c2c66affSColin Finck  * CM_Remove_SubTree [SETUPAPI.@]
5506*c2c66affSColin Finck  *
5507*c2c66affSColin Finck  * This function is obsolete in Windows XP and above.
5508*c2c66affSColin Finck  */
5509*c2c66affSColin Finck CONFIGRET WINAPI CM_Remove_SubTree(
5510*c2c66affSColin Finck     DEVINST dnAncestor, ULONG ulFlags)
5511*c2c66affSColin Finck {
5512*c2c66affSColin Finck     TRACE("%lx %lx\n", dnAncestor, ulFlags);
5513*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
5514*c2c66affSColin Finck }
5515*c2c66affSColin Finck 
5516*c2c66affSColin Finck 
5517*c2c66affSColin Finck /***********************************************************************
5518*c2c66affSColin Finck  * CM_Remove_SubTree_Ex [SETUPAPI.@]
5519*c2c66affSColin Finck  *
5520*c2c66affSColin Finck  * This function is obsolete in Windows XP and above.
5521*c2c66affSColin Finck  */
5522*c2c66affSColin Finck CONFIGRET WINAPI CM_Remove_SubTree_Ex(
5523*c2c66affSColin Finck     DEVINST dnAncestor, ULONG ulFlags, HMACHINE hMachine)
5524*c2c66affSColin Finck {
5525*c2c66affSColin Finck     TRACE("%lx %lx %lx\n", dnAncestor, ulFlags, hMachine);
5526*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
5527*c2c66affSColin Finck }
5528*c2c66affSColin Finck 
5529*c2c66affSColin Finck 
5530*c2c66affSColin Finck /***********************************************************************
5531*c2c66affSColin Finck  * CM_Request_Device_EjectA [SETUPAPI.@]
5532*c2c66affSColin Finck  */
5533*c2c66affSColin Finck CONFIGRET WINAPI CM_Request_Device_EjectA(
5534*c2c66affSColin Finck     DEVINST dnDevInst, PPNP_VETO_TYPE pVetoType, LPSTR pszVetoName,
5535*c2c66affSColin Finck     ULONG ulNameLength, ULONG ulFlags)
5536*c2c66affSColin Finck {
5537*c2c66affSColin Finck     TRACE("%lx %p %s %lu %lx\n", dnDevInst, pVetoType, pszVetoName,
5538*c2c66affSColin Finck           ulNameLength, ulFlags);
5539*c2c66affSColin Finck     return CM_Request_Device_Eject_ExA(dnDevInst, pVetoType, pszVetoName,
5540*c2c66affSColin Finck                                        ulNameLength, ulFlags, NULL);
5541*c2c66affSColin Finck }
5542*c2c66affSColin Finck 
5543*c2c66affSColin Finck 
5544*c2c66affSColin Finck /***********************************************************************
5545*c2c66affSColin Finck  * CM_Request_Device_EjectW [SETUPAPI.@]
5546*c2c66affSColin Finck  */
5547*c2c66affSColin Finck CONFIGRET WINAPI CM_Request_Device_EjectW(
5548*c2c66affSColin Finck     DEVINST dnDevInst, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName,
5549*c2c66affSColin Finck     ULONG ulNameLength, ULONG ulFlags)
5550*c2c66affSColin Finck {
5551*c2c66affSColin Finck     TRACE("%lx %p %s %lu %lx\n", dnDevInst, pVetoType, debugstr_w(pszVetoName),
5552*c2c66affSColin Finck           ulNameLength, ulFlags);
5553*c2c66affSColin Finck     return CM_Request_Device_Eject_ExW(dnDevInst, pVetoType, pszVetoName,
5554*c2c66affSColin Finck                                        ulNameLength, ulFlags, NULL);
5555*c2c66affSColin Finck }
5556*c2c66affSColin Finck 
5557*c2c66affSColin Finck 
5558*c2c66affSColin Finck /***********************************************************************
5559*c2c66affSColin Finck  * CM_Request_Device_Eject_ExA [SETUPAPI.@]
5560*c2c66affSColin Finck  */
5561*c2c66affSColin Finck CONFIGRET WINAPI CM_Request_Device_Eject_ExA(
5562*c2c66affSColin Finck     DEVINST dnDevInst, PPNP_VETO_TYPE pVetoType, LPSTR pszVetoName,
5563*c2c66affSColin Finck     ULONG ulNameLength, ULONG ulFlags, HMACHINE hMachine)
5564*c2c66affSColin Finck {
5565*c2c66affSColin Finck     LPWSTR lpLocalVetoName;
5566*c2c66affSColin Finck     CONFIGRET ret;
5567*c2c66affSColin Finck 
5568*c2c66affSColin Finck     TRACE("%lx %p %s %lu %lx %lx\n", dnDevInst, pVetoType, pszVetoName,
5569*c2c66affSColin Finck           ulNameLength, ulFlags, hMachine);
5570*c2c66affSColin Finck 
5571*c2c66affSColin Finck     if (pszVetoName == NULL && ulNameLength == 0)
5572*c2c66affSColin Finck         return CR_INVALID_POINTER;
5573*c2c66affSColin Finck 
5574*c2c66affSColin Finck     lpLocalVetoName = HeapAlloc(GetProcessHeap(), 0, ulNameLength * sizeof(WCHAR));
5575*c2c66affSColin Finck     if (lpLocalVetoName == NULL)
5576*c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
5577*c2c66affSColin Finck 
5578*c2c66affSColin Finck     ret = CM_Request_Device_Eject_ExW(dnDevInst, pVetoType, lpLocalVetoName,
5579*c2c66affSColin Finck                                       ulNameLength, ulFlags, hMachine);
5580*c2c66affSColin Finck     if (ret == CR_REMOVE_VETOED)
5581*c2c66affSColin Finck     {
5582*c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
5583*c2c66affSColin Finck                                 0,
5584*c2c66affSColin Finck                                 lpLocalVetoName,
5585*c2c66affSColin Finck                                 ulNameLength,
5586*c2c66affSColin Finck                                 pszVetoName,
5587*c2c66affSColin Finck                                 ulNameLength,
5588*c2c66affSColin Finck                                 NULL,
5589*c2c66affSColin Finck                                 NULL) == 0)
5590*c2c66affSColin Finck             ret = CR_FAILURE;
5591*c2c66affSColin Finck     }
5592*c2c66affSColin Finck 
5593*c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, lpLocalVetoName);
5594*c2c66affSColin Finck 
5595*c2c66affSColin Finck     return ret;
5596*c2c66affSColin Finck }
5597*c2c66affSColin Finck 
5598*c2c66affSColin Finck 
5599*c2c66affSColin Finck /***********************************************************************
5600*c2c66affSColin Finck  * CM_Request_Device_Eject_ExW [SETUPAPI.@]
5601*c2c66affSColin Finck  */
5602*c2c66affSColin Finck CONFIGRET WINAPI CM_Request_Device_Eject_ExW(
5603*c2c66affSColin Finck     DEVINST dnDevInst, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName,
5604*c2c66affSColin Finck     ULONG ulNameLength, ULONG ulFlags, HMACHINE hMachine)
5605*c2c66affSColin Finck {
5606*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5607*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
5608*c2c66affSColin Finck     LPWSTR lpDevInst;
5609*c2c66affSColin Finck     CONFIGRET ret;
5610*c2c66affSColin Finck 
5611*c2c66affSColin Finck     TRACE("%lx %p %s %lu %lx %lx\n", dnDevInst, pVetoType,
5612*c2c66affSColin Finck           debugstr_w(pszVetoName), ulNameLength, ulFlags, hMachine);
5613*c2c66affSColin Finck 
5614*c2c66affSColin Finck     if (dnDevInst == 0)
5615*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5616*c2c66affSColin Finck 
5617*c2c66affSColin Finck     if (ulFlags != 0)
5618*c2c66affSColin Finck         return CR_INVALID_FLAG;
5619*c2c66affSColin Finck 
5620*c2c66affSColin Finck     if (pszVetoName == NULL && ulNameLength == 0)
5621*c2c66affSColin Finck         return CR_INVALID_POINTER;
5622*c2c66affSColin Finck 
5623*c2c66affSColin Finck     if (hMachine != NULL)
5624*c2c66affSColin Finck     {
5625*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5626*c2c66affSColin Finck         if (BindingHandle == NULL)
5627*c2c66affSColin Finck             return CR_FAILURE;
5628*c2c66affSColin Finck 
5629*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
5630*c2c66affSColin Finck         if (StringTable == 0)
5631*c2c66affSColin Finck             return CR_FAILURE;
5632*c2c66affSColin Finck     }
5633*c2c66affSColin Finck     else
5634*c2c66affSColin Finck     {
5635*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
5636*c2c66affSColin Finck             return CR_FAILURE;
5637*c2c66affSColin Finck     }
5638*c2c66affSColin Finck 
5639*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
5640*c2c66affSColin Finck     if (lpDevInst == NULL)
5641*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5642*c2c66affSColin Finck 
5643*c2c66affSColin Finck     RpcTryExcept
5644*c2c66affSColin Finck     {
5645*c2c66affSColin Finck         ret = PNP_RequestDeviceEject(BindingHandle,
5646*c2c66affSColin Finck                                      lpDevInst,
5647*c2c66affSColin Finck                                      pVetoType,
5648*c2c66affSColin Finck                                      pszVetoName,
5649*c2c66affSColin Finck                                      ulNameLength,
5650*c2c66affSColin Finck                                      ulFlags);
5651*c2c66affSColin Finck     }
5652*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5653*c2c66affSColin Finck     {
5654*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5655*c2c66affSColin Finck     }
5656*c2c66affSColin Finck     RpcEndExcept;
5657*c2c66affSColin Finck 
5658*c2c66affSColin Finck     return ret;
5659*c2c66affSColin Finck }
5660*c2c66affSColin Finck 
5661*c2c66affSColin Finck 
5662*c2c66affSColin Finck /***********************************************************************
5663*c2c66affSColin Finck  * CM_Request_Eject_PC [SETUPAPI.@]
5664*c2c66affSColin Finck  */
5665*c2c66affSColin Finck CONFIGRET WINAPI CM_Request_Eject_PC(VOID)
5666*c2c66affSColin Finck {
5667*c2c66affSColin Finck     TRACE("\n");
5668*c2c66affSColin Finck     return CM_Request_Eject_PC_Ex(NULL);
5669*c2c66affSColin Finck }
5670*c2c66affSColin Finck 
5671*c2c66affSColin Finck 
5672*c2c66affSColin Finck /***********************************************************************
5673*c2c66affSColin Finck  * CM_Request_Eject_PC_Ex [SETUPAPI.@]
5674*c2c66affSColin Finck  */
5675*c2c66affSColin Finck CONFIGRET WINAPI CM_Request_Eject_PC_Ex(
5676*c2c66affSColin Finck     HMACHINE hMachine)
5677*c2c66affSColin Finck {
5678*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5679*c2c66affSColin Finck     CONFIGRET ret;
5680*c2c66affSColin Finck 
5681*c2c66affSColin Finck     TRACE("%lx\n", hMachine);
5682*c2c66affSColin Finck 
5683*c2c66affSColin Finck     if (hMachine != NULL)
5684*c2c66affSColin Finck     {
5685*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5686*c2c66affSColin Finck         if (BindingHandle == NULL)
5687*c2c66affSColin Finck             return CR_FAILURE;
5688*c2c66affSColin Finck     }
5689*c2c66affSColin Finck     else
5690*c2c66affSColin Finck     {
5691*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
5692*c2c66affSColin Finck             return CR_FAILURE;
5693*c2c66affSColin Finck     }
5694*c2c66affSColin Finck 
5695*c2c66affSColin Finck     RpcTryExcept
5696*c2c66affSColin Finck     {
5697*c2c66affSColin Finck         ret = PNP_RequestEjectPC(BindingHandle);
5698*c2c66affSColin Finck     }
5699*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5700*c2c66affSColin Finck     {
5701*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5702*c2c66affSColin Finck     }
5703*c2c66affSColin Finck     RpcEndExcept;
5704*c2c66affSColin Finck 
5705*c2c66affSColin Finck     return ret;
5706*c2c66affSColin Finck }
5707*c2c66affSColin Finck 
5708*c2c66affSColin Finck 
5709*c2c66affSColin Finck /***********************************************************************
5710*c2c66affSColin Finck  * CM_Run_Detection [SETUPAPI.@]
5711*c2c66affSColin Finck  */
5712*c2c66affSColin Finck CONFIGRET WINAPI CM_Run_Detection(
5713*c2c66affSColin Finck     ULONG ulFlags)
5714*c2c66affSColin Finck {
5715*c2c66affSColin Finck     TRACE("%lx\n", ulFlags);
5716*c2c66affSColin Finck     return CM_Run_Detection_Ex(ulFlags, NULL);
5717*c2c66affSColin Finck }
5718*c2c66affSColin Finck 
5719*c2c66affSColin Finck 
5720*c2c66affSColin Finck /***********************************************************************
5721*c2c66affSColin Finck  * CM_Run_Detection_Ex [SETUPAPI.@]
5722*c2c66affSColin Finck  */
5723*c2c66affSColin Finck CONFIGRET WINAPI CM_Run_Detection_Ex(
5724*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
5725*c2c66affSColin Finck {
5726*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5727*c2c66affSColin Finck     CONFIGRET ret;
5728*c2c66affSColin Finck 
5729*c2c66affSColin Finck     TRACE("%lx %lx\n", ulFlags, hMachine);
5730*c2c66affSColin Finck 
5731*c2c66affSColin Finck     if (!pSetupIsUserAdmin())
5732*c2c66affSColin Finck         return CR_ACCESS_DENIED;
5733*c2c66affSColin Finck 
5734*c2c66affSColin Finck     if (ulFlags & ~CM_DETECT_BITS)
5735*c2c66affSColin Finck         return CR_INVALID_FLAG;
5736*c2c66affSColin Finck 
5737*c2c66affSColin Finck     if (hMachine != NULL)
5738*c2c66affSColin Finck     {
5739*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5740*c2c66affSColin Finck         if (BindingHandle == NULL)
5741*c2c66affSColin Finck             return CR_FAILURE;
5742*c2c66affSColin Finck     }
5743*c2c66affSColin Finck     else
5744*c2c66affSColin Finck     {
5745*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
5746*c2c66affSColin Finck             return CR_FAILURE;
5747*c2c66affSColin Finck     }
5748*c2c66affSColin Finck 
5749*c2c66affSColin Finck     RpcTryExcept
5750*c2c66affSColin Finck     {
5751*c2c66affSColin Finck         ret = PNP_RunDetection(BindingHandle,
5752*c2c66affSColin Finck                                ulFlags);
5753*c2c66affSColin Finck     }
5754*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5755*c2c66affSColin Finck     {
5756*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5757*c2c66affSColin Finck     }
5758*c2c66affSColin Finck     RpcEndExcept;
5759*c2c66affSColin Finck 
5760*c2c66affSColin Finck     return ret;
5761*c2c66affSColin Finck }
5762*c2c66affSColin Finck 
5763*c2c66affSColin Finck 
5764*c2c66affSColin Finck /***********************************************************************
5765*c2c66affSColin Finck  * CM_Set_Class_Registry_PropertyA [SETUPAPI.@]
5766*c2c66affSColin Finck  */
5767*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_Class_Registry_PropertyA(
5768*c2c66affSColin Finck     LPGUID ClassGuid, ULONG ulProperty, PCVOID Buffer, ULONG ulLength,
5769*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
5770*c2c66affSColin Finck {
5771*c2c66affSColin Finck     FIXME("%p %lx %p %lu %lx %p\n",
5772*c2c66affSColin Finck           ClassGuid, ulProperty, Buffer, ulLength, ulFlags, hMachine);
5773*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
5774*c2c66affSColin Finck }
5775*c2c66affSColin Finck 
5776*c2c66affSColin Finck 
5777*c2c66affSColin Finck /***********************************************************************
5778*c2c66affSColin Finck  * CM_Set_Class_Registry_PropertyW [SETUPAPI.@]
5779*c2c66affSColin Finck  */
5780*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_Class_Registry_PropertyW(
5781*c2c66affSColin Finck     LPGUID ClassGuid, ULONG ulProperty, PCVOID Buffer, ULONG ulLength,
5782*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
5783*c2c66affSColin Finck {
5784*c2c66affSColin Finck     FIXME("%p %lx %p %lu %lx %p\n",
5785*c2c66affSColin Finck           ClassGuid, ulProperty, Buffer, ulLength, ulFlags, hMachine);
5786*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
5787*c2c66affSColin Finck }
5788*c2c66affSColin Finck 
5789*c2c66affSColin Finck 
5790*c2c66affSColin Finck /***********************************************************************
5791*c2c66affSColin Finck  * CM_Set_DevNode_Problem [SETUPAPI.@]
5792*c2c66affSColin Finck  */
5793*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_DevNode_Problem(
5794*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulProblem, ULONG ulFlags)
5795*c2c66affSColin Finck {
5796*c2c66affSColin Finck     TRACE("%lx %lx %lx\n", dnDevInst, ulProblem, ulFlags);
5797*c2c66affSColin Finck     return CM_Set_DevNode_Problem_Ex(dnDevInst, ulProblem, ulFlags, NULL);
5798*c2c66affSColin Finck }
5799*c2c66affSColin Finck 
5800*c2c66affSColin Finck 
5801*c2c66affSColin Finck /***********************************************************************
5802*c2c66affSColin Finck  * CM_Set_DevNode_Problem_Ex [SETUPAPI.@]
5803*c2c66affSColin Finck  */
5804*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_DevNode_Problem_Ex(
5805*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulProblem, ULONG ulFlags, HMACHINE hMachine)
5806*c2c66affSColin Finck {
5807*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5808*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
5809*c2c66affSColin Finck     LPWSTR lpDevInst;
5810*c2c66affSColin Finck     CONFIGRET ret;
5811*c2c66affSColin Finck 
5812*c2c66affSColin Finck     TRACE("%lx %lx %lx %lx\n", dnDevInst, ulProblem, ulFlags, hMachine);
5813*c2c66affSColin Finck 
5814*c2c66affSColin Finck     if (dnDevInst == 0)
5815*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5816*c2c66affSColin Finck 
5817*c2c66affSColin Finck     if (ulFlags & ~CM_SET_DEVNODE_PROBLEM_BITS)
5818*c2c66affSColin Finck         return CR_INVALID_FLAG;
5819*c2c66affSColin Finck 
5820*c2c66affSColin Finck     if (hMachine != NULL)
5821*c2c66affSColin Finck     {
5822*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5823*c2c66affSColin Finck         if (BindingHandle == NULL)
5824*c2c66affSColin Finck             return CR_FAILURE;
5825*c2c66affSColin Finck 
5826*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
5827*c2c66affSColin Finck         if (StringTable == 0)
5828*c2c66affSColin Finck             return CR_FAILURE;
5829*c2c66affSColin Finck     }
5830*c2c66affSColin Finck     else
5831*c2c66affSColin Finck     {
5832*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
5833*c2c66affSColin Finck             return CR_FAILURE;
5834*c2c66affSColin Finck     }
5835*c2c66affSColin Finck 
5836*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
5837*c2c66affSColin Finck     if (lpDevInst == NULL)
5838*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5839*c2c66affSColin Finck 
5840*c2c66affSColin Finck     RpcTryExcept
5841*c2c66affSColin Finck     {
5842*c2c66affSColin Finck         ret = PNP_SetDeviceProblem(BindingHandle,
5843*c2c66affSColin Finck                                    lpDevInst,
5844*c2c66affSColin Finck                                    ulProblem,
5845*c2c66affSColin Finck                                    ulFlags);
5846*c2c66affSColin Finck     }
5847*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5848*c2c66affSColin Finck     {
5849*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5850*c2c66affSColin Finck     }
5851*c2c66affSColin Finck     RpcEndExcept;
5852*c2c66affSColin Finck 
5853*c2c66affSColin Finck     return ret;
5854*c2c66affSColin Finck }
5855*c2c66affSColin Finck 
5856*c2c66affSColin Finck 
5857*c2c66affSColin Finck /***********************************************************************
5858*c2c66affSColin Finck  * CM_Set_DevNode_Registry_PropertyA [SETUPAPI.@]
5859*c2c66affSColin Finck  */
5860*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_DevNode_Registry_PropertyA(
5861*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulProperty, PCVOID Buffer, ULONG ulLength,
5862*c2c66affSColin Finck     ULONG ulFlags)
5863*c2c66affSColin Finck {
5864*c2c66affSColin Finck     TRACE("%lx %lu %p %lx %lx\n",
5865*c2c66affSColin Finck           dnDevInst, ulProperty, Buffer, ulLength, ulFlags);
5866*c2c66affSColin Finck     return CM_Set_DevNode_Registry_Property_ExA(dnDevInst, ulProperty,
5867*c2c66affSColin Finck                                                 Buffer, ulLength,
5868*c2c66affSColin Finck                                                 ulFlags, NULL);
5869*c2c66affSColin Finck }
5870*c2c66affSColin Finck 
5871*c2c66affSColin Finck 
5872*c2c66affSColin Finck /***********************************************************************
5873*c2c66affSColin Finck  * CM_Set_DevNode_Registry_PropertyW [SETUPAPI.@]
5874*c2c66affSColin Finck  */
5875*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_DevNode_Registry_PropertyW(
5876*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulProperty, PCVOID Buffer, ULONG ulLength,
5877*c2c66affSColin Finck     ULONG ulFlags)
5878*c2c66affSColin Finck {
5879*c2c66affSColin Finck     TRACE("%lx %lu %p %lx %lx\n",
5880*c2c66affSColin Finck           dnDevInst, ulProperty, Buffer, ulLength, ulFlags);
5881*c2c66affSColin Finck     return CM_Set_DevNode_Registry_Property_ExW(dnDevInst, ulProperty,
5882*c2c66affSColin Finck                                                 Buffer, ulLength,
5883*c2c66affSColin Finck                                                 ulFlags, NULL);
5884*c2c66affSColin Finck }
5885*c2c66affSColin Finck 
5886*c2c66affSColin Finck 
5887*c2c66affSColin Finck /***********************************************************************
5888*c2c66affSColin Finck  * CM_Set_DevNode_Registry_Property_ExA [SETUPAPI.@]
5889*c2c66affSColin Finck  */
5890*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_DevNode_Registry_Property_ExA(
5891*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulProperty, PCVOID Buffer, ULONG ulLength,
5892*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
5893*c2c66affSColin Finck {
5894*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
5895*c2c66affSColin Finck     LPWSTR lpBuffer;
5896*c2c66affSColin Finck     ULONG ulType;
5897*c2c66affSColin Finck 
5898*c2c66affSColin Finck     FIXME("%lx %lu %p %lx %lx %lx\n",
5899*c2c66affSColin Finck           dnDevInst, ulProperty, Buffer, ulLength, ulFlags, hMachine);
5900*c2c66affSColin Finck 
5901*c2c66affSColin Finck     if (Buffer == NULL && ulLength != 0)
5902*c2c66affSColin Finck         return CR_INVALID_POINTER;
5903*c2c66affSColin Finck 
5904*c2c66affSColin Finck     if (ulProperty < CM_DRP_MIN || ulProperty > CM_DRP_MAX)
5905*c2c66affSColin Finck         return CR_INVALID_PROPERTY;
5906*c2c66affSColin Finck 
5907*c2c66affSColin Finck     if (Buffer == NULL)
5908*c2c66affSColin Finck     {
5909*c2c66affSColin Finck         ret = CM_Set_DevNode_Registry_Property_ExW(dnDevInst,
5910*c2c66affSColin Finck                                                    ulProperty,
5911*c2c66affSColin Finck                                                    NULL,
5912*c2c66affSColin Finck                                                    0,
5913*c2c66affSColin Finck                                                    ulFlags,
5914*c2c66affSColin Finck                                                    hMachine);
5915*c2c66affSColin Finck     }
5916*c2c66affSColin Finck     else
5917*c2c66affSColin Finck     {
5918*c2c66affSColin Finck         /* Get property type */
5919*c2c66affSColin Finck         ulType = GetRegistryPropertyType(ulProperty);
5920*c2c66affSColin Finck 
5921*c2c66affSColin Finck         /* Allocate buffer if needed */
5922*c2c66affSColin Finck         if (ulType == REG_SZ ||
5923*c2c66affSColin Finck             ulType == REG_MULTI_SZ)
5924*c2c66affSColin Finck         {
5925*c2c66affSColin Finck             lpBuffer = MyMalloc(ulLength * sizeof(WCHAR));
5926*c2c66affSColin Finck             if (lpBuffer == NULL)
5927*c2c66affSColin Finck             {
5928*c2c66affSColin Finck                 ret = CR_OUT_OF_MEMORY;
5929*c2c66affSColin Finck             }
5930*c2c66affSColin Finck             else
5931*c2c66affSColin Finck             {
5932*c2c66affSColin Finck                 if (!MultiByteToWideChar(CP_ACP, 0, Buffer,
5933*c2c66affSColin Finck                                          ulLength, lpBuffer, ulLength))
5934*c2c66affSColin Finck                 {
5935*c2c66affSColin Finck                     MyFree(lpBuffer);
5936*c2c66affSColin Finck                     ret = CR_FAILURE;
5937*c2c66affSColin Finck                 }
5938*c2c66affSColin Finck                 else
5939*c2c66affSColin Finck                 {
5940*c2c66affSColin Finck                     ret = CM_Set_DevNode_Registry_Property_ExW(dnDevInst,
5941*c2c66affSColin Finck                                                                ulProperty,
5942*c2c66affSColin Finck                                                                lpBuffer,
5943*c2c66affSColin Finck                                                                ulLength * sizeof(WCHAR),
5944*c2c66affSColin Finck                                                                ulFlags,
5945*c2c66affSColin Finck                                                                hMachine);
5946*c2c66affSColin Finck                     MyFree(lpBuffer);
5947*c2c66affSColin Finck                 }
5948*c2c66affSColin Finck             }
5949*c2c66affSColin Finck         }
5950*c2c66affSColin Finck         else
5951*c2c66affSColin Finck         {
5952*c2c66affSColin Finck             ret = CM_Set_DevNode_Registry_Property_ExW(dnDevInst,
5953*c2c66affSColin Finck                                                        ulProperty,
5954*c2c66affSColin Finck                                                        Buffer,
5955*c2c66affSColin Finck                                                        ulLength,
5956*c2c66affSColin Finck                                                        ulFlags,
5957*c2c66affSColin Finck                                                        hMachine);
5958*c2c66affSColin Finck         }
5959*c2c66affSColin Finck 
5960*c2c66affSColin Finck         ret = CR_CALL_NOT_IMPLEMENTED;
5961*c2c66affSColin Finck     }
5962*c2c66affSColin Finck 
5963*c2c66affSColin Finck     return ret;
5964*c2c66affSColin Finck }
5965*c2c66affSColin Finck 
5966*c2c66affSColin Finck 
5967*c2c66affSColin Finck /***********************************************************************
5968*c2c66affSColin Finck  * CM_Set_DevNode_Registry_Property_ExW [SETUPAPI.@]
5969*c2c66affSColin Finck  */
5970*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_DevNode_Registry_Property_ExW(
5971*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulProperty, PCVOID Buffer, ULONG ulLength,
5972*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
5973*c2c66affSColin Finck {
5974*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5975*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
5976*c2c66affSColin Finck     LPWSTR lpDevInst;
5977*c2c66affSColin Finck     ULONG ulType;
5978*c2c66affSColin Finck     CONFIGRET ret;
5979*c2c66affSColin Finck 
5980*c2c66affSColin Finck     TRACE("%lx %lu %p %lx %lx %lx\n",
5981*c2c66affSColin Finck           dnDevInst, ulProperty, Buffer, ulLength, ulFlags, hMachine);
5982*c2c66affSColin Finck 
5983*c2c66affSColin Finck     if (dnDevInst == 0)
5984*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5985*c2c66affSColin Finck 
5986*c2c66affSColin Finck     if (ulProperty <  CM_DRP_MIN || ulProperty > CM_DRP_MAX)
5987*c2c66affSColin Finck         return CR_INVALID_PROPERTY;
5988*c2c66affSColin Finck 
5989*c2c66affSColin Finck     if (Buffer != NULL && ulLength == 0)
5990*c2c66affSColin Finck         return CR_INVALID_POINTER;
5991*c2c66affSColin Finck 
5992*c2c66affSColin Finck     if (ulFlags != 0)
5993*c2c66affSColin Finck         return CR_INVALID_FLAG;
5994*c2c66affSColin Finck 
5995*c2c66affSColin Finck     if (hMachine != NULL)
5996*c2c66affSColin Finck     {
5997*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5998*c2c66affSColin Finck         if (BindingHandle == NULL)
5999*c2c66affSColin Finck             return CR_FAILURE;
6000*c2c66affSColin Finck 
6001*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
6002*c2c66affSColin Finck         if (StringTable == 0)
6003*c2c66affSColin Finck             return CR_FAILURE;
6004*c2c66affSColin Finck     }
6005*c2c66affSColin Finck     else
6006*c2c66affSColin Finck     {
6007*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
6008*c2c66affSColin Finck             return CR_FAILURE;
6009*c2c66affSColin Finck     }
6010*c2c66affSColin Finck 
6011*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
6012*c2c66affSColin Finck     if (lpDevInst == NULL)
6013*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
6014*c2c66affSColin Finck 
6015*c2c66affSColin Finck     /* Get property type */
6016*c2c66affSColin Finck     ulType = GetRegistryPropertyType(ulProperty);
6017*c2c66affSColin Finck 
6018*c2c66affSColin Finck     RpcTryExcept
6019*c2c66affSColin Finck     {
6020*c2c66affSColin Finck         ret = PNP_SetDeviceRegProp(BindingHandle,
6021*c2c66affSColin Finck                                    lpDevInst,
6022*c2c66affSColin Finck                                    ulProperty,
6023*c2c66affSColin Finck                                    ulType,
6024*c2c66affSColin Finck                                    (BYTE *)Buffer,
6025*c2c66affSColin Finck                                    ulLength,
6026*c2c66affSColin Finck                                    ulFlags);
6027*c2c66affSColin Finck     }
6028*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
6029*c2c66affSColin Finck     {
6030*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
6031*c2c66affSColin Finck     }
6032*c2c66affSColin Finck     RpcEndExcept;
6033*c2c66affSColin Finck 
6034*c2c66affSColin Finck     return ret;
6035*c2c66affSColin Finck }
6036*c2c66affSColin Finck 
6037*c2c66affSColin Finck 
6038*c2c66affSColin Finck /***********************************************************************
6039*c2c66affSColin Finck  * CM_Set_HW_Prof [SETUPAPI.@]
6040*c2c66affSColin Finck  */
6041*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_HW_Prof(
6042*c2c66affSColin Finck     ULONG ulHardwareProfile, ULONG ulFlags)
6043*c2c66affSColin Finck {
6044*c2c66affSColin Finck     TRACE("%lu %lu\n", ulHardwareProfile, ulFlags);
6045*c2c66affSColin Finck     return CM_Set_HW_Prof_Ex(ulHardwareProfile, ulFlags, NULL);
6046*c2c66affSColin Finck }
6047*c2c66affSColin Finck 
6048*c2c66affSColin Finck 
6049*c2c66affSColin Finck /***********************************************************************
6050*c2c66affSColin Finck  * CM_Set_HW_Prof_Ex [SETUPAPI.@]
6051*c2c66affSColin Finck  */
6052*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_HW_Prof_Ex(
6053*c2c66affSColin Finck     ULONG ulHardwareProfile, ULONG ulFlags, HMACHINE hMachine)
6054*c2c66affSColin Finck {
6055*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
6056*c2c66affSColin Finck     CONFIGRET ret;
6057*c2c66affSColin Finck 
6058*c2c66affSColin Finck     TRACE("%lu %lu %lx\n", ulHardwareProfile, ulFlags, hMachine);
6059*c2c66affSColin Finck 
6060*c2c66affSColin Finck     if (!pSetupIsUserAdmin())
6061*c2c66affSColin Finck         return CR_ACCESS_DENIED;
6062*c2c66affSColin Finck 
6063*c2c66affSColin Finck     if (ulFlags != 0)
6064*c2c66affSColin Finck         return CR_INVALID_FLAG;
6065*c2c66affSColin Finck 
6066*c2c66affSColin Finck     if (hMachine != NULL)
6067*c2c66affSColin Finck     {
6068*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
6069*c2c66affSColin Finck         if (BindingHandle == NULL)
6070*c2c66affSColin Finck             return CR_FAILURE;
6071*c2c66affSColin Finck     }
6072*c2c66affSColin Finck     else
6073*c2c66affSColin Finck     {
6074*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
6075*c2c66affSColin Finck             return CR_FAILURE;
6076*c2c66affSColin Finck     }
6077*c2c66affSColin Finck 
6078*c2c66affSColin Finck     RpcTryExcept
6079*c2c66affSColin Finck     {
6080*c2c66affSColin Finck         ret = PNP_SetHwProf(BindingHandle, ulHardwareProfile, ulFlags);
6081*c2c66affSColin Finck     }
6082*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
6083*c2c66affSColin Finck     {
6084*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
6085*c2c66affSColin Finck     }
6086*c2c66affSColin Finck     RpcEndExcept;
6087*c2c66affSColin Finck 
6088*c2c66affSColin Finck     return ret;
6089*c2c66affSColin Finck }
6090*c2c66affSColin Finck 
6091*c2c66affSColin Finck 
6092*c2c66affSColin Finck /***********************************************************************
6093*c2c66affSColin Finck  * CM_Set_HW_Prof_FlagsA [SETUPAPI.@]
6094*c2c66affSColin Finck  */
6095*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_HW_Prof_FlagsA(
6096*c2c66affSColin Finck     DEVINSTID_A szDevInstName, ULONG ulConfig, ULONG ulValue,
6097*c2c66affSColin Finck     ULONG ulFlags)
6098*c2c66affSColin Finck {
6099*c2c66affSColin Finck     TRACE("%s %lu %lu %lx\n", szDevInstName,
6100*c2c66affSColin Finck           ulConfig, ulValue, ulFlags);
6101*c2c66affSColin Finck     return CM_Set_HW_Prof_Flags_ExA(szDevInstName, ulConfig, ulValue,
6102*c2c66affSColin Finck                                     ulFlags, NULL);
6103*c2c66affSColin Finck }
6104*c2c66affSColin Finck 
6105*c2c66affSColin Finck 
6106*c2c66affSColin Finck /***********************************************************************
6107*c2c66affSColin Finck  * CM_Set_HW_Prof_FlagsW [SETUPAPI.@]
6108*c2c66affSColin Finck  */
6109*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_HW_Prof_FlagsW(
6110*c2c66affSColin Finck     DEVINSTID_W szDevInstName, ULONG ulConfig, ULONG ulValue,
6111*c2c66affSColin Finck     ULONG ulFlags)
6112*c2c66affSColin Finck {
6113*c2c66affSColin Finck     TRACE("%s %lu %lu %lx\n", debugstr_w(szDevInstName),
6114*c2c66affSColin Finck           ulConfig, ulValue, ulFlags);
6115*c2c66affSColin Finck     return CM_Set_HW_Prof_Flags_ExW(szDevInstName, ulConfig, ulValue,
6116*c2c66affSColin Finck                                     ulFlags, NULL);
6117*c2c66affSColin Finck }
6118*c2c66affSColin Finck 
6119*c2c66affSColin Finck 
6120*c2c66affSColin Finck /***********************************************************************
6121*c2c66affSColin Finck  * CM_Set_HW_Prof_Flags_ExA [SETUPAPI.@]
6122*c2c66affSColin Finck  */
6123*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_HW_Prof_Flags_ExA(
6124*c2c66affSColin Finck     DEVINSTID_A szDevInstName, ULONG ulConfig, ULONG ulValue,
6125*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
6126*c2c66affSColin Finck {
6127*c2c66affSColin Finck     DEVINSTID_W pszDevIdW = NULL;
6128*c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
6129*c2c66affSColin Finck 
6130*c2c66affSColin Finck     TRACE("%s %lu %lu %lx %lx\n", szDevInstName,
6131*c2c66affSColin Finck           ulConfig, ulValue, ulFlags, hMachine);
6132*c2c66affSColin Finck 
6133*c2c66affSColin Finck     if (szDevInstName != NULL)
6134*c2c66affSColin Finck     {
6135*c2c66affSColin Finck        if (pSetupCaptureAndConvertAnsiArg(szDevInstName, &pszDevIdW))
6136*c2c66affSColin Finck          return CR_INVALID_DEVICE_ID;
6137*c2c66affSColin Finck     }
6138*c2c66affSColin Finck 
6139*c2c66affSColin Finck     ret = CM_Set_HW_Prof_Flags_ExW(pszDevIdW, ulConfig, ulValue,
6140*c2c66affSColin Finck                                    ulFlags, hMachine);
6141*c2c66affSColin Finck 
6142*c2c66affSColin Finck     if (pszDevIdW != NULL)
6143*c2c66affSColin Finck         MyFree(pszDevIdW);
6144*c2c66affSColin Finck 
6145*c2c66affSColin Finck     return ret;
6146*c2c66affSColin Finck }
6147*c2c66affSColin Finck 
6148*c2c66affSColin Finck 
6149*c2c66affSColin Finck /***********************************************************************
6150*c2c66affSColin Finck  * CM_Set_HW_Prof_Flags_ExW [SETUPAPI.@]
6151*c2c66affSColin Finck  */
6152*c2c66affSColin Finck CONFIGRET WINAPI CM_Set_HW_Prof_Flags_ExW(
6153*c2c66affSColin Finck     DEVINSTID_W szDevInstName, ULONG ulConfig, ULONG ulValue,
6154*c2c66affSColin Finck     ULONG ulFlags, HMACHINE hMachine)
6155*c2c66affSColin Finck {
6156*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
6157*c2c66affSColin Finck     CONFIGRET ret;
6158*c2c66affSColin Finck 
6159*c2c66affSColin Finck     FIXME("%s %lu %lu %lx %lx\n", debugstr_w(szDevInstName),
6160*c2c66affSColin Finck           ulConfig, ulValue, ulFlags, hMachine);
6161*c2c66affSColin Finck 
6162*c2c66affSColin Finck     if (szDevInstName == NULL)
6163*c2c66affSColin Finck         return CR_INVALID_POINTER;
6164*c2c66affSColin Finck 
6165*c2c66affSColin Finck     if (ulFlags & ~ CM_SET_HW_PROF_FLAGS_BITS)
6166*c2c66affSColin Finck         return CR_INVALID_FLAG;
6167*c2c66affSColin Finck 
6168*c2c66affSColin Finck     /* FIXME: Check whether szDevInstName is valid */
6169*c2c66affSColin Finck 
6170*c2c66affSColin Finck     if (hMachine != NULL)
6171*c2c66affSColin Finck     {
6172*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
6173*c2c66affSColin Finck         if (BindingHandle == NULL)
6174*c2c66affSColin Finck             return CR_FAILURE;
6175*c2c66affSColin Finck     }
6176*c2c66affSColin Finck     else
6177*c2c66affSColin Finck     {
6178*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
6179*c2c66affSColin Finck             return CR_FAILURE;
6180*c2c66affSColin Finck     }
6181*c2c66affSColin Finck 
6182*c2c66affSColin Finck     RpcTryExcept
6183*c2c66affSColin Finck     {
6184*c2c66affSColin Finck         ret = PNP_HwProfFlags(BindingHandle, PNP_SET_HWPROFFLAGS, szDevInstName,
6185*c2c66affSColin Finck                               ulConfig, &ulValue, NULL, NULL, 0, 0);
6186*c2c66affSColin Finck     }
6187*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
6188*c2c66affSColin Finck     {
6189*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
6190*c2c66affSColin Finck     }
6191*c2c66affSColin Finck     RpcEndExcept;
6192*c2c66affSColin Finck 
6193*c2c66affSColin Finck     return ret;
6194*c2c66affSColin Finck }
6195*c2c66affSColin Finck 
6196*c2c66affSColin Finck 
6197*c2c66affSColin Finck /***********************************************************************
6198*c2c66affSColin Finck  * CM_Setup_DevNode [SETUPAPI.@]
6199*c2c66affSColin Finck  */
6200*c2c66affSColin Finck CONFIGRET WINAPI CM_Setup_DevNode(
6201*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulFlags)
6202*c2c66affSColin Finck {
6203*c2c66affSColin Finck     TRACE("%lx %lx\n", dnDevInst, ulFlags);
6204*c2c66affSColin Finck     return CM_Setup_DevNode_Ex(dnDevInst, ulFlags, NULL);
6205*c2c66affSColin Finck }
6206*c2c66affSColin Finck 
6207*c2c66affSColin Finck 
6208*c2c66affSColin Finck /***********************************************************************
6209*c2c66affSColin Finck  * CM_Setup_DevNode_Ex [SETUPAPI.@]
6210*c2c66affSColin Finck  */
6211*c2c66affSColin Finck CONFIGRET WINAPI CM_Setup_DevNode_Ex(
6212*c2c66affSColin Finck     DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
6213*c2c66affSColin Finck {
6214*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
6215*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
6216*c2c66affSColin Finck     LPWSTR lpDevInst;
6217*c2c66affSColin Finck     CONFIGRET ret;
6218*c2c66affSColin Finck 
6219*c2c66affSColin Finck     FIXME("%lx %lx %lx\n", dnDevInst, ulFlags, hMachine);
6220*c2c66affSColin Finck 
6221*c2c66affSColin Finck     if (!pSetupIsUserAdmin())
6222*c2c66affSColin Finck         return CR_ACCESS_DENIED;
6223*c2c66affSColin Finck 
6224*c2c66affSColin Finck     if (dnDevInst == 0)
6225*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
6226*c2c66affSColin Finck 
6227*c2c66affSColin Finck     if (ulFlags & ~CM_SETUP_BITS)
6228*c2c66affSColin Finck         return CR_INVALID_FLAG;
6229*c2c66affSColin Finck 
6230*c2c66affSColin Finck     if (hMachine != NULL)
6231*c2c66affSColin Finck     {
6232*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
6233*c2c66affSColin Finck         if (BindingHandle == NULL)
6234*c2c66affSColin Finck             return CR_FAILURE;
6235*c2c66affSColin Finck 
6236*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
6237*c2c66affSColin Finck         if (StringTable == 0)
6238*c2c66affSColin Finck             return CR_FAILURE;
6239*c2c66affSColin Finck     }
6240*c2c66affSColin Finck     else
6241*c2c66affSColin Finck     {
6242*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
6243*c2c66affSColin Finck             return CR_FAILURE;
6244*c2c66affSColin Finck     }
6245*c2c66affSColin Finck 
6246*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
6247*c2c66affSColin Finck     if (lpDevInst == NULL)
6248*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
6249*c2c66affSColin Finck 
6250*c2c66affSColin Finck     RpcTryExcept
6251*c2c66affSColin Finck     {
6252*c2c66affSColin Finck         ret = PNP_DeviceInstanceAction(BindingHandle,
6253*c2c66affSColin Finck                                        PNP_DEVINST_SETUP,
6254*c2c66affSColin Finck                                        ulFlags,
6255*c2c66affSColin Finck                                        lpDevInst,
6256*c2c66affSColin Finck                                        NULL);
6257*c2c66affSColin Finck     }
6258*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
6259*c2c66affSColin Finck     {
6260*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
6261*c2c66affSColin Finck     }
6262*c2c66affSColin Finck     RpcEndExcept;
6263*c2c66affSColin Finck 
6264*c2c66affSColin Finck     return ret;
6265*c2c66affSColin Finck }
6266*c2c66affSColin Finck 
6267*c2c66affSColin Finck 
6268*c2c66affSColin Finck /***********************************************************************
6269*c2c66affSColin Finck  * CM_Test_Range_Available [SETUPAPI.@]
6270*c2c66affSColin Finck  */
6271*c2c66affSColin Finck CONFIGRET
6272*c2c66affSColin Finck WINAPI
6273*c2c66affSColin Finck CM_Test_Range_Available(
6274*c2c66affSColin Finck     _In_ DWORDLONG ullStartValue,
6275*c2c66affSColin Finck     _In_ DWORDLONG ullEndValue,
6276*c2c66affSColin Finck     _In_ RANGE_LIST rlh,
6277*c2c66affSColin Finck     _In_ ULONG ulFlags)
6278*c2c66affSColin Finck {
6279*c2c66affSColin Finck     FIXME("CM_Test_Range_Available(%I64u %I64u %p %lx)\n",
6280*c2c66affSColin Finck           ullStartValue, ullEndValue, rlh, ulFlags);
6281*c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
6282*c2c66affSColin Finck }
6283*c2c66affSColin Finck 
6284*c2c66affSColin Finck 
6285*c2c66affSColin Finck /***********************************************************************
6286*c2c66affSColin Finck  * CM_Uninstall_DevNode [SETUPAPI.@]
6287*c2c66affSColin Finck  */
6288*c2c66affSColin Finck CONFIGRET WINAPI CM_Uninstall_DevNode(
6289*c2c66affSColin Finck     DEVINST dnPhantom, ULONG ulFlags)
6290*c2c66affSColin Finck {
6291*c2c66affSColin Finck     TRACE("%lx %lx\n", dnPhantom, ulFlags);
6292*c2c66affSColin Finck     return CM_Uninstall_DevNode_Ex(dnPhantom, ulFlags, NULL);
6293*c2c66affSColin Finck }
6294*c2c66affSColin Finck 
6295*c2c66affSColin Finck 
6296*c2c66affSColin Finck /***********************************************************************
6297*c2c66affSColin Finck  * CM_Uninstall_DevNode_Ex [SETUPAPI.@]
6298*c2c66affSColin Finck  */
6299*c2c66affSColin Finck CONFIGRET WINAPI CM_Uninstall_DevNode_Ex(
6300*c2c66affSColin Finck     DEVINST dnPhantom, ULONG ulFlags, HMACHINE hMachine)
6301*c2c66affSColin Finck {
6302*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
6303*c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
6304*c2c66affSColin Finck     LPWSTR lpDevInst;
6305*c2c66affSColin Finck     CONFIGRET ret;
6306*c2c66affSColin Finck 
6307*c2c66affSColin Finck     TRACE("%lx %lx %lx\n", dnPhantom, ulFlags, hMachine);
6308*c2c66affSColin Finck 
6309*c2c66affSColin Finck     if (dnPhantom == 0)
6310*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
6311*c2c66affSColin Finck 
6312*c2c66affSColin Finck     if (ulFlags != 0)
6313*c2c66affSColin Finck         return CR_INVALID_FLAG;
6314*c2c66affSColin Finck 
6315*c2c66affSColin Finck     if (hMachine != NULL)
6316*c2c66affSColin Finck     {
6317*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
6318*c2c66affSColin Finck         if (BindingHandle == NULL)
6319*c2c66affSColin Finck             return CR_FAILURE;
6320*c2c66affSColin Finck 
6321*c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
6322*c2c66affSColin Finck         if (StringTable == 0)
6323*c2c66affSColin Finck             return CR_FAILURE;
6324*c2c66affSColin Finck     }
6325*c2c66affSColin Finck     else
6326*c2c66affSColin Finck     {
6327*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
6328*c2c66affSColin Finck             return CR_FAILURE;
6329*c2c66affSColin Finck     }
6330*c2c66affSColin Finck 
6331*c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnPhantom);
6332*c2c66affSColin Finck     if (lpDevInst == NULL)
6333*c2c66affSColin Finck         return CR_INVALID_DEVNODE;
6334*c2c66affSColin Finck 
6335*c2c66affSColin Finck     RpcTryExcept
6336*c2c66affSColin Finck     {
6337*c2c66affSColin Finck         ret = PNP_UninstallDevInst(BindingHandle,
6338*c2c66affSColin Finck                                    lpDevInst,
6339*c2c66affSColin Finck                                    ulFlags);
6340*c2c66affSColin Finck     }
6341*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
6342*c2c66affSColin Finck     {
6343*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
6344*c2c66affSColin Finck     }
6345*c2c66affSColin Finck     RpcEndExcept;
6346*c2c66affSColin Finck 
6347*c2c66affSColin Finck     return ret;
6348*c2c66affSColin Finck }
6349*c2c66affSColin Finck 
6350*c2c66affSColin Finck 
6351*c2c66affSColin Finck /***********************************************************************
6352*c2c66affSColin Finck  * CM_Unregister_Device_InterfaceA [SETUPAPI.@]
6353*c2c66affSColin Finck  */
6354*c2c66affSColin Finck CONFIGRET WINAPI CM_Unregister_Device_InterfaceA(
6355*c2c66affSColin Finck     LPCSTR pszDeviceInterface, ULONG ulFlags)
6356*c2c66affSColin Finck {
6357*c2c66affSColin Finck     TRACE("%s %lx\n", pszDeviceInterface, ulFlags);
6358*c2c66affSColin Finck 
6359*c2c66affSColin Finck     return CM_Unregister_Device_Interface_ExA(pszDeviceInterface,
6360*c2c66affSColin Finck                                               ulFlags, NULL);
6361*c2c66affSColin Finck }
6362*c2c66affSColin Finck 
6363*c2c66affSColin Finck 
6364*c2c66affSColin Finck /***********************************************************************
6365*c2c66affSColin Finck  * CM_Unregister_Device_InterfaceW [SETUPAPI.@]
6366*c2c66affSColin Finck  */
6367*c2c66affSColin Finck CONFIGRET WINAPI CM_Unregister_Device_InterfaceW(
6368*c2c66affSColin Finck     LPCWSTR pszDeviceInterface, ULONG ulFlags)
6369*c2c66affSColin Finck {
6370*c2c66affSColin Finck     TRACE("%s %lx\n", debugstr_w(pszDeviceInterface), ulFlags);
6371*c2c66affSColin Finck 
6372*c2c66affSColin Finck     return CM_Unregister_Device_Interface_ExW(pszDeviceInterface,
6373*c2c66affSColin Finck                                               ulFlags, NULL);
6374*c2c66affSColin Finck }
6375*c2c66affSColin Finck 
6376*c2c66affSColin Finck 
6377*c2c66affSColin Finck /***********************************************************************
6378*c2c66affSColin Finck  * CM_Unregister_Device_Interface_ExA [SETUPAPI.@]
6379*c2c66affSColin Finck  */
6380*c2c66affSColin Finck CONFIGRET WINAPI CM_Unregister_Device_Interface_ExA(
6381*c2c66affSColin Finck     LPCSTR pszDeviceInterface, ULONG ulFlags, HMACHINE hMachine)
6382*c2c66affSColin Finck {
6383*c2c66affSColin Finck     LPWSTR pszDeviceInterfaceW = NULL;
6384*c2c66affSColin Finck     CONFIGRET ret;
6385*c2c66affSColin Finck 
6386*c2c66affSColin Finck     TRACE("%s %lx %lx\n", pszDeviceInterface, ulFlags, hMachine);
6387*c2c66affSColin Finck 
6388*c2c66affSColin Finck     if (pszDeviceInterface == NULL)
6389*c2c66affSColin Finck         return CR_INVALID_POINTER;
6390*c2c66affSColin Finck 
6391*c2c66affSColin Finck     if (pSetupCaptureAndConvertAnsiArg(pszDeviceInterface, &pszDeviceInterfaceW))
6392*c2c66affSColin Finck         return CR_INVALID_DATA;
6393*c2c66affSColin Finck 
6394*c2c66affSColin Finck     ret = CM_Unregister_Device_Interface_ExW(pszDeviceInterfaceW,
6395*c2c66affSColin Finck                                              ulFlags, hMachine);
6396*c2c66affSColin Finck 
6397*c2c66affSColin Finck     if (pszDeviceInterfaceW != NULL)
6398*c2c66affSColin Finck         MyFree(pszDeviceInterfaceW);
6399*c2c66affSColin Finck 
6400*c2c66affSColin Finck     return ret;
6401*c2c66affSColin Finck }
6402*c2c66affSColin Finck 
6403*c2c66affSColin Finck 
6404*c2c66affSColin Finck /***********************************************************************
6405*c2c66affSColin Finck  * CM_Unregister_Device_Interface_ExW [SETUPAPI.@]
6406*c2c66affSColin Finck  */
6407*c2c66affSColin Finck CONFIGRET WINAPI CM_Unregister_Device_Interface_ExW(
6408*c2c66affSColin Finck     LPCWSTR pszDeviceInterface, ULONG ulFlags, HMACHINE hMachine)
6409*c2c66affSColin Finck {
6410*c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
6411*c2c66affSColin Finck     CONFIGRET ret;
6412*c2c66affSColin Finck 
6413*c2c66affSColin Finck     TRACE("%s %lx %lx\n", debugstr_w(pszDeviceInterface), ulFlags, hMachine);
6414*c2c66affSColin Finck 
6415*c2c66affSColin Finck     if (pszDeviceInterface == NULL)
6416*c2c66affSColin Finck         return CR_INVALID_POINTER;
6417*c2c66affSColin Finck 
6418*c2c66affSColin Finck     if (ulFlags != 0)
6419*c2c66affSColin Finck         return CR_INVALID_FLAG;
6420*c2c66affSColin Finck 
6421*c2c66affSColin Finck     if (hMachine != NULL)
6422*c2c66affSColin Finck     {
6423*c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
6424*c2c66affSColin Finck         if (BindingHandle == NULL)
6425*c2c66affSColin Finck             return CR_FAILURE;
6426*c2c66affSColin Finck     }
6427*c2c66affSColin Finck     else
6428*c2c66affSColin Finck     {
6429*c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
6430*c2c66affSColin Finck             return CR_FAILURE;
6431*c2c66affSColin Finck     }
6432*c2c66affSColin Finck 
6433*c2c66affSColin Finck     RpcTryExcept
6434*c2c66affSColin Finck     {
6435*c2c66affSColin Finck         ret = PNP_UnregisterDeviceClassAssociation(BindingHandle,
6436*c2c66affSColin Finck                                                    (LPWSTR)pszDeviceInterface,
6437*c2c66affSColin Finck                                                    ulFlags);
6438*c2c66affSColin Finck     }
6439*c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
6440*c2c66affSColin Finck     {
6441*c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
6442*c2c66affSColin Finck     }
6443*c2c66affSColin Finck     RpcEndExcept;
6444*c2c66affSColin Finck 
6445*c2c66affSColin Finck     return ret;
6446*c2c66affSColin Finck }
6447