xref: /reactos/dll/win32/setupapi/cfgmgr.c (revision b667d82f)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * Configuration manager functions
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * Copyright 2000 James Hatheway
5c2c66affSColin Finck  * Copyright 2005, 2006 Eric Kohl
6c2c66affSColin Finck  *
7c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
8c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
9c2c66affSColin Finck  * License as published by the Free Software Foundation; either
10c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
11c2c66affSColin Finck  *
12c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
13c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15c2c66affSColin Finck  * Lesser General Public License for more details.
16c2c66affSColin Finck  *
17c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
18c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
19c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20c2c66affSColin Finck  */
21c2c66affSColin Finck 
22c2c66affSColin Finck #include "setupapi_private.h"
23c2c66affSColin Finck 
24c2c66affSColin Finck #include <dbt.h>
25c2c66affSColin Finck #include <pnp_c.h>
26ece54dcdSEric Kohl #include <winsvc.h>
27c2c66affSColin Finck 
28e470b583SJérôme Gardou #include <pseh/pseh2.h>
29e470b583SJérôme Gardou 
30c2c66affSColin Finck #include "rpc_private.h"
31c2c66affSColin Finck 
32ece54dcdSEric Kohl DWORD
33ece54dcdSEric Kohl WINAPI
34ece54dcdSEric Kohl I_ScPnPGetServiceName(IN SERVICE_STATUS_HANDLE hServiceStatus,
35ece54dcdSEric Kohl                       OUT LPWSTR lpServiceName,
36ece54dcdSEric Kohl                       IN DWORD cchServiceName);
37ece54dcdSEric Kohl 
38ece54dcdSEric Kohl 
39c2c66affSColin Finck /* Registry key and value names */
408da00cd9SHervé Poussineau static const WCHAR BackslashOpenBrace[] = {'\\', '{', 0};
418da00cd9SHervé Poussineau static const WCHAR CloseBrace[] = {'}', 0};
42c2c66affSColin Finck static const WCHAR Class[]  = {'C','l','a','s','s',0};
43c2c66affSColin Finck 
44c2c66affSColin Finck static const WCHAR ControlClass[] = {'S','y','s','t','e','m','\\',
45c2c66affSColin Finck                                      'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
46c2c66affSColin Finck                                      'C','o','n','t','r','o','l','\\',
47c2c66affSColin Finck                                      'C','l','a','s','s',0};
48c2c66affSColin Finck 
49c2c66affSColin Finck static const WCHAR DeviceClasses[] = {'S','y','s','t','e','m','\\',
50c2c66affSColin Finck                                       'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
51c2c66affSColin Finck                                       'C','o','n','t','r','o','l','\\',
52c2c66affSColin Finck                                       'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
53c2c66affSColin Finck 
54c2c66affSColin Finck typedef struct _MACHINE_INFO
55c2c66affSColin Finck {
56c2c66affSColin Finck     WCHAR szMachineName[SP_MAX_MACHINENAME_LENGTH];
57c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle;
58c2c66affSColin Finck     HSTRING_TABLE StringTable;
59c2c66affSColin Finck     BOOL bLocal;
60c2c66affSColin Finck } MACHINE_INFO, *PMACHINE_INFO;
61c2c66affSColin Finck 
62c2c66affSColin Finck 
63c2c66affSColin Finck typedef struct _LOG_CONF_INFO
64c2c66affSColin Finck {
65c2c66affSColin Finck     ULONG ulMagic;
66c2c66affSColin Finck     DEVINST dnDevInst;
676efb3cbeSEric Kohl     ULONG ulType;
68c2c66affSColin Finck     ULONG ulTag;
69c2c66affSColin Finck } LOG_CONF_INFO, *PLOG_CONF_INFO;
70c2c66affSColin Finck 
71c2c66affSColin Finck #define LOG_CONF_MAGIC 0x464E434C  /* "LCNF" */
72c2c66affSColin Finck 
73894ad4f1SEric Kohl typedef struct _RES_DES_INFO
74894ad4f1SEric Kohl {
75894ad4f1SEric Kohl     ULONG ulMagic;
76894ad4f1SEric Kohl     DEVINST dnDevInst;
77894ad4f1SEric Kohl     ULONG ulLogConfType;
78894ad4f1SEric Kohl     ULONG ulLogConfTag;
79894ad4f1SEric Kohl     ULONG ulResDesType;
80894ad4f1SEric Kohl     ULONG ulResDesTag;
81894ad4f1SEric Kohl } RES_DES_INFO, *PRES_DES_INFO;
82894ad4f1SEric Kohl 
83894ad4f1SEric Kohl #define RES_DES_MAGIC 0x53445352  /* "RSDS" */
84c2c66affSColin Finck 
85c2c66affSColin Finck typedef struct _NOTIFY_DATA
86c2c66affSColin Finck {
87c2c66affSColin Finck     ULONG ulMagic;
88b0a73746SEric Kohl     PVOID hNotifyHandle;
89c2c66affSColin Finck } NOTIFY_DATA, *PNOTIFY_DATA;
90c2c66affSColin Finck 
91c2c66affSColin Finck #define NOTIFY_MAGIC 0x44556677
92c2c66affSColin Finck 
93c2c66affSColin Finck 
943ad5c7fdSEric Kohl typedef struct _INTERNAL_RANGE
95c2c66affSColin Finck {
963ad5c7fdSEric Kohl     LIST_ENTRY ListEntry;
97e88a6b20SEric Kohl     struct _INTERNAL_RANGE_LIST *pRangeList;
983ad5c7fdSEric Kohl     DWORDLONG ullStart;
993ad5c7fdSEric Kohl     DWORDLONG ullEnd;
1003ad5c7fdSEric Kohl } INTERNAL_RANGE, *PINTERNAL_RANGE;
101c2c66affSColin Finck 
102c2c66affSColin Finck typedef struct _INTERNAL_RANGE_LIST
103c2c66affSColin Finck {
104c2c66affSColin Finck     ULONG ulMagic;
1053ad5c7fdSEric Kohl     HANDLE hMutex;
1063ad5c7fdSEric Kohl     LIST_ENTRY ListHead;
107c2c66affSColin Finck } INTERNAL_RANGE_LIST, *PINTERNAL_RANGE_LIST;
108c2c66affSColin Finck 
109c2c66affSColin Finck #define RANGE_LIST_MAGIC 0x33445566
110c2c66affSColin Finck 
111cee1817eSEric Kohl typedef struct _CONFLICT_DATA
112cee1817eSEric Kohl {
113cee1817eSEric Kohl     ULONG ulMagic;
114cee1817eSEric Kohl     PPNP_CONFLICT_LIST pConflictList;
115cee1817eSEric Kohl } CONFLICT_DATA, *PCONFLICT_DATA;
116cee1817eSEric Kohl 
117cee1817eSEric Kohl #define CONFLICT_MAGIC 0x11225588
118cee1817eSEric Kohl 
119cee1817eSEric Kohl 
120cee1817eSEric Kohl /* FUNCTIONS ****************************************************************/
121c2c66affSColin Finck 
122d9a33981SEric Kohl static
123d9a33981SEric Kohl BOOL
124d9a33981SEric Kohl GuidToString(
125d9a33981SEric Kohl     _In_ LPGUID Guid,
126d9a33981SEric Kohl     _Out_ LPWSTR String)
127c2c66affSColin Finck {
128c2c66affSColin Finck     LPWSTR lpString;
129c2c66affSColin Finck 
130c2c66affSColin Finck     if (UuidToStringW(Guid, &lpString) != RPC_S_OK)
131c2c66affSColin Finck         return FALSE;
132c2c66affSColin Finck 
133c2c66affSColin Finck     lstrcpyW(&String[1], lpString);
134c2c66affSColin Finck 
135c2c66affSColin Finck     String[0] = '{';
136c2c66affSColin Finck     String[MAX_GUID_STRING_LEN - 2] = '}';
137c2c66affSColin Finck     String[MAX_GUID_STRING_LEN - 1] = UNICODE_NULL;
138c2c66affSColin Finck 
139c2c66affSColin Finck     RpcStringFreeW(&lpString);
140c2c66affSColin Finck 
141c2c66affSColin Finck     return TRUE;
142c2c66affSColin Finck }
143c2c66affSColin Finck 
144c2c66affSColin Finck 
145d9a33981SEric Kohl static
146d9a33981SEric Kohl CONFIGRET
147d9a33981SEric Kohl RpcStatusToCmStatus(
148d9a33981SEric Kohl     _In_ RPC_STATUS Status)
149c2c66affSColin Finck {
150c2c66affSColin Finck     return CR_FAILURE;
151c2c66affSColin Finck }
152c2c66affSColin Finck 
153c2c66affSColin Finck 
154c2c66affSColin Finck static
155c2c66affSColin Finck ULONG
156c2c66affSColin Finck GetRegistryPropertyType(
157d9a33981SEric Kohl     _In_ ULONG ulProperty)
158c2c66affSColin Finck {
159c2c66affSColin Finck     switch (ulProperty)
160c2c66affSColin Finck     {
161c2c66affSColin Finck         case CM_DRP_DEVICEDESC:
162c2c66affSColin Finck         case CM_DRP_SERVICE:
163c2c66affSColin Finck         case CM_DRP_CLASS:
164c2c66affSColin Finck         case CM_DRP_CLASSGUID:
165c2c66affSColin Finck         case CM_DRP_DRIVER:
166c2c66affSColin Finck         case CM_DRP_MFG:
167c2c66affSColin Finck         case CM_DRP_FRIENDLYNAME:
168c2c66affSColin Finck         case CM_DRP_LOCATION_INFORMATION:
169c2c66affSColin Finck         case CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME:
170c2c66affSColin Finck         case CM_DRP_ENUMERATOR_NAME:
171c2c66affSColin Finck         case CM_DRP_SECURITY_SDS:
172c2c66affSColin Finck         case CM_DRP_UI_NUMBER_DESC_FORMAT:
173c2c66affSColin Finck             return REG_SZ;
174c2c66affSColin Finck 
175c2c66affSColin Finck         case CM_DRP_HARDWAREID:
176c2c66affSColin Finck         case CM_DRP_COMPATIBLEIDS:
177c2c66affSColin Finck         case CM_DRP_UPPERFILTERS:
178c2c66affSColin Finck         case CM_DRP_LOWERFILTERS:
179c2c66affSColin Finck             return REG_MULTI_SZ;
180c2c66affSColin Finck 
181c2c66affSColin Finck         case CM_DRP_CONFIGFLAGS:
182c2c66affSColin Finck         case CM_DRP_CAPABILITIES:
183c2c66affSColin Finck         case CM_DRP_UI_NUMBER:
184c2c66affSColin Finck         case CM_DRP_LEGACYBUSTYPE:
185c2c66affSColin Finck         case CM_DRP_BUSNUMBER:
186c2c66affSColin Finck         case CM_DRP_DEVTYPE:
187c2c66affSColin Finck         case CM_DRP_EXCLUSIVE:
188c2c66affSColin Finck         case CM_DRP_CHARACTERISTICS:
189c2c66affSColin Finck         case CM_DRP_ADDRESS:
190c2c66affSColin Finck         case CM_DRP_REMOVAL_POLICY:
191c2c66affSColin Finck         case CM_DRP_REMOVAL_POLICY_HW_DEFAULT:
192c2c66affSColin Finck         case CM_DRP_REMOVAL_POLICY_OVERRIDE:
193c2c66affSColin Finck         case CM_DRP_INSTALL_STATE:
194c2c66affSColin Finck             return REG_DWORD;
195c2c66affSColin Finck 
196c2c66affSColin Finck         case CM_DRP_BUSTYPEGUID:
197c2c66affSColin Finck         case CM_DRP_SECURITY:
198c2c66affSColin Finck         case CM_DRP_DEVICE_POWER_DATA:
199c2c66affSColin Finck         default:
200c2c66affSColin Finck             return REG_BINARY;
201c2c66affSColin Finck     }
202c2c66affSColin Finck 
203c2c66affSColin Finck     return REG_NONE;
204c2c66affSColin Finck }
205c2c66affSColin Finck 
206c2c66affSColin Finck 
20778cf2a04SEric Kohl static
20878cf2a04SEric Kohl VOID
20978cf2a04SEric Kohl SplitDeviceInstanceId(
21078cf2a04SEric Kohl     _In_ PWSTR pszDeviceInstanceId,
21178cf2a04SEric Kohl     _Out_ PWSTR pszDeviceId,
21278cf2a04SEric Kohl     _Out_ PWSTR pszInstanceId)
21378cf2a04SEric Kohl {
21478cf2a04SEric Kohl     PWCHAR ptr;
21578cf2a04SEric Kohl 
21678cf2a04SEric Kohl     wcscpy(pszDeviceId, pszDeviceInstanceId);
21778cf2a04SEric Kohl 
21878cf2a04SEric Kohl     ptr = wcschr(pszDeviceId, L'\\');
21978cf2a04SEric Kohl     if (ptr != NULL)
22078cf2a04SEric Kohl     {
22178cf2a04SEric Kohl         *ptr = UNICODE_NULL;
22278cf2a04SEric Kohl         ptr++;
22378cf2a04SEric Kohl 
22478cf2a04SEric Kohl         wcscpy(pszInstanceId, ptr);
22578cf2a04SEric Kohl     }
22678cf2a04SEric Kohl     else
22778cf2a04SEric Kohl     {
22878cf2a04SEric Kohl         *pszInstanceId = UNICODE_NULL;
22978cf2a04SEric Kohl     }
23078cf2a04SEric Kohl }
23178cf2a04SEric Kohl 
23278cf2a04SEric Kohl 
23378cf2a04SEric Kohl static
23478cf2a04SEric Kohl CONFIGRET
23578cf2a04SEric Kohl GetDeviceInstanceKeyPath(
23678cf2a04SEric Kohl     _In_ RPC_BINDING_HANDLE BindingHandle,
23778cf2a04SEric Kohl     _In_ PWSTR pszDeviceInst,
23878cf2a04SEric Kohl     _Out_ PWSTR pszKeyPath,
23978cf2a04SEric Kohl     _Out_ PWSTR pszInstancePath,
24078cf2a04SEric Kohl     _In_ ULONG ulHardwareProfile,
24178cf2a04SEric Kohl     _In_ ULONG ulFlags)
24278cf2a04SEric Kohl {
24378cf2a04SEric Kohl     PWSTR pszBuffer = NULL;
24478cf2a04SEric Kohl     ULONG ulType = 0;
24578cf2a04SEric Kohl     ULONG ulTransferLength, ulLength;
24678cf2a04SEric Kohl     CONFIGRET ret = CR_SUCCESS;
24778cf2a04SEric Kohl 
24878cf2a04SEric Kohl     TRACE("GetDeviceInstanceKeyPath()\n");
24978cf2a04SEric Kohl 
250d57b0ef9SEric Kohl     /* Allocate a buffer for the device id */
251d57b0ef9SEric Kohl     pszBuffer = MyMalloc(300 * sizeof(WCHAR));
252d57b0ef9SEric Kohl     if (pszBuffer == NULL)
253d57b0ef9SEric Kohl     {
254d57b0ef9SEric Kohl         ERR("MyMalloc() failed\n");
255d57b0ef9SEric Kohl         return CR_OUT_OF_MEMORY;
256d57b0ef9SEric Kohl     }
257d57b0ef9SEric Kohl 
25878cf2a04SEric Kohl     if (ulFlags & CM_REGISTRY_SOFTWARE)
25978cf2a04SEric Kohl     {
26078cf2a04SEric Kohl         /* Software Key Path */
2618e850d19SEric Kohl 
26278cf2a04SEric Kohl         ulTransferLength = 300 * sizeof(WCHAR);
26378cf2a04SEric Kohl         ulLength = 300 * sizeof(WCHAR);
264adc9bd48SEric Kohl 
265adc9bd48SEric Kohl         RpcTryExcept
266adc9bd48SEric Kohl         {
26778cf2a04SEric Kohl             ret = PNP_GetDeviceRegProp(BindingHandle,
26878cf2a04SEric Kohl                                        pszDeviceInst,
26978cf2a04SEric Kohl                                        CM_DRP_DRIVER,
27078cf2a04SEric Kohl                                        &ulType,
27178cf2a04SEric Kohl                                        (PVOID)pszBuffer,
27278cf2a04SEric Kohl                                        &ulTransferLength,
27378cf2a04SEric Kohl                                        &ulLength,
27478cf2a04SEric Kohl                                        0);
275adc9bd48SEric Kohl         }
276adc9bd48SEric Kohl         RpcExcept(EXCEPTION_EXECUTE_HANDLER)
277adc9bd48SEric Kohl         {
278adc9bd48SEric Kohl             ret = RpcStatusToCmStatus(RpcExceptionCode());
279adc9bd48SEric Kohl         }
280adc9bd48SEric Kohl         RpcEndExcept;
281adc9bd48SEric Kohl 
28278cf2a04SEric Kohl         if (ret != CR_SUCCESS)
28378cf2a04SEric Kohl         {
284adc9bd48SEric Kohl             RpcTryExcept
285adc9bd48SEric Kohl             {
286adc9bd48SEric Kohl                 ret = PNP_GetClassInstance(BindingHandle,
287adc9bd48SEric Kohl                                            pszDeviceInst,
288adc9bd48SEric Kohl                                            (PVOID)pszBuffer,
289adc9bd48SEric Kohl                                            300);
290adc9bd48SEric Kohl             }
291adc9bd48SEric Kohl             RpcExcept(EXCEPTION_EXECUTE_HANDLER)
292adc9bd48SEric Kohl             {
293adc9bd48SEric Kohl                 ret = RpcStatusToCmStatus(RpcExceptionCode());
294adc9bd48SEric Kohl             }
295adc9bd48SEric Kohl             RpcEndExcept;
296adc9bd48SEric Kohl 
297adc9bd48SEric Kohl             if (ret != CR_SUCCESS)
298adc9bd48SEric Kohl             {
29978cf2a04SEric Kohl                 goto done;
30078cf2a04SEric Kohl             }
301adc9bd48SEric Kohl         }
30278cf2a04SEric Kohl 
30378cf2a04SEric Kohl         TRACE("szBuffer: %S\n", pszBuffer);
30478cf2a04SEric Kohl 
30578cf2a04SEric Kohl         SplitDeviceInstanceId(pszBuffer,
30678cf2a04SEric Kohl                               pszBuffer,
30778cf2a04SEric Kohl                               pszInstancePath);
30878cf2a04SEric Kohl 
30978cf2a04SEric Kohl         TRACE("szBuffer: %S\n", pszBuffer);
31078cf2a04SEric Kohl 
31178cf2a04SEric Kohl         if (ulFlags & CM_REGISTRY_CONFIG)
31278cf2a04SEric Kohl         {
31378cf2a04SEric Kohl             if (ulHardwareProfile == 0)
31478cf2a04SEric Kohl             {
31578cf2a04SEric Kohl                 wsprintfW(pszKeyPath,
31678cf2a04SEric Kohl                           L"%s\\%s\\%s\\%s",
31778cf2a04SEric Kohl                           L"System\\CurrentControlSet\\Hardware Profiles",
31878cf2a04SEric Kohl                           L"Current",
31978cf2a04SEric Kohl                           L"System\\CurrentControlSet\\Control\\Class",
32078cf2a04SEric Kohl                           pszBuffer);
32178cf2a04SEric Kohl             }
32278cf2a04SEric Kohl             else
32378cf2a04SEric Kohl             {
32478cf2a04SEric Kohl                 wsprintfW(pszKeyPath,
32578cf2a04SEric Kohl                           L"%s\\%04lu\\%s\\%s",
32678cf2a04SEric Kohl                           L"System\\CurrentControlSet\\Hardware Profiles",
32778cf2a04SEric Kohl                           ulHardwareProfile,
32878cf2a04SEric Kohl                           L"System\\CurrentControlSet\\Control\\Class",
32978cf2a04SEric Kohl                           pszBuffer);
33078cf2a04SEric Kohl             }
33178cf2a04SEric Kohl         }
33278cf2a04SEric Kohl         else
33378cf2a04SEric Kohl         {
33478cf2a04SEric Kohl             wsprintfW(pszKeyPath,
33578cf2a04SEric Kohl                       L"%s\\%s",
33678cf2a04SEric Kohl                       L"System\\CurrentControlSet\\Control\\Class",
33778cf2a04SEric Kohl                       pszBuffer);
33878cf2a04SEric Kohl         }
33978cf2a04SEric Kohl     }
3402037bab6SEric Kohl     else
3412037bab6SEric Kohl     {
3422037bab6SEric Kohl         /* Hardware Key Path */
3432037bab6SEric Kohl 
3442037bab6SEric Kohl         if (ulFlags & CM_REGISTRY_CONFIG)
3452037bab6SEric Kohl         {
3462037bab6SEric Kohl             SplitDeviceInstanceId(pszDeviceInst,
3472037bab6SEric Kohl                                   pszBuffer,
3482037bab6SEric Kohl                                   pszInstancePath);
3492037bab6SEric Kohl 
3502037bab6SEric Kohl             if (ulHardwareProfile == 0)
3512037bab6SEric Kohl             {
3522037bab6SEric Kohl                 wsprintfW(pszKeyPath,
3532037bab6SEric Kohl                           L"%s\\%s\\%s\\%s",
3542037bab6SEric Kohl                           L"System\\CurrentControlSet\\Hardware Profiles",
3552037bab6SEric Kohl                           L"Current",
3562037bab6SEric Kohl                           L"System\\CurrentControlSet\\Enum",
3572037bab6SEric Kohl                           pszBuffer);
3582037bab6SEric Kohl             }
3592037bab6SEric Kohl             else
3602037bab6SEric Kohl             {
3612037bab6SEric Kohl                 wsprintfW(pszKeyPath,
3622037bab6SEric Kohl                           L"%s\\%04lu\\%s\\%s",
3632037bab6SEric Kohl                           L"System\\CurrentControlSet\\Hardware Profiles",
3642037bab6SEric Kohl                           ulHardwareProfile,
3652037bab6SEric Kohl                           L"System\\CurrentControlSet\\Enum",
3662037bab6SEric Kohl                           pszBuffer);
3672037bab6SEric Kohl             }
3682037bab6SEric Kohl         }
3692037bab6SEric Kohl         else if (ulFlags & CM_REGISTRY_USER)
3702037bab6SEric Kohl         {
3712037bab6SEric Kohl             wsprintfW(pszKeyPath,
3722037bab6SEric Kohl                       L"%s\\%s",
3732037bab6SEric Kohl                       L"System\\CurrentControlSet\\Enum",
3742037bab6SEric Kohl                       pszDeviceInst);
3752037bab6SEric Kohl 
3762037bab6SEric Kohl             wcscpy(pszInstancePath,
3772037bab6SEric Kohl                    L"Device Parameters");
3782037bab6SEric Kohl         }
3792037bab6SEric Kohl         else
3802037bab6SEric Kohl         {
3812037bab6SEric Kohl             SplitDeviceInstanceId(pszDeviceInst,
3822037bab6SEric Kohl                                   pszBuffer,
3832037bab6SEric Kohl                                   pszInstancePath);
3842037bab6SEric Kohl 
3852037bab6SEric Kohl             wsprintfW(pszKeyPath,
3862037bab6SEric Kohl                       L"%s\\%s",
3872037bab6SEric Kohl                       L"System\\CurrentControlSet\\Enum",
3882037bab6SEric Kohl                       pszBuffer);
3892037bab6SEric Kohl         }
3902037bab6SEric Kohl     }
39178cf2a04SEric Kohl 
39278cf2a04SEric Kohl done:
39378cf2a04SEric Kohl     if (pszBuffer != NULL)
39478cf2a04SEric Kohl         MyFree(pszBuffer);
39578cf2a04SEric Kohl 
39678cf2a04SEric Kohl     return ret;
39778cf2a04SEric Kohl }
39878cf2a04SEric Kohl 
39978cf2a04SEric Kohl 
4003ad5c7fdSEric Kohl BOOL
4013ad5c7fdSEric Kohl IsValidRangeList(
40219fc20f2SEric Kohl     _In_opt_ PINTERNAL_RANGE_LIST pRangeList)
4033ad5c7fdSEric Kohl {
4043ad5c7fdSEric Kohl     BOOL bValid = TRUE;
4053ad5c7fdSEric Kohl 
4063ad5c7fdSEric Kohl     if (pRangeList == NULL)
4073ad5c7fdSEric Kohl         return FALSE;
4083ad5c7fdSEric Kohl 
4093ad5c7fdSEric Kohl     _SEH2_TRY
4103ad5c7fdSEric Kohl     {
4113ad5c7fdSEric Kohl         if (pRangeList->ulMagic != RANGE_LIST_MAGIC)
4123ad5c7fdSEric Kohl             bValid = FALSE;
4133ad5c7fdSEric Kohl     }
4143ad5c7fdSEric Kohl     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
4153ad5c7fdSEric Kohl     {
4163ad5c7fdSEric Kohl         bValid = FALSE;
4173ad5c7fdSEric Kohl     }
4183ad5c7fdSEric Kohl     _SEH2_END;
4193ad5c7fdSEric Kohl 
4203ad5c7fdSEric Kohl     return bValid;
4213ad5c7fdSEric Kohl }
4223ad5c7fdSEric Kohl 
4233ad5c7fdSEric Kohl 
42419fc20f2SEric Kohl BOOL
42519fc20f2SEric Kohl IsValidLogConf(
42619fc20f2SEric Kohl     _In_opt_ PLOG_CONF_INFO pLogConfInfo)
42719fc20f2SEric Kohl {
42819fc20f2SEric Kohl     BOOL bValid = TRUE;
42919fc20f2SEric Kohl 
43019fc20f2SEric Kohl     if (pLogConfInfo == NULL)
43119fc20f2SEric Kohl         return FALSE;
43219fc20f2SEric Kohl 
43319fc20f2SEric Kohl     _SEH2_TRY
43419fc20f2SEric Kohl     {
43519fc20f2SEric Kohl         if (pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
43619fc20f2SEric Kohl             bValid = FALSE;
43719fc20f2SEric Kohl     }
43819fc20f2SEric Kohl     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
43919fc20f2SEric Kohl     {
44019fc20f2SEric Kohl         bValid = FALSE;
44119fc20f2SEric Kohl     }
44219fc20f2SEric Kohl     _SEH2_END;
44319fc20f2SEric Kohl 
44419fc20f2SEric Kohl     return bValid;
44519fc20f2SEric Kohl }
44619fc20f2SEric Kohl 
44719fc20f2SEric Kohl 
448cee1817eSEric Kohl BOOL
449894ad4f1SEric Kohl IsValidResDes(
450894ad4f1SEric Kohl     _In_opt_ PRES_DES_INFO pResDesInfo)
451894ad4f1SEric Kohl {
452894ad4f1SEric Kohl     BOOL bValid = TRUE;
453894ad4f1SEric Kohl 
454894ad4f1SEric Kohl     if (pResDesInfo == NULL)
455894ad4f1SEric Kohl         return FALSE;
456894ad4f1SEric Kohl 
457894ad4f1SEric Kohl     _SEH2_TRY
458894ad4f1SEric Kohl     {
459894ad4f1SEric Kohl         if (pResDesInfo->ulMagic != RES_DES_MAGIC)
460894ad4f1SEric Kohl             bValid = FALSE;
461894ad4f1SEric Kohl     }
462894ad4f1SEric Kohl     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
463894ad4f1SEric Kohl     {
464894ad4f1SEric Kohl         bValid = FALSE;
465894ad4f1SEric Kohl     }
466894ad4f1SEric Kohl     _SEH2_END;
467894ad4f1SEric Kohl 
468894ad4f1SEric Kohl     return bValid;
469894ad4f1SEric Kohl }
470894ad4f1SEric Kohl 
471894ad4f1SEric Kohl 
472894ad4f1SEric Kohl BOOL
473cee1817eSEric Kohl IsValidConflictData(
474cee1817eSEric Kohl     _In_opt_ PCONFLICT_DATA pConflictData)
475cee1817eSEric Kohl {
476cee1817eSEric Kohl     BOOL bValid = TRUE;
477cee1817eSEric Kohl 
478cee1817eSEric Kohl     if (pConflictData == NULL)
479cee1817eSEric Kohl         return FALSE;
480cee1817eSEric Kohl 
481cee1817eSEric Kohl     _SEH2_TRY
482cee1817eSEric Kohl     {
483cee1817eSEric Kohl         if (pConflictData->ulMagic != CONFLICT_MAGIC)
484cee1817eSEric Kohl             bValid = FALSE;
485cee1817eSEric Kohl     }
486cee1817eSEric Kohl     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
487cee1817eSEric Kohl     {
488cee1817eSEric Kohl         bValid = FALSE;
489cee1817eSEric Kohl     }
490cee1817eSEric Kohl     _SEH2_END;
491cee1817eSEric Kohl 
492cee1817eSEric Kohl     return bValid;
493cee1817eSEric Kohl }
494cee1817eSEric Kohl 
495cee1817eSEric Kohl 
496c2c66affSColin Finck /***********************************************************************
497c2c66affSColin Finck  * CMP_GetBlockedDriverInfo [SETUPAPI.@]
498c2c66affSColin Finck  */
499c2c66affSColin Finck CONFIGRET
500c2c66affSColin Finck WINAPI
501c2c66affSColin Finck CMP_GetBlockedDriverInfo(
502c2c66affSColin Finck     _Out_opt_ LPWSTR pszNames,
503c2c66affSColin Finck     _Inout_ PULONG pulLength,
504c2c66affSColin Finck     _In_ ULONG ulFlags,
505c2c66affSColin Finck     _In_opt_ HMACHINE hMachine)
506c2c66affSColin Finck {
507c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
508c2c66affSColin Finck     ULONG ulTransferLength;
509c2c66affSColin Finck     CONFIGRET ret;
510c2c66affSColin Finck 
511c2c66affSColin Finck     TRACE("CMP_GetBlockedDriverInfo(%p %p %lx %p)\n",
512c2c66affSColin Finck           pszNames, pulLength, ulFlags, hMachine);
513c2c66affSColin Finck 
514c2c66affSColin Finck     if (hMachine != NULL)
515c2c66affSColin Finck     {
516c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
517c2c66affSColin Finck         if (BindingHandle == NULL)
518c2c66affSColin Finck             return CR_FAILURE;
519c2c66affSColin Finck     }
520c2c66affSColin Finck     else
521c2c66affSColin Finck     {
522c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
523c2c66affSColin Finck             return CR_FAILURE;
524c2c66affSColin Finck     }
525c2c66affSColin Finck 
526c2c66affSColin Finck     ulTransferLength = *pulLength;
527c2c66affSColin Finck 
528c2c66affSColin Finck     RpcTryExcept
529c2c66affSColin Finck     {
530c2c66affSColin Finck         ret = PNP_GetBlockedDriverInfo(BindingHandle,
531c2c66affSColin Finck                                        (PBYTE)pszNames,
532c2c66affSColin Finck                                        &ulTransferLength,
533c2c66affSColin Finck                                        pulLength,
534c2c66affSColin Finck                                        ulFlags);
535c2c66affSColin Finck     }
536c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
537c2c66affSColin Finck     {
538c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
539c2c66affSColin Finck     }
540c2c66affSColin Finck     RpcEndExcept;
541c2c66affSColin Finck 
542c2c66affSColin Finck     return ret;
543c2c66affSColin Finck }
544c2c66affSColin Finck 
545c2c66affSColin Finck 
546c2c66affSColin Finck /***********************************************************************
547c2c66affSColin Finck  * CMP_GetServerSideDeviceInstallFlags [SETUPAPI.@]
548c2c66affSColin Finck  */
549c2c66affSColin Finck CONFIGRET
550c2c66affSColin Finck WINAPI
551c2c66affSColin Finck CMP_GetServerSideDeviceInstallFlags(
552c2c66affSColin Finck     _Out_ PULONG pulSSDIFlags,
553c2c66affSColin Finck     _In_ ULONG ulFlags,
554c2c66affSColin Finck     _In_opt_ HMACHINE hMachine)
555c2c66affSColin Finck {
556c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
557c2c66affSColin Finck     CONFIGRET ret;
558c2c66affSColin Finck 
559c2c66affSColin Finck     TRACE("CMP_GetServerSideDeviceInstallFlags(%p %lx %p)\n",
560c2c66affSColin Finck           pulSSDIFlags, ulFlags, hMachine);
561c2c66affSColin Finck 
562c2c66affSColin Finck     if (pulSSDIFlags == NULL)
563c2c66affSColin Finck         return CR_INVALID_POINTER;
564c2c66affSColin Finck 
565c2c66affSColin Finck     if (ulFlags != 0)
566c2c66affSColin Finck         return CR_INVALID_FLAG;
567c2c66affSColin Finck 
568c2c66affSColin Finck     if (hMachine != NULL)
569c2c66affSColin Finck     {
570c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
571c2c66affSColin Finck         if (BindingHandle == NULL)
572c2c66affSColin Finck             return CR_FAILURE;
573c2c66affSColin Finck     }
574c2c66affSColin Finck     else
575c2c66affSColin Finck     {
576c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
577c2c66affSColin Finck             return CR_FAILURE;
578c2c66affSColin Finck     }
579c2c66affSColin Finck 
580c2c66affSColin Finck     RpcTryExcept
581c2c66affSColin Finck     {
582c2c66affSColin Finck         ret = PNP_GetServerSideDeviceInstallFlags(BindingHandle,
583c2c66affSColin Finck                                                   pulSSDIFlags,
584c2c66affSColin Finck                                                   ulFlags);
585c2c66affSColin Finck     }
586c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
587c2c66affSColin Finck     {
588c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
589c2c66affSColin Finck     }
590c2c66affSColin Finck     RpcEndExcept;
591c2c66affSColin Finck 
592c2c66affSColin Finck     return ret;
593c2c66affSColin Finck }
594c2c66affSColin Finck 
595c2c66affSColin Finck 
596c2c66affSColin Finck /***********************************************************************
597c2c66affSColin Finck  * CMP_Init_Detection [SETUPAPI.@]
598c2c66affSColin Finck  */
599c2c66affSColin Finck CONFIGRET
600c2c66affSColin Finck WINAPI
601c2c66affSColin Finck CMP_Init_Detection(
602c2c66affSColin Finck     _In_ ULONG ulMagic)
603c2c66affSColin Finck {
604c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
605c2c66affSColin Finck     CONFIGRET ret;
606c2c66affSColin Finck 
607c2c66affSColin Finck     TRACE("CMP_Init_Detection(%lu)\n", ulMagic);
608c2c66affSColin Finck 
609c2c66affSColin Finck     if (ulMagic != CMP_MAGIC)
610c2c66affSColin Finck         return CR_INVALID_DATA;
611c2c66affSColin Finck 
612c2c66affSColin Finck     if (!PnpGetLocalHandles(&BindingHandle, NULL))
613c2c66affSColin Finck         return CR_FAILURE;
614c2c66affSColin Finck 
615c2c66affSColin Finck     RpcTryExcept
616c2c66affSColin Finck     {
617c2c66affSColin Finck         ret = PNP_InitDetection(BindingHandle);
618c2c66affSColin Finck     }
619c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
620c2c66affSColin Finck     {
621c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
622c2c66affSColin Finck     }
623c2c66affSColin Finck     RpcEndExcept;
624c2c66affSColin Finck 
625c2c66affSColin Finck     return ret;
626c2c66affSColin Finck }
627c2c66affSColin Finck 
628c2c66affSColin Finck 
629c2c66affSColin Finck /***********************************************************************
630c2c66affSColin Finck  * CMP_RegisterNotification [SETUPAPI.@]
631c2c66affSColin Finck  */
632c2c66affSColin Finck CONFIGRET
633c2c66affSColin Finck WINAPI
634c2c66affSColin Finck CMP_RegisterNotification(
635c2c66affSColin Finck     _In_ HANDLE hRecipient,
636c2c66affSColin Finck     _In_ LPVOID lpvNotificationFilter,
637c2c66affSColin Finck     _In_ ULONG ulFlags,
638c2c66affSColin Finck     _Out_ PHDEVNOTIFY phDevNotify)
639c2c66affSColin Finck {
640c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
6418943354dSSerge Gautherie     PNOTIFY_DATA pNotifyData;
642ece54dcdSEric Kohl     WCHAR szNameBuffer[256];
64386e8a477SEric Kohl     INT nLength;
6447eb6e426SEric Kohl     DWORD ulUnknown9 = 0;
64586e8a477SEric Kohl     DWORD dwError;
646c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
647c2c66affSColin Finck 
6487eb6e426SEric Kohl     FIXME("CMP_RegisterNotification(%p %p %lu %p)\n",
649c2c66affSColin Finck           hRecipient, lpvNotificationFilter, ulFlags, phDevNotify);
650c2c66affSColin Finck 
651c2c66affSColin Finck     if ((hRecipient == NULL) ||
652c2c66affSColin Finck         (lpvNotificationFilter == NULL) ||
653c2c66affSColin Finck         (phDevNotify == NULL))
654c2c66affSColin Finck         return CR_INVALID_POINTER;
655c2c66affSColin Finck 
656c2c66affSColin Finck     if (ulFlags & ~0x7)
657c2c66affSColin Finck         return CR_INVALID_FLAG;
658c2c66affSColin Finck 
659c2c66affSColin Finck     if (((PDEV_BROADCAST_HDR)lpvNotificationFilter)->dbch_size < sizeof(DEV_BROADCAST_HDR))
660c2c66affSColin Finck         return CR_INVALID_DATA;
661c2c66affSColin Finck 
662c2c66affSColin Finck     if (!PnpGetLocalHandles(&BindingHandle, NULL))
663c2c66affSColin Finck         return CR_FAILURE;
664c2c66affSColin Finck 
665c2c66affSColin Finck     pNotifyData = HeapAlloc(GetProcessHeap(),
666c2c66affSColin Finck                             HEAP_ZERO_MEMORY,
667c2c66affSColin Finck                             sizeof(NOTIFY_DATA));
668c2c66affSColin Finck     if (pNotifyData == NULL)
669c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
670c2c66affSColin Finck 
671c2c66affSColin Finck     pNotifyData->ulMagic = NOTIFY_MAGIC;
672b0a73746SEric Kohl     pNotifyData->hNotifyHandle = NULL;
673c2c66affSColin Finck 
6749277f535SEric Kohl     ZeroMemory(szNameBuffer, sizeof(szNameBuffer));
6759277f535SEric Kohl 
676ece54dcdSEric Kohl     if ((ulFlags & DEVICE_NOTIFY_SERVICE_HANDLE) == DEVICE_NOTIFY_WINDOW_HANDLE)
677c2c66affSColin Finck     {
678ece54dcdSEric Kohl         FIXME("Register a window\n");
679c2c66affSColin Finck 
68086e8a477SEric Kohl         nLength = GetWindowTextW((HWND)hRecipient,
68186e8a477SEric Kohl                                  szNameBuffer,
68286e8a477SEric Kohl                                  ARRAYSIZE(szNameBuffer));
68386e8a477SEric Kohl         if (nLength == 0)
68486e8a477SEric Kohl         {
6859277f535SEric Kohl             szNameBuffer[0] = UNICODE_NULL;
68686e8a477SEric Kohl         }
68786e8a477SEric Kohl 
68886e8a477SEric Kohl         FIXME("Register window: %S\n", szNameBuffer);
689c2c66affSColin Finck     }
690ece54dcdSEric Kohl     else if ((ulFlags & DEVICE_NOTIFY_SERVICE_HANDLE) == DEVICE_NOTIFY_SERVICE_HANDLE)
691c2c66affSColin Finck     {
692ece54dcdSEric Kohl         FIXME("Register a service\n");
693c2c66affSColin Finck 
694ece54dcdSEric Kohl         dwError = I_ScPnPGetServiceName((SERVICE_STATUS_HANDLE)hRecipient,
695ece54dcdSEric Kohl                                         szNameBuffer,
696ece54dcdSEric Kohl                                         ARRAYSIZE(szNameBuffer));
697ece54dcdSEric Kohl         if (dwError != ERROR_SUCCESS)
698ece54dcdSEric Kohl         {
699ece54dcdSEric Kohl             HeapFree(GetProcessHeap(), 0, pNotifyData);
700ece54dcdSEric Kohl             return CR_INVALID_DATA;
701c2c66affSColin Finck         }
702ece54dcdSEric Kohl 
703ece54dcdSEric Kohl         FIXME("Register service: %S\n", szNameBuffer);
704ece54dcdSEric Kohl     }
705c2c66affSColin Finck 
706c2c66affSColin Finck     RpcTryExcept
707c2c66affSColin Finck     {
708c2c66affSColin Finck         ret = PNP_RegisterNotification(BindingHandle,
70971df39b0SEric Kohl                                        (DWORD_PTR)hRecipient,
710ece54dcdSEric Kohl                                        szNameBuffer,
711ca040613SEric Kohl                                        (BYTE*)lpvNotificationFilter,
712ca040613SEric Kohl                                        ((DEV_BROADCAST_HDR*)lpvNotificationFilter)->dbch_size,
713c2c66affSColin Finck                                        ulFlags,
714b0a73746SEric Kohl                                        &pNotifyData->hNotifyHandle,
7157faca935SEric Kohl                                        GetCurrentProcessId(),
716ece54dcdSEric Kohl                                        &ulUnknown9); /* ??? */
717c2c66affSColin Finck     }
718c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
719c2c66affSColin Finck     {
720c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
721c2c66affSColin Finck     }
722c2c66affSColin Finck     RpcEndExcept;
723c2c66affSColin Finck 
724c2c66affSColin Finck     if (ret == CR_SUCCESS)
725c2c66affSColin Finck     {
726b0a73746SEric Kohl         TRACE("hNotifyHandle: %p\n", pNotifyData->hNotifyHandle);
727c2c66affSColin Finck         *phDevNotify = (HDEVNOTIFY)pNotifyData;
728c2c66affSColin Finck     }
729c2c66affSColin Finck     else
730c2c66affSColin Finck     {
731c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, pNotifyData);
732c2c66affSColin Finck 
733c2c66affSColin Finck         *phDevNotify = (HDEVNOTIFY)NULL;
734c2c66affSColin Finck     }
735c2c66affSColin Finck 
736c2c66affSColin Finck     return ret;
737c2c66affSColin Finck }
738c2c66affSColin Finck 
739c2c66affSColin Finck 
740c2c66affSColin Finck /***********************************************************************
741c2c66affSColin Finck  * CMP_Report_LogOn [SETUPAPI.@]
742c2c66affSColin Finck  */
743c2c66affSColin Finck CONFIGRET
744c2c66affSColin Finck WINAPI
745c2c66affSColin Finck CMP_Report_LogOn(
746c2c66affSColin Finck     _In_ DWORD dwMagic,
747c2c66affSColin Finck     _In_ DWORD dwProcessId)
748c2c66affSColin Finck {
749c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
750c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
751c2c66affSColin Finck     BOOL bAdmin;
752c2c66affSColin Finck     DWORD i;
753c2c66affSColin Finck 
754c2c66affSColin Finck     TRACE("CMP_Report_LogOn(%lu %lu)\n", dwMagic, dwProcessId);
755c2c66affSColin Finck 
756c2c66affSColin Finck     if (dwMagic != CMP_MAGIC)
757c2c66affSColin Finck         return CR_INVALID_DATA;
758c2c66affSColin Finck 
759c2c66affSColin Finck     if (!PnpGetLocalHandles(&BindingHandle, NULL))
760c2c66affSColin Finck         return CR_FAILURE;
761c2c66affSColin Finck 
762c2c66affSColin Finck     bAdmin = pSetupIsUserAdmin();
763c2c66affSColin Finck 
764c2c66affSColin Finck     for (i = 0; i < 30; i++)
765c2c66affSColin Finck     {
766c2c66affSColin Finck         RpcTryExcept
767c2c66affSColin Finck         {
768c2c66affSColin Finck             ret = PNP_ReportLogOn(BindingHandle,
769c2c66affSColin Finck                                   bAdmin,
770c2c66affSColin Finck                                   dwProcessId);
771c2c66affSColin Finck         }
772c2c66affSColin Finck         RpcExcept(EXCEPTION_EXECUTE_HANDLER)
773c2c66affSColin Finck         {
774c2c66affSColin Finck             ret = RpcStatusToCmStatus(RpcExceptionCode());
775c2c66affSColin Finck         }
776c2c66affSColin Finck         RpcEndExcept;
777c2c66affSColin Finck 
778c2c66affSColin Finck         if (ret == CR_SUCCESS)
779c2c66affSColin Finck             break;
780c2c66affSColin Finck 
781c2c66affSColin Finck         Sleep(5000);
782c2c66affSColin Finck     }
783c2c66affSColin Finck 
784c2c66affSColin Finck     return ret;
785c2c66affSColin Finck }
786c2c66affSColin Finck 
787c2c66affSColin Finck 
788c2c66affSColin Finck /***********************************************************************
789c2c66affSColin Finck  * CMP_UnregisterNotification [SETUPAPI.@]
790c2c66affSColin Finck  */
791c2c66affSColin Finck CONFIGRET
792c2c66affSColin Finck WINAPI
793c2c66affSColin Finck CMP_UnregisterNotification(
794c2c66affSColin Finck     _In_ HDEVNOTIFY hDevNotify)
795c2c66affSColin Finck {
796c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
797c2c66affSColin Finck     PNOTIFY_DATA pNotifyData;
798c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
799c2c66affSColin Finck 
800c2c66affSColin Finck     TRACE("CMP_UnregisterNotification(%p)\n", hDevNotify);
801c2c66affSColin Finck 
802c2c66affSColin Finck     pNotifyData = (PNOTIFY_DATA)hDevNotify;
803c2c66affSColin Finck 
804c2c66affSColin Finck     if ((pNotifyData == NULL) ||
805c2c66affSColin Finck         (pNotifyData->ulMagic != NOTIFY_MAGIC))
806c2c66affSColin Finck         return CR_INVALID_POINTER;
807c2c66affSColin Finck 
808c2c66affSColin Finck     if (!PnpGetLocalHandles(&BindingHandle, NULL))
809c2c66affSColin Finck         return CR_FAILURE;
810c2c66affSColin Finck 
811c2c66affSColin Finck     RpcTryExcept
812c2c66affSColin Finck     {
813c2c66affSColin Finck         ret = PNP_UnregisterNotification(BindingHandle,
814b0a73746SEric Kohl                                          &pNotifyData->hNotifyHandle);
815c2c66affSColin Finck     }
816c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
817c2c66affSColin Finck     {
818c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
819c2c66affSColin Finck     }
820c2c66affSColin Finck     RpcEndExcept;
821c2c66affSColin Finck 
822c2c66affSColin Finck     if (ret == CR_SUCCESS)
823b0a73746SEric Kohl     {
824b0a73746SEric Kohl         pNotifyData->hNotifyHandle = NULL;
825c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, pNotifyData);
826b0a73746SEric Kohl     }
827c2c66affSColin Finck 
828c2c66affSColin Finck     return ret;
829c2c66affSColin Finck }
830c2c66affSColin Finck 
831c2c66affSColin Finck 
832c2c66affSColin Finck /***********************************************************************
833c2c66affSColin Finck  * CMP_WaitNoPendingInstallEvents [SETUPAPI.@]
834c2c66affSColin Finck  */
835c2c66affSColin Finck DWORD
836c2c66affSColin Finck WINAPI
837c2c66affSColin Finck CMP_WaitNoPendingInstallEvents(
838c2c66affSColin Finck     _In_ DWORD dwTimeout)
839c2c66affSColin Finck {
840c2c66affSColin Finck     HANDLE hEvent;
841c2c66affSColin Finck     DWORD ret;
842c2c66affSColin Finck 
843c2c66affSColin Finck     TRACE("CMP_WaitNoPendingInstallEvents(%lu)\n", dwTimeout);
844c2c66affSColin Finck 
845c2c66affSColin Finck     hEvent = OpenEventW(SYNCHRONIZE, FALSE, L"Global\\PnP_No_Pending_Install_Events");
846c2c66affSColin Finck     if (hEvent == NULL)
847c2c66affSColin Finck        return WAIT_FAILED;
848c2c66affSColin Finck 
849c2c66affSColin Finck     ret = WaitForSingleObject(hEvent, dwTimeout);
850c2c66affSColin Finck     CloseHandle(hEvent);
851c2c66affSColin Finck     return ret;
852c2c66affSColin Finck }
853c2c66affSColin Finck 
854c2c66affSColin Finck 
855c2c66affSColin Finck /***********************************************************************
856c2c66affSColin Finck  * CMP_WaitServicesAvailable [SETUPAPI.@]
857c2c66affSColin Finck  */
858c2c66affSColin Finck CONFIGRET
859c2c66affSColin Finck WINAPI
860c2c66affSColin Finck CMP_WaitServicesAvailable(
861c2c66affSColin Finck     _In_opt_ HMACHINE hMachine)
862c2c66affSColin Finck {
863c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
864c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
865c2c66affSColin Finck     WORD Version;
866c2c66affSColin Finck 
867c2c66affSColin Finck     TRACE("CMP_WaitServicesAvailable(%p)\n", hMachine);
868c2c66affSColin Finck 
869c2c66affSColin Finck     if (hMachine != NULL)
870c2c66affSColin Finck     {
871c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
872c2c66affSColin Finck         if (BindingHandle == NULL)
873c2c66affSColin Finck             return CR_FAILURE;
874c2c66affSColin Finck     }
875c2c66affSColin Finck     else
876c2c66affSColin Finck     {
877c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
878c2c66affSColin Finck             return CR_FAILURE;
879c2c66affSColin Finck     }
880c2c66affSColin Finck 
881c2c66affSColin Finck     RpcTryExcept
882c2c66affSColin Finck     {
883c2c66affSColin Finck         ret = PNP_GetVersion(BindingHandle, &Version);
884c2c66affSColin Finck     }
885c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
886c2c66affSColin Finck     {
887c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
888c2c66affSColin Finck     }
889c2c66affSColin Finck     RpcEndExcept;
890c2c66affSColin Finck 
891c2c66affSColin Finck     return ret;
892c2c66affSColin Finck }
893c2c66affSColin Finck 
894c2c66affSColin Finck 
895c2c66affSColin Finck /***********************************************************************
896c2c66affSColin Finck  * CM_Add_Empty_Log_Conf [SETUPAPI.@]
897c2c66affSColin Finck  */
898d9a33981SEric Kohl CONFIGRET
899d9a33981SEric Kohl WINAPI
900d9a33981SEric Kohl CM_Add_Empty_Log_Conf(
901d9a33981SEric Kohl     _Out_ PLOG_CONF plcLogConf,
902d9a33981SEric Kohl     _In_ DEVINST dnDevInst,
903d9a33981SEric Kohl     _In_ PRIORITY Priority,
904d9a33981SEric Kohl     _In_ ULONG ulFlags)
905c2c66affSColin Finck {
906d9a33981SEric Kohl     TRACE("CM_Add_Empty_Log_Conf(%p %p %lu %lx)\n",
907d9a33981SEric Kohl           plcLogConf, dnDevInst, Priority, ulFlags);
90865d3bf74SEric Kohl 
909c2c66affSColin Finck     return CM_Add_Empty_Log_Conf_Ex(plcLogConf, dnDevInst, Priority,
910c2c66affSColin Finck                                     ulFlags, NULL);
911c2c66affSColin Finck }
912c2c66affSColin Finck 
913c2c66affSColin Finck 
914c2c66affSColin Finck /***********************************************************************
915c2c66affSColin Finck  * CM_Add_Empty_Log_Conf_Ex [SETUPAPI.@]
916c2c66affSColin Finck  */
917d9a33981SEric Kohl CONFIGRET
918adc9bd48SEric Kohl WINAPI
919adc9bd48SEric Kohl CM_Add_Empty_Log_Conf_Ex(
920d9a33981SEric Kohl     _Out_ PLOG_CONF plcLogConf,
921d9a33981SEric Kohl     _In_ DEVINST dnDevInst,
922d9a33981SEric Kohl     _In_ PRIORITY Priority,
923d9a33981SEric Kohl     _In_ ULONG ulFlags,
924d9a33981SEric Kohl     _In_opt_ HMACHINE hMachine)
925c2c66affSColin Finck {
926c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
927c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
928c2c66affSColin Finck     ULONG ulLogConfTag = 0;
929c2c66affSColin Finck     LPWSTR lpDevInst;
930c2c66affSColin Finck     PLOG_CONF_INFO pLogConfInfo;
931c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
932c2c66affSColin Finck 
933d9a33981SEric Kohl     FIXME("CM_Add_Empty_Log_Conf_Ex(%p %p %lu %lx %p)\n",
934c2c66affSColin Finck           plcLogConf, dnDevInst, Priority, ulFlags, hMachine);
935c2c66affSColin Finck 
936c2c66affSColin Finck     if (!pSetupIsUserAdmin())
937c2c66affSColin Finck         return CR_ACCESS_DENIED;
938c2c66affSColin Finck 
939c2c66affSColin Finck     if (plcLogConf == NULL)
940c2c66affSColin Finck         return CR_INVALID_POINTER;
941c2c66affSColin Finck 
942c2c66affSColin Finck     if (dnDevInst == 0)
943c2c66affSColin Finck         return CR_INVALID_DEVINST;
944c2c66affSColin Finck 
945c2c66affSColin Finck     if (Priority > 0xFFFF)
946c2c66affSColin Finck         return CR_INVALID_PRIORITY;
947c2c66affSColin Finck 
948c2c66affSColin Finck     if (ulFlags & ~(LOG_CONF_BITS | PRIORITY_BIT))
949c2c66affSColin Finck         return CR_INVALID_FLAG;
950c2c66affSColin Finck 
951c2c66affSColin Finck     if (hMachine != NULL)
952c2c66affSColin Finck     {
953c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
954c2c66affSColin Finck         if (BindingHandle == NULL)
955c2c66affSColin Finck             return CR_FAILURE;
956c2c66affSColin Finck 
957c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
958c2c66affSColin Finck         if (StringTable == 0)
959c2c66affSColin Finck             return CR_FAILURE;
960c2c66affSColin Finck     }
961c2c66affSColin Finck     else
962c2c66affSColin Finck     {
963c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
964c2c66affSColin Finck             return CR_FAILURE;
965c2c66affSColin Finck     }
966c2c66affSColin Finck 
967c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
968c2c66affSColin Finck     if (lpDevInst == NULL)
969c2c66affSColin Finck         return CR_INVALID_DEVNODE;
970c2c66affSColin Finck 
971c2c66affSColin Finck     RpcTryExcept
972c2c66affSColin Finck     {
973c2c66affSColin Finck         ret = PNP_AddEmptyLogConf(BindingHandle, lpDevInst, Priority,
974c2c66affSColin Finck                                   &ulLogConfTag, ulFlags);
975c2c66affSColin Finck     }
976c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
977c2c66affSColin Finck     {
978c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
979c2c66affSColin Finck     }
980c2c66affSColin Finck     RpcEndExcept;
981c2c66affSColin Finck 
982c2c66affSColin Finck     if (ret == CR_SUCCESS)
983c2c66affSColin Finck     {
984c2c66affSColin Finck         pLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
985c2c66affSColin Finck         if (pLogConfInfo == NULL)
986c2c66affSColin Finck         {
987c2c66affSColin Finck             ret = CR_OUT_OF_MEMORY;
988c2c66affSColin Finck         }
989c2c66affSColin Finck         else
990c2c66affSColin Finck         {
991c2c66affSColin Finck             pLogConfInfo->ulMagic = LOG_CONF_MAGIC;
992c2c66affSColin Finck             pLogConfInfo->dnDevInst = dnDevInst;
9936efb3cbeSEric Kohl             pLogConfInfo->ulType = ulFlags;
994c2c66affSColin Finck             pLogConfInfo->ulTag = ulLogConfTag;
995c2c66affSColin Finck 
996c2c66affSColin Finck             *plcLogConf = (LOG_CONF)pLogConfInfo;
997c2c66affSColin Finck 
998c2c66affSColin Finck             ret = CR_SUCCESS;
999c2c66affSColin Finck         }
1000c2c66affSColin Finck     }
1001c2c66affSColin Finck 
1002c2c66affSColin Finck     return ret;
1003c2c66affSColin Finck }
1004c2c66affSColin Finck 
1005c2c66affSColin Finck 
1006c2c66affSColin Finck /***********************************************************************
1007c2c66affSColin Finck  * CM_Add_IDA [SETUPAPI.@]
1008c2c66affSColin Finck  */
1009d9a33981SEric Kohl CONFIGRET
1010d9a33981SEric Kohl WINAPI
1011d9a33981SEric Kohl CM_Add_IDA(
1012d9a33981SEric Kohl     _In_ DEVINST dnDevInst,
1013d9a33981SEric Kohl     _In_ PSTR pszID,
1014d9a33981SEric Kohl     _In_ ULONG ulFlags)
1015c2c66affSColin Finck {
1016d9a33981SEric Kohl     TRACE("CM_Add_IDA(%p %s %lx)\n",
101765d3bf74SEric Kohl           dnDevInst, debugstr_a(pszID), ulFlags);
101865d3bf74SEric Kohl 
1019c2c66affSColin Finck     return CM_Add_ID_ExA(dnDevInst, pszID, ulFlags, NULL);
1020c2c66affSColin Finck }
1021c2c66affSColin Finck 
1022c2c66affSColin Finck 
1023c2c66affSColin Finck /***********************************************************************
1024c2c66affSColin Finck  * CM_Add_IDW [SETUPAPI.@]
1025c2c66affSColin Finck  */
1026d9a33981SEric Kohl CONFIGRET
1027d9a33981SEric Kohl WINAPI
1028d9a33981SEric Kohl CM_Add_IDW(
1029d9a33981SEric Kohl     _In_ DEVINST dnDevInst,
1030d9a33981SEric Kohl     _In_ PWSTR pszID,
1031d9a33981SEric Kohl     _In_ ULONG ulFlags)
1032c2c66affSColin Finck {
1033d9a33981SEric Kohl     TRACE("CM_Add_IDW(%p %s %lx)\n",
1034d9a33981SEric Kohl           dnDevInst, debugstr_w(pszID), ulFlags);
103565d3bf74SEric Kohl 
1036c2c66affSColin Finck     return CM_Add_ID_ExW(dnDevInst, pszID, ulFlags, NULL);
1037c2c66affSColin Finck }
1038c2c66affSColin Finck 
1039c2c66affSColin Finck 
1040c2c66affSColin Finck /***********************************************************************
1041c2c66affSColin Finck  * CM_Add_ID_ExA [SETUPAPI.@]
1042c2c66affSColin Finck  */
1043d9a33981SEric Kohl CONFIGRET
1044d9a33981SEric Kohl WINAPI
1045d9a33981SEric Kohl CM_Add_ID_ExA(
1046d9a33981SEric Kohl     _In_ DEVINST dnDevInst,
1047d9a33981SEric Kohl     _In_ PSTR pszID,
1048d9a33981SEric Kohl     _In_ ULONG ulFlags,
1049d9a33981SEric Kohl     _In_opt_ HMACHINE hMachine)
1050c2c66affSColin Finck {
1051c2c66affSColin Finck     PWSTR pszIDW;
1052c2c66affSColin Finck     CONFIGRET ret;
1053c2c66affSColin Finck 
1054d9a33981SEric Kohl     TRACE("CM_Add_ID_ExA(%p %s %lx %p)\n",
105565d3bf74SEric Kohl           dnDevInst, debugstr_a(pszID), ulFlags, hMachine);
1056c2c66affSColin Finck 
1057c2c66affSColin Finck     if (pSetupCaptureAndConvertAnsiArg(pszID, &pszIDW))
1058c2c66affSColin Finck         return CR_INVALID_DATA;
1059c2c66affSColin Finck 
1060c2c66affSColin Finck     ret = CM_Add_ID_ExW(dnDevInst, pszIDW, ulFlags, hMachine);
1061c2c66affSColin Finck 
1062c2c66affSColin Finck     MyFree(pszIDW);
1063c2c66affSColin Finck 
1064c2c66affSColin Finck     return ret;
1065c2c66affSColin Finck }
1066c2c66affSColin Finck 
1067c2c66affSColin Finck 
1068c2c66affSColin Finck /***********************************************************************
1069c2c66affSColin Finck  * CM_Add_ID_ExW [SETUPAPI.@]
1070c2c66affSColin Finck  */
1071d9a33981SEric Kohl CONFIGRET
1072d9a33981SEric Kohl WINAPI
1073d9a33981SEric Kohl CM_Add_ID_ExW(
1074d9a33981SEric Kohl     _In_ DEVINST dnDevInst,
1075d9a33981SEric Kohl     _In_ PWSTR pszID,
1076d9a33981SEric Kohl     _In_ ULONG ulFlags,
1077d9a33981SEric Kohl     _In_opt_ HMACHINE hMachine)
1078c2c66affSColin Finck {
1079c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
1080c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
1081c2c66affSColin Finck     LPWSTR lpDevInst;
1082c2c66affSColin Finck     CONFIGRET ret;
1083c2c66affSColin Finck 
1084d9a33981SEric Kohl     TRACE("CM_Add_ID_ExW(%p %s %lx %p)\n",
1085d9a33981SEric Kohl           dnDevInst, debugstr_w(pszID), ulFlags, hMachine);
1086c2c66affSColin Finck 
1087c2c66affSColin Finck     if (!pSetupIsUserAdmin())
1088c2c66affSColin Finck         return CR_ACCESS_DENIED;
1089c2c66affSColin Finck 
1090c2c66affSColin Finck     if (dnDevInst == 0)
1091c2c66affSColin Finck         return CR_INVALID_DEVINST;
1092c2c66affSColin Finck 
1093c2c66affSColin Finck     if (pszID == NULL)
1094c2c66affSColin Finck         return CR_INVALID_POINTER;
1095c2c66affSColin Finck 
1096c2c66affSColin Finck     if (ulFlags & ~CM_ADD_ID_BITS)
1097c2c66affSColin Finck         return CR_INVALID_FLAG;
1098c2c66affSColin Finck 
1099c2c66affSColin Finck     if (hMachine != NULL)
1100c2c66affSColin Finck     {
1101c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1102c2c66affSColin Finck         if (BindingHandle == NULL)
1103c2c66affSColin Finck             return CR_FAILURE;
1104c2c66affSColin Finck 
1105c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1106c2c66affSColin Finck         if (StringTable == 0)
1107c2c66affSColin Finck             return CR_FAILURE;
1108c2c66affSColin Finck     }
1109c2c66affSColin Finck     else
1110c2c66affSColin Finck     {
1111c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1112c2c66affSColin Finck             return CR_FAILURE;
1113c2c66affSColin Finck     }
1114c2c66affSColin Finck 
1115c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1116c2c66affSColin Finck     if (lpDevInst == NULL)
1117c2c66affSColin Finck         return CR_INVALID_DEVNODE;
1118c2c66affSColin Finck 
1119c2c66affSColin Finck     RpcTryExcept
1120c2c66affSColin Finck     {
1121c2c66affSColin Finck         ret = PNP_AddID(BindingHandle,
1122c2c66affSColin Finck                         lpDevInst,
1123c2c66affSColin Finck                         pszID,
1124c2c66affSColin Finck                         ulFlags);
1125c2c66affSColin Finck     }
1126c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1127c2c66affSColin Finck     {
1128c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
1129c2c66affSColin Finck     }
1130c2c66affSColin Finck     RpcEndExcept;
1131c2c66affSColin Finck 
1132c2c66affSColin Finck     return ret;
1133c2c66affSColin Finck }
1134c2c66affSColin Finck 
1135c2c66affSColin Finck 
1136c2c66affSColin Finck /***********************************************************************
1137c2c66affSColin Finck  * CM_Add_Range [SETUPAPI.@]
1138c2c66affSColin Finck  */
1139c2c66affSColin Finck CONFIGRET
1140c2c66affSColin Finck WINAPI
1141c2c66affSColin Finck CM_Add_Range(
1142c2c66affSColin Finck     _In_ DWORDLONG ullStartValue,
1143c2c66affSColin Finck     _In_ DWORDLONG ullEndValue,
1144c2c66affSColin Finck     _In_ RANGE_LIST rlh,
1145c2c66affSColin Finck     _In_ ULONG ulFlags)
1146c2c66affSColin Finck {
11473ad5c7fdSEric Kohl     PINTERNAL_RANGE_LIST pRangeList;
11483ad5c7fdSEric Kohl     PINTERNAL_RANGE pRange;
11493ad5c7fdSEric Kohl     CONFIGRET ret = CR_SUCCESS;
11503ad5c7fdSEric Kohl 
1151c2c66affSColin Finck     FIXME("CM_Add_Range(%I64u %I64u %p %lx)\n",
1152c2c66affSColin Finck           ullStartValue, ullEndValue, rlh, ulFlags);
11533ad5c7fdSEric Kohl 
11543ad5c7fdSEric Kohl     pRangeList = (PINTERNAL_RANGE_LIST)rlh;
11553ad5c7fdSEric Kohl 
11563ad5c7fdSEric Kohl     if (!IsValidRangeList(pRangeList))
11573ad5c7fdSEric Kohl         return CR_INVALID_RANGE_LIST;
11583ad5c7fdSEric Kohl 
11593ad5c7fdSEric Kohl     if (ulFlags & ~CM_ADD_RANGE_BITS)
11603ad5c7fdSEric Kohl         return CR_INVALID_FLAG;
11613ad5c7fdSEric Kohl 
11623ad5c7fdSEric Kohl     if (ullEndValue < ullStartValue)
11633ad5c7fdSEric Kohl         return CR_INVALID_RANGE;
11643ad5c7fdSEric Kohl 
11653ad5c7fdSEric Kohl     /* Lock the range list */
11663ad5c7fdSEric Kohl     WaitForSingleObject(pRangeList->hMutex, INFINITE);
11673ad5c7fdSEric Kohl 
11683ad5c7fdSEric Kohl     /* Allocate the new range */
11693ad5c7fdSEric Kohl     pRange = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNAL_RANGE));
11703ad5c7fdSEric Kohl     if (pRange == NULL)
11713ad5c7fdSEric Kohl     {
11723ad5c7fdSEric Kohl         ret = CR_OUT_OF_MEMORY;
11733ad5c7fdSEric Kohl         goto done;
11743ad5c7fdSEric Kohl     }
11753ad5c7fdSEric Kohl 
1176e88a6b20SEric Kohl     pRange->pRangeList = pRangeList;
11773ad5c7fdSEric Kohl     pRange->ullStart = ullStartValue;
11783ad5c7fdSEric Kohl     pRange->ullEnd = ullEndValue;
11793ad5c7fdSEric Kohl 
11803ad5c7fdSEric Kohl     /* Insert the range */
11813ad5c7fdSEric Kohl     if (IsListEmpty(&pRangeList->ListHead))
11823ad5c7fdSEric Kohl     {
11833ad5c7fdSEric Kohl         InsertTailList(&pRangeList->ListHead, &pRange->ListEntry);
11843ad5c7fdSEric Kohl     }
11853ad5c7fdSEric Kohl     else
11863ad5c7fdSEric Kohl     {
11870bc8e2a5SBișoc George         HeapFree(GetProcessHeap(), 0, pRange);
11880bc8e2a5SBișoc George         UNIMPLEMENTED;
11893ad5c7fdSEric Kohl     }
11903ad5c7fdSEric Kohl 
11913ad5c7fdSEric Kohl done:
11923ad5c7fdSEric Kohl     /* Unlock the range list */
11933ad5c7fdSEric Kohl     ReleaseMutex(pRangeList->hMutex);
11943ad5c7fdSEric Kohl 
11953ad5c7fdSEric Kohl     return ret;
1196c2c66affSColin Finck }
1197c2c66affSColin Finck 
1198c2c66affSColin Finck 
1199c2c66affSColin Finck /***********************************************************************
1200c2c66affSColin Finck  * CM_Add_Res_Des [SETUPAPI.@]
1201c2c66affSColin Finck  */
1202d9a33981SEric Kohl CONFIGRET
1203d9a33981SEric Kohl WINAPI
1204d9a33981SEric Kohl CM_Add_Res_Des(
1205d9a33981SEric Kohl     _Out_opt_ PRES_DES prdResDes,
1206d9a33981SEric Kohl     _In_ LOG_CONF lcLogConf,
1207d9a33981SEric Kohl     _In_ RESOURCEID ResourceID,
120865d3bf74SEric Kohl     _In_reads_bytes_(ResourceLen) PCVOID ResourceData,
1209d9a33981SEric Kohl     _In_ ULONG ResourceLen,
1210d9a33981SEric Kohl     _In_ ULONG ulFlags)
1211c2c66affSColin Finck {
1212d9a33981SEric Kohl     TRACE("CM_Add_Res_Des(%p %p %lu %p %lu %lx)\n",
1213d9a33981SEric Kohl           prdResDes, lcLogConf, ResourceID, ResourceData, ResourceLen, ulFlags);
121465d3bf74SEric Kohl 
1215c2c66affSColin Finck     return CM_Add_Res_Des_Ex(prdResDes, lcLogConf, ResourceID, ResourceData,
1216c2c66affSColin Finck                              ResourceLen, ulFlags, NULL);
1217c2c66affSColin Finck }
1218c2c66affSColin Finck 
1219c2c66affSColin Finck 
1220c2c66affSColin Finck /***********************************************************************
1221c2c66affSColin Finck  * CM_Add_Res_Des_Ex [SETUPAPI.@]
1222c2c66affSColin Finck  */
1223d9a33981SEric Kohl CONFIGRET
1224d9a33981SEric Kohl WINAPI
1225d9a33981SEric Kohl CM_Add_Res_Des_Ex(
1226d9a33981SEric Kohl     _Out_opt_ PRES_DES prdResDes,
1227d9a33981SEric Kohl     _In_ LOG_CONF lcLogConf,
1228d9a33981SEric Kohl     _In_ RESOURCEID ResourceID,
122965d3bf74SEric Kohl     _In_reads_bytes_(ResourceLen) PCVOID ResourceData,
1230d9a33981SEric Kohl     _In_ ULONG ResourceLen,
1231d9a33981SEric Kohl     _In_ ULONG ulFlags,
1232d9a33981SEric Kohl     _In_opt_ HMACHINE hMachine)
1233c2c66affSColin Finck {
1234d9a33981SEric Kohl     FIXME("CM_Add_Res_Des_Ex(%p %p %lu %p %lu %lx %p)\n",
1235d9a33981SEric Kohl           prdResDes, lcLogConf, ResourceID,
1236c2c66affSColin Finck           ResourceData, ResourceLen, ulFlags, hMachine);
1237c2c66affSColin Finck 
1238c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
1239c2c66affSColin Finck }
1240c2c66affSColin Finck 
1241c2c66affSColin Finck 
1242c2c66affSColin Finck /***********************************************************************
1243c2c66affSColin Finck  * CM_Connect_MachineA [SETUPAPI.@]
1244c2c66affSColin Finck  */
1245d9a33981SEric Kohl CONFIGRET
1246d9a33981SEric Kohl WINAPI
1247d9a33981SEric Kohl CM_Connect_MachineA(
1248d9a33981SEric Kohl     _In_opt_ PCSTR UNCServerName,
1249d9a33981SEric Kohl     _Out_ PHMACHINE phMachine)
1250c2c66affSColin Finck {
1251c2c66affSColin Finck     PWSTR pServerNameW;
1252c2c66affSColin Finck     CONFIGRET ret;
1253c2c66affSColin Finck 
1254d9a33981SEric Kohl     TRACE("CM_Connect_MachineA(%s %p)\n",
125565d3bf74SEric Kohl           debugstr_a(UNCServerName), phMachine);
1256c2c66affSColin Finck 
1257c2c66affSColin Finck     if (UNCServerName == NULL || *UNCServerName == 0)
1258c2c66affSColin Finck         return CM_Connect_MachineW(NULL, phMachine);
1259c2c66affSColin Finck 
1260c2c66affSColin Finck     if (pSetupCaptureAndConvertAnsiArg(UNCServerName, &pServerNameW))
1261c2c66affSColin Finck         return CR_INVALID_DATA;
1262c2c66affSColin Finck 
1263c2c66affSColin Finck     ret = CM_Connect_MachineW(pServerNameW, phMachine);
1264c2c66affSColin Finck 
1265c2c66affSColin Finck     MyFree(pServerNameW);
1266c2c66affSColin Finck 
1267c2c66affSColin Finck     return ret;
1268c2c66affSColin Finck }
1269c2c66affSColin Finck 
1270c2c66affSColin Finck 
1271c2c66affSColin Finck /***********************************************************************
1272c2c66affSColin Finck  * CM_Connect_MachineW [SETUPAPI.@]
1273c2c66affSColin Finck  */
1274d9a33981SEric Kohl CONFIGRET
1275d9a33981SEric Kohl WINAPI
1276d9a33981SEric Kohl CM_Connect_MachineW(
1277d9a33981SEric Kohl     _In_opt_ PCWSTR UNCServerName,
1278d9a33981SEric Kohl     _Out_ PHMACHINE phMachine)
1279c2c66affSColin Finck {
1280c2c66affSColin Finck     PMACHINE_INFO pMachine;
1281c2c66affSColin Finck 
1282d9a33981SEric Kohl     TRACE("CM_Connect_MachineW(%s %p)\n",
1283d9a33981SEric Kohl           debugstr_w(UNCServerName), phMachine);
1284c2c66affSColin Finck 
1285c2c66affSColin Finck     if (phMachine == NULL)
1286c2c66affSColin Finck         return CR_INVALID_POINTER;
1287c2c66affSColin Finck 
1288c2c66affSColin Finck     *phMachine = NULL;
1289c2c66affSColin Finck 
1290c2c66affSColin Finck     pMachine = HeapAlloc(GetProcessHeap(), 0, sizeof(MACHINE_INFO));
1291c2c66affSColin Finck     if (pMachine == NULL)
1292c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
1293c2c66affSColin Finck 
1294c2c66affSColin Finck     if (UNCServerName == NULL || *UNCServerName == 0)
1295c2c66affSColin Finck     {
1296c2c66affSColin Finck         pMachine->bLocal = TRUE;
1297c2c66affSColin Finck 
1298c2c66affSColin Finck         /* FIXME: store the computers name in pMachine->szMachineName */
1299c2c66affSColin Finck 
1300c2c66affSColin Finck         if (!PnpGetLocalHandles(&pMachine->BindingHandle,
1301c2c66affSColin Finck                                 &pMachine->StringTable))
1302c2c66affSColin Finck         {
1303c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, pMachine);
1304c2c66affSColin Finck             return CR_FAILURE;
1305c2c66affSColin Finck         }
1306c2c66affSColin Finck     }
1307c2c66affSColin Finck     else
1308c2c66affSColin Finck     {
1309c2c66affSColin Finck         pMachine->bLocal = FALSE;
1310c2c66affSColin Finck         if (wcslen(UNCServerName) >= SP_MAX_MACHINENAME_LENGTH - 1)
1311c2c66affSColin Finck         {
1312c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, pMachine);
1313c2c66affSColin Finck             return CR_INVALID_MACHINENAME;
1314c2c66affSColin Finck         }
1315c2c66affSColin Finck         lstrcpyW(pMachine->szMachineName, UNCServerName);
1316c2c66affSColin Finck 
1317c2c66affSColin Finck         pMachine->StringTable = pSetupStringTableInitialize();
1318c2c66affSColin Finck         if (pMachine->StringTable == NULL)
1319c2c66affSColin Finck         {
1320c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, pMachine);
1321c2c66affSColin Finck             return CR_FAILURE;
1322c2c66affSColin Finck         }
1323c2c66affSColin Finck 
1324c2c66affSColin Finck         pSetupStringTableAddString(pMachine->StringTable, L"PLT", 1);
1325c2c66affSColin Finck 
1326c2c66affSColin Finck         if (!PnpBindRpc(UNCServerName, &pMachine->BindingHandle))
1327c2c66affSColin Finck         {
1328c2c66affSColin Finck             pSetupStringTableDestroy(pMachine->StringTable);
1329c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, pMachine);
1330c2c66affSColin Finck             return CR_INVALID_MACHINENAME;
1331c2c66affSColin Finck         }
1332c2c66affSColin Finck     }
1333c2c66affSColin Finck 
1334c2c66affSColin Finck     *phMachine = (PHMACHINE)pMachine;
1335c2c66affSColin Finck 
1336c2c66affSColin Finck     return CR_SUCCESS;
1337c2c66affSColin Finck }
1338c2c66affSColin Finck 
1339c2c66affSColin Finck 
1340c2c66affSColin Finck /***********************************************************************
1341c2c66affSColin Finck  * CM_Create_DevNodeA [SETUPAPI.@]
1342c2c66affSColin Finck  */
1343d9a33981SEric Kohl CONFIGRET
1344d9a33981SEric Kohl WINAPI
1345d9a33981SEric Kohl CM_Create_DevNodeA(
1346d9a33981SEric Kohl     _Out_ PDEVINST pdnDevInst,
1347d9a33981SEric Kohl     _In_ DEVINSTID_A pDeviceID,
1348d9a33981SEric Kohl     _In_ DEVINST dnParent,
1349d9a33981SEric Kohl     _In_ ULONG ulFlags)
1350c2c66affSColin Finck {
1351d9a33981SEric Kohl     TRACE("CM_Create_DevNodeA(%p %s %p %lx)\n",
1352c2c66affSColin Finck           pdnDevInst, debugstr_a(pDeviceID), dnParent, ulFlags);
135365d3bf74SEric Kohl 
1354c2c66affSColin Finck     return CM_Create_DevNode_ExA(pdnDevInst, pDeviceID, dnParent,
1355c2c66affSColin Finck                                  ulFlags, NULL);
1356c2c66affSColin Finck }
1357c2c66affSColin Finck 
1358c2c66affSColin Finck 
1359c2c66affSColin Finck /***********************************************************************
1360c2c66affSColin Finck  * CM_Create_DevNodeW [SETUPAPI.@]
1361c2c66affSColin Finck  */
1362d9a33981SEric Kohl CONFIGRET
1363d9a33981SEric Kohl WINAPI
1364d9a33981SEric Kohl CM_Create_DevNodeW(
1365d9a33981SEric Kohl     _Out_ PDEVINST pdnDevInst,
1366d9a33981SEric Kohl     _In_ DEVINSTID_W pDeviceID,
1367d9a33981SEric Kohl     _In_ DEVINST dnParent,
1368d9a33981SEric Kohl     _In_ ULONG ulFlags)
1369c2c66affSColin Finck {
1370d9a33981SEric Kohl     TRACE("CM_Create_DevNodeW(%p %s %p %lx)\n",
1371c2c66affSColin Finck           pdnDevInst, debugstr_w(pDeviceID), dnParent, ulFlags);
137265d3bf74SEric Kohl 
1373c2c66affSColin Finck     return CM_Create_DevNode_ExW(pdnDevInst, pDeviceID, dnParent,
1374c2c66affSColin Finck                                  ulFlags, NULL);
1375c2c66affSColin Finck }
1376c2c66affSColin Finck 
1377c2c66affSColin Finck 
1378c2c66affSColin Finck /***********************************************************************
1379c2c66affSColin Finck  * CM_Create_DevNode_ExA [SETUPAPI.@]
1380c2c66affSColin Finck  */
1381d9a33981SEric Kohl CONFIGRET
1382d9a33981SEric Kohl WINAPI
1383d9a33981SEric Kohl CM_Create_DevNode_ExA(
1384d9a33981SEric Kohl     _Out_ PDEVINST pdnDevInst,
1385d9a33981SEric Kohl     _In_ DEVINSTID_A pDeviceID,
1386d9a33981SEric Kohl     _In_ DEVINST dnParent,
1387d9a33981SEric Kohl     _In_ ULONG ulFlags,
1388d9a33981SEric Kohl     _In_opt_ HANDLE hMachine)
1389c2c66affSColin Finck {
1390c2c66affSColin Finck     DEVINSTID_W pDeviceIDW;
1391c2c66affSColin Finck     CONFIGRET ret;
1392c2c66affSColin Finck 
1393d9a33981SEric Kohl     TRACE("CM_Create_DevNode_ExA(%p %s %p %lx %p)\n",
1394c2c66affSColin Finck           pdnDevInst, debugstr_a(pDeviceID), dnParent, ulFlags, hMachine);
1395c2c66affSColin Finck 
1396c2c66affSColin Finck     if (pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDeviceIDW))
1397c2c66affSColin Finck         return CR_INVALID_DATA;
1398c2c66affSColin Finck 
1399c2c66affSColin Finck     ret = CM_Create_DevNode_ExW(pdnDevInst, pDeviceIDW, dnParent, ulFlags,
1400c2c66affSColin Finck                                 hMachine);
1401c2c66affSColin Finck 
1402c2c66affSColin Finck     MyFree(pDeviceIDW);
1403c2c66affSColin Finck 
1404c2c66affSColin Finck     return ret;
1405c2c66affSColin Finck }
1406c2c66affSColin Finck 
1407c2c66affSColin Finck 
1408c2c66affSColin Finck /***********************************************************************
1409c2c66affSColin Finck  * CM_Create_DevNode_ExW [SETUPAPI.@]
1410c2c66affSColin Finck  */
1411d9a33981SEric Kohl CONFIGRET
1412d9a33981SEric Kohl WINAPI
1413d9a33981SEric Kohl CM_Create_DevNode_ExW(
1414d9a33981SEric Kohl     _Out_ PDEVINST pdnDevInst,
1415d9a33981SEric Kohl     _In_ DEVINSTID_W pDeviceID,
1416d9a33981SEric Kohl     _In_ DEVINST dnParent,
1417d9a33981SEric Kohl     _In_ ULONG ulFlags,
1418d9a33981SEric Kohl     _In_opt_ HANDLE hMachine)
1419c2c66affSColin Finck {
1420c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
1421c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
1422c2c66affSColin Finck     LPWSTR lpParentDevInst;
1423c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
1424c2c66affSColin Finck     WCHAR szLocalDeviceID[MAX_DEVICE_ID_LEN];
1425c2c66affSColin Finck 
1426d9a33981SEric Kohl     TRACE("CM_Create_DevNode_ExW(%p %s %p %lx %p)\n",
1427c2c66affSColin Finck           pdnDevInst, debugstr_w(pDeviceID), dnParent, ulFlags, hMachine);
1428c2c66affSColin Finck 
1429c2c66affSColin Finck     if (!pSetupIsUserAdmin())
1430c2c66affSColin Finck         return CR_ACCESS_DENIED;
1431c2c66affSColin Finck 
1432c2c66affSColin Finck     if (pdnDevInst == NULL)
1433c2c66affSColin Finck         return CR_INVALID_POINTER;
1434c2c66affSColin Finck 
1435c2c66affSColin Finck     if (pDeviceID == NULL || wcslen(pDeviceID) == 0 || wcslen(pDeviceID) >= MAX_DEVICE_ID_LEN)
1436c2c66affSColin Finck         return CR_INVALID_DEVICE_ID;
1437c2c66affSColin Finck 
1438c2c66affSColin Finck     if (dnParent == 0)
1439c2c66affSColin Finck         return CR_INVALID_DEVNODE;
1440c2c66affSColin Finck 
1441c2c66affSColin Finck     if (ulFlags & ~CM_CREATE_DEVNODE_BITS)
1442c2c66affSColin Finck         return CR_INVALID_FLAG;
1443c2c66affSColin Finck 
1444c2c66affSColin Finck     if (hMachine != NULL)
1445c2c66affSColin Finck     {
1446c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1447c2c66affSColin Finck         if (BindingHandle == NULL)
1448c2c66affSColin Finck             return CR_FAILURE;
1449c2c66affSColin Finck 
1450c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1451c2c66affSColin Finck         if (StringTable == 0)
1452c2c66affSColin Finck             return CR_FAILURE;
1453c2c66affSColin Finck     }
1454c2c66affSColin Finck     else
1455c2c66affSColin Finck     {
1456c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1457c2c66affSColin Finck             return CR_FAILURE;
1458c2c66affSColin Finck     }
1459c2c66affSColin Finck 
1460c2c66affSColin Finck     lpParentDevInst = pSetupStringTableStringFromId(StringTable, dnParent);
1461c2c66affSColin Finck     if (lpParentDevInst == NULL)
1462c2c66affSColin Finck         return CR_INVALID_DEVNODE;
1463c2c66affSColin Finck 
1464c2c66affSColin Finck     wcscpy(szLocalDeviceID, pDeviceID);
1465c2c66affSColin Finck 
1466c2c66affSColin Finck     RpcTryExcept
1467c2c66affSColin Finck     {
1468c2c66affSColin Finck         ret = PNP_CreateDevInst(BindingHandle,
1469c2c66affSColin Finck                                 szLocalDeviceID,
1470c2c66affSColin Finck                                 lpParentDevInst,
1471c2c66affSColin Finck                                 MAX_DEVICE_ID_LEN,
1472c2c66affSColin Finck                                 ulFlags);
1473c2c66affSColin Finck     }
1474c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1475c2c66affSColin Finck     {
1476c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
1477c2c66affSColin Finck     }
1478c2c66affSColin Finck     RpcEndExcept;
1479c2c66affSColin Finck 
1480c2c66affSColin Finck     if (ret == CR_SUCCESS)
1481c2c66affSColin Finck     {
1482c2c66affSColin Finck         /* If CM_CREATE_DEVINST_GENERATE_ID was passed in, PNP_CreateDevInst
1483c2c66affSColin Finck          * will return the generated device ID in szLocalDeviceID */
1484c2c66affSColin Finck         *pdnDevInst = pSetupStringTableAddString(StringTable, szLocalDeviceID, 1);
1485c2c66affSColin Finck         if (*pdnDevInst == 0)
1486c2c66affSColin Finck             ret = CR_NO_SUCH_DEVNODE;
1487c2c66affSColin Finck     }
1488c2c66affSColin Finck 
1489c2c66affSColin Finck     return ret;
1490c2c66affSColin Finck }
1491c2c66affSColin Finck 
1492c2c66affSColin Finck 
1493c2c66affSColin Finck /***********************************************************************
1494c2c66affSColin Finck  * CM_Create_Range_List [SETUPAPI.@]
1495c2c66affSColin Finck  */
1496c2c66affSColin Finck CONFIGRET
1497c2c66affSColin Finck WINAPI
1498c2c66affSColin Finck CM_Create_Range_List(
1499c2c66affSColin Finck     _Out_ PRANGE_LIST prlh,
1500c2c66affSColin Finck     _In_ ULONG ulFlags)
1501c2c66affSColin Finck {
15028943354dSSerge Gautherie     PINTERNAL_RANGE_LIST pRangeList;
1503c2c66affSColin Finck 
150465d3bf74SEric Kohl     FIXME("CM_Create_Range_List(%p %lx)\n",
150565d3bf74SEric Kohl           prlh, ulFlags);
1506c2c66affSColin Finck 
1507c2c66affSColin Finck     if (ulFlags != 0)
1508c2c66affSColin Finck         return CR_INVALID_FLAG;
1509c2c66affSColin Finck 
1510c2c66affSColin Finck     if (prlh == NULL)
1511c2c66affSColin Finck         return CR_INVALID_POINTER;
1512c2c66affSColin Finck 
15133ad5c7fdSEric Kohl     /* Allocate the range list */
1514c2c66affSColin Finck     pRangeList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(INTERNAL_RANGE_LIST));
1515c2c66affSColin Finck     if (pRangeList == NULL)
1516c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
1517c2c66affSColin Finck 
15183ad5c7fdSEric Kohl     /* Set the magic value */
1519c2c66affSColin Finck     pRangeList->ulMagic = RANGE_LIST_MAGIC;
1520c2c66affSColin Finck 
15213ad5c7fdSEric Kohl     /* Initialize the mutex for synchonized access */
15223ad5c7fdSEric Kohl     pRangeList->hMutex = CreateMutex(NULL, FALSE, NULL);
15233ad5c7fdSEric Kohl     if (pRangeList->hMutex == NULL)
15243ad5c7fdSEric Kohl     {
15253ad5c7fdSEric Kohl         HeapFree(GetProcessHeap(), 0, pRangeList);
15263ad5c7fdSEric Kohl         return CR_FAILURE;
15273ad5c7fdSEric Kohl     }
15283ad5c7fdSEric Kohl 
15293ad5c7fdSEric Kohl     InitializeListHead(&pRangeList->ListHead);
1530c2c66affSColin Finck 
1531c2c66affSColin Finck     *prlh = (RANGE_LIST)pRangeList;
1532c2c66affSColin Finck 
1533c2c66affSColin Finck     return CR_SUCCESS;
1534c2c66affSColin Finck }
1535c2c66affSColin Finck 
1536c2c66affSColin Finck 
1537c2c66affSColin Finck /***********************************************************************
1538c2c66affSColin Finck  * CM_Delete_Class_Key [SETUPAPI.@]
1539c2c66affSColin Finck  */
1540d9a33981SEric Kohl CONFIGRET
1541d9a33981SEric Kohl WINAPI
1542d9a33981SEric Kohl CM_Delete_Class_Key(
1543d9a33981SEric Kohl     _In_ LPGUID ClassGuid,
1544d9a33981SEric Kohl     _In_ ULONG ulFlags)
1545c2c66affSColin Finck {
1546d9a33981SEric Kohl     TRACE("CM_Delete_Class_Key(%p %lx)\n",
1547d9a33981SEric Kohl           ClassGuid, ulFlags);
154865d3bf74SEric Kohl 
1549c2c66affSColin Finck     return CM_Delete_Class_Key_Ex(ClassGuid, ulFlags, NULL);
1550c2c66affSColin Finck }
1551c2c66affSColin Finck 
1552c2c66affSColin Finck 
1553c2c66affSColin Finck /***********************************************************************
1554c2c66affSColin Finck  * CM_Delete_Class_Key_Ex [SETUPAPI.@]
1555c2c66affSColin Finck  */
1556d9a33981SEric Kohl CONFIGRET
1557d9a33981SEric Kohl WINAPI
1558d9a33981SEric Kohl CM_Delete_Class_Key_Ex(
1559d9a33981SEric Kohl     _In_ LPGUID ClassGuid,
1560d9a33981SEric Kohl     _In_ ULONG ulFlags,
1561d9a33981SEric Kohl     _In_opt_ HANDLE hMachine)
1562c2c66affSColin Finck {
1563c2c66affSColin Finck     WCHAR szGuidString[MAX_GUID_STRING_LEN];
1564c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
1565c2c66affSColin Finck     CONFIGRET ret;
1566c2c66affSColin Finck 
156760a21894SEric Kohl     TRACE("CM_Delete_Class_Key_Ex(%p %lx %p)\n",
1568d9a33981SEric Kohl           ClassGuid, ulFlags, hMachine);
1569c2c66affSColin Finck 
1570c2c66affSColin Finck     if (ClassGuid == NULL)
1571c2c66affSColin Finck         return CR_INVALID_POINTER;
1572c2c66affSColin Finck 
1573c2c66affSColin Finck     if (ulFlags & ~CM_DELETE_CLASS_BITS)
1574c2c66affSColin Finck         return CR_INVALID_FLAG;
1575c2c66affSColin Finck 
1576c2c66affSColin Finck     if (!GuidToString(ClassGuid, szGuidString))
1577c2c66affSColin Finck         return CR_INVALID_DATA;
1578c2c66affSColin Finck 
1579c2c66affSColin Finck     if (hMachine != NULL)
1580c2c66affSColin Finck     {
1581c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1582c2c66affSColin Finck         if (BindingHandle == NULL)
1583c2c66affSColin Finck             return CR_FAILURE;
1584c2c66affSColin Finck     }
1585c2c66affSColin Finck     else
1586c2c66affSColin Finck     {
1587c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
1588c2c66affSColin Finck             return CR_FAILURE;
1589c2c66affSColin Finck     }
1590c2c66affSColin Finck 
1591c2c66affSColin Finck     RpcTryExcept
1592c2c66affSColin Finck     {
1593c2c66affSColin Finck         ret = PNP_DeleteClassKey(BindingHandle,
1594c2c66affSColin Finck                                  szGuidString,
1595c2c66affSColin Finck                                  ulFlags);
1596c2c66affSColin Finck     }
1597c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1598c2c66affSColin Finck     {
1599c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
1600c2c66affSColin Finck     }
1601c2c66affSColin Finck     RpcEndExcept;
1602c2c66affSColin Finck 
1603c2c66affSColin Finck     return ret;
1604c2c66affSColin Finck }
1605c2c66affSColin Finck 
1606c2c66affSColin Finck 
1607c2c66affSColin Finck /***********************************************************************
1608c2c66affSColin Finck  * CM_Delete_DevNode_Key [SETUPAPI.@]
1609c2c66affSColin Finck  */
1610d9a33981SEric Kohl CONFIGRET
1611d9a33981SEric Kohl WINAPI
1612d9a33981SEric Kohl CM_Delete_DevNode_Key(
161393f77f26SEric Kohl     _In_ DEVINST dnDevInst,
1614d9a33981SEric Kohl     _In_ ULONG ulHardwareProfile,
1615d9a33981SEric Kohl     _In_ ULONG ulFlags)
1616c2c66affSColin Finck {
1617d9a33981SEric Kohl     TRACE("CM_Delete_DevNode_Key(%p %lu %lx)\n",
161893f77f26SEric Kohl           dnDevInst, ulHardwareProfile, ulFlags);
161965d3bf74SEric Kohl 
162093f77f26SEric Kohl     return CM_Delete_DevNode_Key_Ex(dnDevInst, ulHardwareProfile, ulFlags,
1621c2c66affSColin Finck                                     NULL);
1622c2c66affSColin Finck }
1623c2c66affSColin Finck 
1624c2c66affSColin Finck 
1625c2c66affSColin Finck /***********************************************************************
1626c2c66affSColin Finck  * CM_Delete_DevNode_Key_Ex [SETUPAPI.@]
1627c2c66affSColin Finck  */
1628d9a33981SEric Kohl CONFIGRET
1629d9a33981SEric Kohl WINAPI
1630d9a33981SEric Kohl CM_Delete_DevNode_Key_Ex(
163193f77f26SEric Kohl     _In_ DEVINST dnDevInst,
1632d9a33981SEric Kohl     _In_ ULONG ulHardwareProfile,
1633d9a33981SEric Kohl     _In_ ULONG ulFlags,
1634d9a33981SEric Kohl     _In_opt_ HANDLE hMachine)
1635c2c66affSColin Finck {
1636433c9d32SEric Kohl     RPC_BINDING_HANDLE BindingHandle = NULL;
1637433c9d32SEric Kohl     HSTRING_TABLE StringTable = NULL;
1638433c9d32SEric Kohl     PWSTR pszDevInst, pszKeyPath = NULL, pszInstancePath = NULL;
1639433c9d32SEric Kohl     CONFIGRET ret;
1640433c9d32SEric Kohl 
1641d9a33981SEric Kohl     FIXME("CM_Delete_DevNode_Key_Ex(%p %lu %lx %p)\n",
164293f77f26SEric Kohl           dnDevInst, ulHardwareProfile, ulFlags, hMachine);
1643c2c66affSColin Finck 
1644433c9d32SEric Kohl     if (dnDevInst == 0)
1645433c9d32SEric Kohl         return CR_INVALID_DEVINST;
1646433c9d32SEric Kohl 
1647433c9d32SEric Kohl     if (ulFlags & ~CM_REGISTRY_BITS)
1648433c9d32SEric Kohl         return CR_INVALID_FLAG;
1649433c9d32SEric Kohl 
1650433c9d32SEric Kohl     if ((ulFlags & CM_REGISTRY_USER) && (ulFlags & CM_REGISTRY_CONFIG))
1651433c9d32SEric Kohl         return CR_INVALID_FLAG;
1652433c9d32SEric Kohl 
1653433c9d32SEric Kohl     if (hMachine != NULL)
1654433c9d32SEric Kohl     {
1655433c9d32SEric Kohl         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1656433c9d32SEric Kohl         if (BindingHandle == NULL)
1657433c9d32SEric Kohl             return CR_FAILURE;
1658433c9d32SEric Kohl 
1659433c9d32SEric Kohl         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1660433c9d32SEric Kohl         if (StringTable == 0)
1661433c9d32SEric Kohl             return CR_FAILURE;
1662433c9d32SEric Kohl     }
1663433c9d32SEric Kohl     else
1664433c9d32SEric Kohl     {
1665433c9d32SEric Kohl         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1666433c9d32SEric Kohl             return CR_FAILURE;
1667433c9d32SEric Kohl     }
1668433c9d32SEric Kohl 
1669433c9d32SEric Kohl     pszDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1670433c9d32SEric Kohl     if (pszDevInst == NULL)
1671433c9d32SEric Kohl         return CR_INVALID_DEVNODE;
1672433c9d32SEric Kohl 
1673433c9d32SEric Kohl     TRACE("pszDevInst: %S\n", pszDevInst);
1674433c9d32SEric Kohl 
1675433c9d32SEric Kohl     pszKeyPath = MyMalloc(512 * sizeof(WCHAR));
1676433c9d32SEric Kohl     if (pszKeyPath == NULL)
1677433c9d32SEric Kohl     {
1678433c9d32SEric Kohl         ret = CR_OUT_OF_MEMORY;
1679433c9d32SEric Kohl         goto done;
1680433c9d32SEric Kohl     }
1681433c9d32SEric Kohl 
1682433c9d32SEric Kohl     pszInstancePath = MyMalloc(512 * sizeof(WCHAR));
1683433c9d32SEric Kohl     if (pszInstancePath == NULL)
1684433c9d32SEric Kohl     {
1685433c9d32SEric Kohl         ret = CR_OUT_OF_MEMORY;
1686433c9d32SEric Kohl         goto done;
1687433c9d32SEric Kohl     }
1688433c9d32SEric Kohl 
1689433c9d32SEric Kohl     ret = GetDeviceInstanceKeyPath(BindingHandle,
1690433c9d32SEric Kohl                                    pszDevInst,
1691433c9d32SEric Kohl                                    pszKeyPath,
1692433c9d32SEric Kohl                                    pszInstancePath,
1693433c9d32SEric Kohl                                    ulHardwareProfile,
1694433c9d32SEric Kohl                                    ulFlags);
1695433c9d32SEric Kohl     if (ret != CR_SUCCESS)
1696433c9d32SEric Kohl         goto done;
1697433c9d32SEric Kohl 
1698433c9d32SEric Kohl     TRACE("pszKeyPath: %S\n", pszKeyPath);
1699433c9d32SEric Kohl     TRACE("pszInstancePath: %S\n", pszInstancePath);
1700433c9d32SEric Kohl 
1701433c9d32SEric Kohl     if (ulFlags & CM_REGISTRY_USER)
1702433c9d32SEric Kohl     {
1703433c9d32SEric Kohl         FIXME("The CM_REGISTRY_USER flag is not supported yet!\n");
1704433c9d32SEric Kohl     }
1705433c9d32SEric Kohl     else
1706433c9d32SEric Kohl     {
1707433c9d32SEric Kohl #if 0
1708433c9d32SEric Kohl         if (!pSetupIsUserAdmin())
1709433c9d32SEric Kohl         {
1710433c9d32SEric Kohl             ret = CR_ACCESS_DENIED;
1711433c9d32SEric Kohl             goto done;
1712433c9d32SEric Kohl         }
1713433c9d32SEric Kohl #endif
1714433c9d32SEric Kohl 
1715433c9d32SEric Kohl         if (!(ulFlags & CM_REGISTRY_CONFIG))
1716433c9d32SEric Kohl             ulHardwareProfile = 0;
1717433c9d32SEric Kohl 
1718433c9d32SEric Kohl         RpcTryExcept
1719433c9d32SEric Kohl         {
1720433c9d32SEric Kohl             ret = PNP_DeleteRegistryKey(BindingHandle,
1721433c9d32SEric Kohl                                         pszDevInst,
1722433c9d32SEric Kohl                                         pszKeyPath,
1723433c9d32SEric Kohl                                         pszInstancePath,
1724433c9d32SEric Kohl                                         ulHardwareProfile);
1725433c9d32SEric Kohl         }
1726433c9d32SEric Kohl         RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1727433c9d32SEric Kohl         {
1728433c9d32SEric Kohl             ret = RpcStatusToCmStatus(RpcExceptionCode());
1729433c9d32SEric Kohl         }
1730433c9d32SEric Kohl         RpcEndExcept;
1731433c9d32SEric Kohl     }
1732433c9d32SEric Kohl 
1733433c9d32SEric Kohl done:
1734433c9d32SEric Kohl     if (pszInstancePath != NULL)
1735433c9d32SEric Kohl         MyFree(pszInstancePath);
1736433c9d32SEric Kohl 
1737433c9d32SEric Kohl     if (pszKeyPath != NULL)
1738433c9d32SEric Kohl         MyFree(pszKeyPath);
1739433c9d32SEric Kohl 
1740433c9d32SEric Kohl     return ret;
1741c2c66affSColin Finck }
1742c2c66affSColin Finck 
1743c2c66affSColin Finck 
1744c2c66affSColin Finck /***********************************************************************
1745c2c66affSColin Finck  * CM_Delete_Range [SETUPAPI.@]
1746c2c66affSColin Finck  */
1747c2c66affSColin Finck CONFIGRET
1748c2c66affSColin Finck WINAPI
1749c2c66affSColin Finck CM_Delete_Range(
1750c2c66affSColin Finck     _In_ DWORDLONG ullStartValue,
1751c2c66affSColin Finck     _In_ DWORDLONG ullEndValue,
1752c2c66affSColin Finck     _In_ RANGE_LIST rlh,
1753c2c66affSColin Finck     _In_ ULONG ulFlags)
1754c2c66affSColin Finck {
1755c2c66affSColin Finck     FIXME("CM_Delete_Range(%I64u %I64u %p %lx)\n",
1756c2c66affSColin Finck           ullStartValue, ullEndValue, rlh, ulFlags);
175765d3bf74SEric Kohl 
1758c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
1759c2c66affSColin Finck }
1760c2c66affSColin Finck 
1761c2c66affSColin Finck 
1762c2c66affSColin Finck /***********************************************************************
17630fbaea84SEric Kohl  * CM_Detect_Resource_Conflict [SETUPAPI.@]
17640fbaea84SEric Kohl  */
17650fbaea84SEric Kohl CONFIGRET
17660fbaea84SEric Kohl WINAPI
17670fbaea84SEric Kohl CM_Detect_Resource_Conflict(
17680fbaea84SEric Kohl     _In_ DEVINST dnDevInst,
17690fbaea84SEric Kohl     _In_ RESOURCEID ResourceID,
17700fbaea84SEric Kohl     _In_reads_bytes_(ResourceLen) PCVOID ResourceData,
17710fbaea84SEric Kohl     _In_ ULONG ResourceLen,
17720fbaea84SEric Kohl     _Out_ PBOOL pbConflictDetected,
17730fbaea84SEric Kohl     _In_ ULONG ulFlags)
17740fbaea84SEric Kohl {
17750fbaea84SEric Kohl     TRACE("CM_Detect_Resource_Conflict(%p %lu %p %lu %p 0x%lx)\n",
17760fbaea84SEric Kohl           dnDevInst, ResourceID, ResourceData, ResourceLen,
17770fbaea84SEric Kohl           pbConflictDetected, ulFlags);
17780fbaea84SEric Kohl 
17790fbaea84SEric Kohl     return CM_Detect_Resource_Conflict_Ex(dnDevInst,
17800fbaea84SEric Kohl                                           ResourceID,
17810fbaea84SEric Kohl                                           ResourceData,
17820fbaea84SEric Kohl                                           ResourceLen,
17830fbaea84SEric Kohl                                           pbConflictDetected,
17840fbaea84SEric Kohl                                           ulFlags,
17850fbaea84SEric Kohl                                           NULL);
17860fbaea84SEric Kohl }
17870fbaea84SEric Kohl 
17880fbaea84SEric Kohl 
17890fbaea84SEric Kohl /***********************************************************************
17900fbaea84SEric Kohl  * CM_Detect_Resource_Conflict_Ex [SETUPAPI.@]
17910fbaea84SEric Kohl  */
17920fbaea84SEric Kohl CONFIGRET
17930fbaea84SEric Kohl WINAPI
17940fbaea84SEric Kohl CM_Detect_Resource_Conflict_Ex(
17950fbaea84SEric Kohl     _In_ DEVINST dnDevInst,
17960fbaea84SEric Kohl     _In_ RESOURCEID ResourceID,
17970fbaea84SEric Kohl     _In_reads_bytes_(ResourceLen) PCVOID ResourceData,
17980fbaea84SEric Kohl     _In_ ULONG ResourceLen,
17990fbaea84SEric Kohl     _Out_ PBOOL pbConflictDetected,
18000fbaea84SEric Kohl     _In_ ULONG ulFlags,
18010fbaea84SEric Kohl     _In_opt_ HMACHINE hMachine)
18020fbaea84SEric Kohl {
18030fbaea84SEric Kohl     FIXME("CM_Detect_Resource_Conflict_Ex(%p %lu %p %lu %p 0x%lx %p)\n",
18040fbaea84SEric Kohl           dnDevInst, ResourceID, ResourceData, ResourceLen,
18050fbaea84SEric Kohl           pbConflictDetected, ulFlags, hMachine);
18060fbaea84SEric Kohl 
18070fbaea84SEric Kohl     return CR_CALL_NOT_IMPLEMENTED;
18080fbaea84SEric Kohl }
18090fbaea84SEric Kohl 
18100fbaea84SEric Kohl 
18110fbaea84SEric Kohl /***********************************************************************
1812c2c66affSColin Finck  * CM_Disable_DevNode [SETUPAPI.@]
1813c2c66affSColin Finck  */
1814c7fc2ef4SEric Kohl CONFIGRET
1815c7fc2ef4SEric Kohl WINAPI
1816c7fc2ef4SEric Kohl CM_Disable_DevNode(
1817c7fc2ef4SEric Kohl     _In_ DEVINST dnDevInst,
1818c7fc2ef4SEric Kohl     _In_ ULONG ulFlags)
1819c2c66affSColin Finck {
1820c7fc2ef4SEric Kohl     TRACE("CM_Disable_DevNode(%p %lx)\n",
1821c7fc2ef4SEric Kohl           dnDevInst, ulFlags);
182265d3bf74SEric Kohl 
1823c2c66affSColin Finck     return CM_Disable_DevNode_Ex(dnDevInst, ulFlags, NULL);
1824c2c66affSColin Finck }
1825c2c66affSColin Finck 
1826c2c66affSColin Finck 
1827c2c66affSColin Finck /***********************************************************************
1828c2c66affSColin Finck  * CM_Disable_DevNode_Ex [SETUPAPI.@]
1829c2c66affSColin Finck  */
1830c7fc2ef4SEric Kohl CONFIGRET
1831c7fc2ef4SEric Kohl WINAPI
1832c7fc2ef4SEric Kohl CM_Disable_DevNode_Ex(
1833c7fc2ef4SEric Kohl     _In_ DEVINST dnDevInst,
1834c7fc2ef4SEric Kohl     _In_ ULONG ulFlags,
1835c7fc2ef4SEric Kohl     _In_opt_ HMACHINE hMachine)
1836c2c66affSColin Finck {
1837c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
1838c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
1839c2c66affSColin Finck     LPWSTR lpDevInst;
1840c2c66affSColin Finck     CONFIGRET ret;
1841c2c66affSColin Finck 
184235cb8f13SHervé Poussineau     TRACE("CM_Disable_DevNode_Ex(%p %lx %p)\n",
1843c7fc2ef4SEric Kohl           dnDevInst, ulFlags, hMachine);
1844c2c66affSColin Finck 
1845c2c66affSColin Finck     if (!pSetupIsUserAdmin())
1846c2c66affSColin Finck         return CR_ACCESS_DENIED;
1847c2c66affSColin Finck 
1848c2c66affSColin Finck     if (dnDevInst == 0)
1849c2c66affSColin Finck         return CR_INVALID_DEVINST;
1850c2c66affSColin Finck 
1851c2c66affSColin Finck     if (ulFlags != 0)
1852c2c66affSColin Finck         return CR_INVALID_FLAG;
1853c2c66affSColin Finck 
1854c2c66affSColin Finck     if (hMachine != NULL)
1855c2c66affSColin Finck     {
1856c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1857c2c66affSColin Finck         if (BindingHandle == NULL)
1858c2c66affSColin Finck             return CR_FAILURE;
1859c2c66affSColin Finck 
1860c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1861c2c66affSColin Finck         if (StringTable == 0)
1862c2c66affSColin Finck             return CR_FAILURE;
1863c2c66affSColin Finck     }
1864c2c66affSColin Finck     else
1865c2c66affSColin Finck     {
1866c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1867c2c66affSColin Finck             return CR_FAILURE;
1868c2c66affSColin Finck     }
1869c2c66affSColin Finck 
1870c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1871c2c66affSColin Finck     if (lpDevInst == NULL)
1872c2c66affSColin Finck         return CR_INVALID_DEVNODE;
1873c2c66affSColin Finck 
1874c2c66affSColin Finck     RpcTryExcept
1875c2c66affSColin Finck     {
18763909ebcfSEric Kohl         ret = PNP_DisableDevInst(BindingHandle,
1877c2c66affSColin Finck                                  lpDevInst,
18783909ebcfSEric Kohl                                  NULL,
18793909ebcfSEric Kohl                                  NULL,
18803909ebcfSEric Kohl                                  0,
18813909ebcfSEric Kohl                                  ulFlags);
1882c2c66affSColin Finck     }
1883c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1884c2c66affSColin Finck     {
1885c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
1886c2c66affSColin Finck     }
1887c2c66affSColin Finck     RpcEndExcept;
1888c2c66affSColin Finck 
1889c2c66affSColin Finck     return ret;
1890c2c66affSColin Finck }
1891c2c66affSColin Finck 
1892c2c66affSColin Finck 
1893c2c66affSColin Finck /***********************************************************************
1894c2c66affSColin Finck  * CM_Disconnect_Machine [SETUPAPI.@]
1895c2c66affSColin Finck  */
1896c7fc2ef4SEric Kohl CONFIGRET
1897c7fc2ef4SEric Kohl WINAPI
1898c7fc2ef4SEric Kohl CM_Disconnect_Machine(
1899c7fc2ef4SEric Kohl     _In_opt_ HMACHINE hMachine)
1900c2c66affSColin Finck {
1901c2c66affSColin Finck     PMACHINE_INFO pMachine;
1902c2c66affSColin Finck 
190360a21894SEric Kohl     TRACE("CM_Disconnect_Machine(%p)\n", hMachine);
1904c2c66affSColin Finck 
1905c2c66affSColin Finck     pMachine = (PMACHINE_INFO)hMachine;
1906c2c66affSColin Finck     if (pMachine == NULL)
1907c2c66affSColin Finck         return CR_SUCCESS;
1908c2c66affSColin Finck 
1909c2c66affSColin Finck     if (pMachine->bLocal == FALSE)
1910c2c66affSColin Finck     {
1911c2c66affSColin Finck         if (pMachine->StringTable != NULL)
1912c2c66affSColin Finck             pSetupStringTableDestroy(pMachine->StringTable);
1913c2c66affSColin Finck 
1914c2c66affSColin Finck         if (!PnpUnbindRpc(pMachine->BindingHandle))
1915c2c66affSColin Finck             return CR_ACCESS_DENIED;
1916c2c66affSColin Finck     }
1917c2c66affSColin Finck 
1918c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, pMachine);
1919c2c66affSColin Finck 
1920c2c66affSColin Finck     return CR_SUCCESS;
1921c2c66affSColin Finck }
1922c2c66affSColin Finck 
1923c2c66affSColin Finck 
1924c2c66affSColin Finck /***********************************************************************
1925c2c66affSColin Finck  * CM_Dup_Range_List [SETUPAPI.@]
1926c2c66affSColin Finck  */
1927c2c66affSColin Finck CONFIGRET
1928c2c66affSColin Finck WINAPI
1929c2c66affSColin Finck CM_Dup_Range_List(
1930c2c66affSColin Finck     _In_ RANGE_LIST rlhOld,
1931c2c66affSColin Finck     _In_ RANGE_LIST rlhNew,
1932c2c66affSColin Finck     _In_ ULONG ulFlags)
1933c2c66affSColin Finck {
1934f24fbb65SEric Kohl     PINTERNAL_RANGE_LIST pOldRangeList, pNewRangeList;
1935f24fbb65SEric Kohl     PINTERNAL_RANGE pOldRange, pNewRange;
1936f24fbb65SEric Kohl     PLIST_ENTRY ListEntry;
1937f24fbb65SEric Kohl     CONFIGRET ret = CR_SUCCESS;
1938f24fbb65SEric Kohl 
1939c2c66affSColin Finck     FIXME("CM_Dup_Range_List(%p %p %lx)\n",
1940c2c66affSColin Finck           rlhOld, rlhNew, ulFlags);
194165d3bf74SEric Kohl 
1942f24fbb65SEric Kohl     pOldRangeList = (PINTERNAL_RANGE_LIST)rlhOld;
1943f24fbb65SEric Kohl     pNewRangeList = (PINTERNAL_RANGE_LIST)rlhNew;
1944f24fbb65SEric Kohl 
1945f24fbb65SEric Kohl     if (!IsValidRangeList(pOldRangeList))
1946f24fbb65SEric Kohl         return CR_INVALID_RANGE_LIST;
1947f24fbb65SEric Kohl 
1948f24fbb65SEric Kohl     if (!IsValidRangeList(pNewRangeList))
1949f24fbb65SEric Kohl         return CR_INVALID_RANGE_LIST;
1950f24fbb65SEric Kohl 
1951f24fbb65SEric Kohl     if (ulFlags != 0)
1952f24fbb65SEric Kohl         return CR_INVALID_FLAG;
1953f24fbb65SEric Kohl 
1954f24fbb65SEric Kohl     /* Lock the range lists */
1955f24fbb65SEric Kohl     WaitForSingleObject(pOldRangeList->hMutex, INFINITE);
1956f24fbb65SEric Kohl     WaitForSingleObject(pNewRangeList->hMutex, INFINITE);
1957f24fbb65SEric Kohl 
1958f24fbb65SEric Kohl     /* Delete the new range list, if ist is not empty */
1959f24fbb65SEric Kohl     while (!IsListEmpty(&pNewRangeList->ListHead))
1960f24fbb65SEric Kohl     {
1961f24fbb65SEric Kohl         ListEntry = RemoveHeadList(&pNewRangeList->ListHead);
1962f24fbb65SEric Kohl         pNewRange = CONTAINING_RECORD(ListEntry, INTERNAL_RANGE, ListEntry);
1963f24fbb65SEric Kohl         HeapFree(GetProcessHeap(), 0, pNewRange);
1964f24fbb65SEric Kohl     }
1965f24fbb65SEric Kohl 
1966f24fbb65SEric Kohl     /* Copy the old range list into the new range list */
1967f24fbb65SEric Kohl     ListEntry = &pOldRangeList->ListHead;
1968f24fbb65SEric Kohl     while (ListEntry->Flink == &pOldRangeList->ListHead)
1969f24fbb65SEric Kohl     {
1970f24fbb65SEric Kohl         pOldRange = CONTAINING_RECORD(ListEntry, INTERNAL_RANGE, ListEntry);
1971f24fbb65SEric Kohl 
1972f24fbb65SEric Kohl         pNewRange = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNAL_RANGE));
1973f24fbb65SEric Kohl         if (pNewRange == NULL)
1974f24fbb65SEric Kohl         {
1975f24fbb65SEric Kohl             ret = CR_OUT_OF_MEMORY;
1976f24fbb65SEric Kohl             goto done;
1977f24fbb65SEric Kohl         }
1978f24fbb65SEric Kohl 
1979f24fbb65SEric Kohl         pNewRange->pRangeList = pNewRangeList;
1980f24fbb65SEric Kohl         pNewRange->ullStart = pOldRange->ullStart;
1981f24fbb65SEric Kohl         pNewRange->ullEnd = pOldRange->ullEnd;
1982f24fbb65SEric Kohl 
1983f24fbb65SEric Kohl         InsertTailList(&pNewRangeList->ListHead, &pNewRange->ListEntry);
1984f24fbb65SEric Kohl 
1985f24fbb65SEric Kohl         ListEntry = ListEntry->Flink;
1986f24fbb65SEric Kohl     }
1987f24fbb65SEric Kohl 
1988f24fbb65SEric Kohl done:
1989f24fbb65SEric Kohl     /* Unlock the range lists */
1990f24fbb65SEric Kohl     ReleaseMutex(pNewRangeList->hMutex);
1991f24fbb65SEric Kohl     ReleaseMutex(pOldRangeList->hMutex);
1992f24fbb65SEric Kohl 
1993f24fbb65SEric Kohl     return ret;
1994c2c66affSColin Finck }
1995c2c66affSColin Finck 
1996c2c66affSColin Finck 
1997c2c66affSColin Finck /***********************************************************************
1998c2c66affSColin Finck  * CM_Enable_DevNode [SETUPAPI.@]
1999c2c66affSColin Finck  */
2000c7fc2ef4SEric Kohl CONFIGRET
2001c7fc2ef4SEric Kohl WINAPI
2002c7fc2ef4SEric Kohl CM_Enable_DevNode(
2003c7fc2ef4SEric Kohl     _In_ DEVINST dnDevInst,
2004c7fc2ef4SEric Kohl     _In_ ULONG ulFlags)
2005c2c66affSColin Finck {
200665d3bf74SEric Kohl     TRACE("CM_Enable_DevNode(%p %lx)\n",
200765d3bf74SEric Kohl           dnDevInst, ulFlags);
200865d3bf74SEric Kohl 
2009c2c66affSColin Finck     return CM_Enable_DevNode_Ex(dnDevInst, ulFlags, NULL);
2010c2c66affSColin Finck }
2011c2c66affSColin Finck 
2012c2c66affSColin Finck 
2013c2c66affSColin Finck /***********************************************************************
2014c2c66affSColin Finck  * CM_Enable_DevNode_Ex [SETUPAPI.@]
2015c2c66affSColin Finck  */
2016c7fc2ef4SEric Kohl CONFIGRET
2017c7fc2ef4SEric Kohl WINAPI
2018c7fc2ef4SEric Kohl CM_Enable_DevNode_Ex(
2019c7fc2ef4SEric Kohl     _In_ DEVINST dnDevInst,
2020c7fc2ef4SEric Kohl     _In_ ULONG ulFlags,
2021c7fc2ef4SEric Kohl     _In_opt_ HMACHINE hMachine)
2022c2c66affSColin Finck {
2023c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
2024c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
2025c2c66affSColin Finck     LPWSTR lpDevInst;
2026c2c66affSColin Finck     CONFIGRET ret;
2027c2c66affSColin Finck 
202865d3bf74SEric Kohl     TRACE("CM_Enable_DevNode_Ex(%p %lx %p)\n",
202965d3bf74SEric Kohl           dnDevInst, ulFlags, hMachine);
2030c2c66affSColin Finck 
2031c2c66affSColin Finck     if (!pSetupIsUserAdmin())
2032c2c66affSColin Finck         return CR_ACCESS_DENIED;
2033c2c66affSColin Finck 
2034c2c66affSColin Finck     if (dnDevInst == 0)
2035c2c66affSColin Finck         return CR_INVALID_DEVINST;
2036c2c66affSColin Finck 
2037c2c66affSColin Finck     if (ulFlags != 0)
2038c2c66affSColin Finck         return CR_INVALID_FLAG;
2039c2c66affSColin Finck 
2040c2c66affSColin Finck     if (hMachine != NULL)
2041c2c66affSColin Finck     {
2042c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2043c2c66affSColin Finck         if (BindingHandle == NULL)
2044c2c66affSColin Finck             return CR_FAILURE;
2045c2c66affSColin Finck 
2046c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2047c2c66affSColin Finck         if (StringTable == 0)
2048c2c66affSColin Finck             return CR_FAILURE;
2049c2c66affSColin Finck     }
2050c2c66affSColin Finck     else
2051c2c66affSColin Finck     {
2052c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2053c2c66affSColin Finck             return CR_FAILURE;
2054c2c66affSColin Finck     }
2055c2c66affSColin Finck 
2056c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2057c2c66affSColin Finck     if (lpDevInst == NULL)
2058c2c66affSColin Finck         return CR_INVALID_DEVNODE;
2059c2c66affSColin Finck 
2060c2c66affSColin Finck     RpcTryExcept
2061c2c66affSColin Finck     {
2062c2c66affSColin Finck         ret = PNP_DeviceInstanceAction(BindingHandle,
2063c2c66affSColin Finck                                        PNP_DEVINST_ENABLE,
2064c2c66affSColin Finck                                        ulFlags,
2065c2c66affSColin Finck                                        lpDevInst,
2066c2c66affSColin Finck                                        NULL);
2067c2c66affSColin Finck     }
2068c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2069c2c66affSColin Finck     {
2070c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2071c2c66affSColin Finck     }
2072c2c66affSColin Finck     RpcEndExcept;
2073c2c66affSColin Finck 
2074c2c66affSColin Finck     return ret;
2075c2c66affSColin Finck }
2076c2c66affSColin Finck 
2077c2c66affSColin Finck 
2078c2c66affSColin Finck /***********************************************************************
2079c2c66affSColin Finck  * CM_Enumerate_Classes [SETUPAPI.@]
2080c2c66affSColin Finck  */
2081c7fc2ef4SEric Kohl CONFIGRET
2082c7fc2ef4SEric Kohl WINAPI
2083c7fc2ef4SEric Kohl CM_Enumerate_Classes(
2084c7fc2ef4SEric Kohl     _In_ ULONG ulClassIndex,
2085c7fc2ef4SEric Kohl     _Out_ LPGUID ClassGuid,
2086c7fc2ef4SEric Kohl     _In_ ULONG ulFlags)
2087c2c66affSColin Finck {
2088c7fc2ef4SEric Kohl     TRACE("CM_Enumerate_Classes(%lx %p %lx)\n",
2089c7fc2ef4SEric Kohl           ulClassIndex, ClassGuid, ulFlags);
2090c7fc2ef4SEric Kohl 
2091c2c66affSColin Finck     return CM_Enumerate_Classes_Ex(ulClassIndex, ClassGuid, ulFlags, NULL);
2092c2c66affSColin Finck }
2093c2c66affSColin Finck 
2094c2c66affSColin Finck 
2095c2c66affSColin Finck /***********************************************************************
2096c2c66affSColin Finck  * CM_Enumerate_Classes_Ex [SETUPAPI.@]
2097c2c66affSColin Finck  */
2098c7fc2ef4SEric Kohl CONFIGRET
2099c7fc2ef4SEric Kohl WINAPI
2100c7fc2ef4SEric Kohl CM_Enumerate_Classes_Ex(
2101c7fc2ef4SEric Kohl     _In_ ULONG ulClassIndex,
2102c7fc2ef4SEric Kohl     _Out_ LPGUID ClassGuid,
2103c7fc2ef4SEric Kohl     _In_ ULONG ulFlags,
2104c7fc2ef4SEric Kohl     _In_opt_ HMACHINE hMachine)
2105c2c66affSColin Finck {
2106c2c66affSColin Finck     WCHAR szBuffer[MAX_GUID_STRING_LEN];
2107c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
2108c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
2109c2c66affSColin Finck     ULONG ulLength = MAX_GUID_STRING_LEN;
2110c2c66affSColin Finck 
2111c7fc2ef4SEric Kohl     TRACE("CM_Enumerate_Classes_Ex(%lx %p %lx %p)\n",
2112c7fc2ef4SEric Kohl           ulClassIndex, ClassGuid, ulFlags, hMachine);
2113c2c66affSColin Finck 
2114c2c66affSColin Finck     if (ClassGuid == NULL)
2115c2c66affSColin Finck         return CR_INVALID_POINTER;
2116c2c66affSColin Finck 
2117c2c66affSColin Finck     if (ulFlags != 0)
2118c2c66affSColin Finck         return CR_INVALID_FLAG;
2119c2c66affSColin Finck 
2120c2c66affSColin Finck     if (hMachine != NULL)
2121c2c66affSColin Finck     {
2122c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2123c2c66affSColin Finck         if (BindingHandle == NULL)
2124c2c66affSColin Finck             return CR_FAILURE;
2125c2c66affSColin Finck     }
2126c2c66affSColin Finck     else
2127c2c66affSColin Finck     {
2128c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
2129c2c66affSColin Finck             return CR_FAILURE;
2130c2c66affSColin Finck     }
2131c2c66affSColin Finck 
2132c2c66affSColin Finck     RpcTryExcept
2133c2c66affSColin Finck     {
2134c2c66affSColin Finck         ret = PNP_EnumerateSubKeys(BindingHandle,
2135c2c66affSColin Finck                                    PNP_CLASS_SUBKEYS,
2136c2c66affSColin Finck                                    ulClassIndex,
2137c2c66affSColin Finck                                    szBuffer,
2138c2c66affSColin Finck                                    MAX_GUID_STRING_LEN,
2139c2c66affSColin Finck                                    &ulLength,
2140c2c66affSColin Finck                                    ulFlags);
2141c2c66affSColin Finck     }
2142c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2143c2c66affSColin Finck     {
2144c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2145c2c66affSColin Finck     }
2146c2c66affSColin Finck     RpcEndExcept;
2147c2c66affSColin Finck 
2148c2c66affSColin Finck     if (ret == CR_SUCCESS)
2149c2c66affSColin Finck     {
2150c2c66affSColin Finck         /* Remove the {} */
2151c2c66affSColin Finck         szBuffer[MAX_GUID_STRING_LEN - 2] = UNICODE_NULL;
2152c2c66affSColin Finck 
2153c2c66affSColin Finck         /* Convert the buffer to a GUID */
2154c2c66affSColin Finck         if (UuidFromStringW(&szBuffer[1], ClassGuid) != RPC_S_OK)
2155c2c66affSColin Finck             return CR_FAILURE;
2156c2c66affSColin Finck     }
2157c2c66affSColin Finck 
2158c2c66affSColin Finck     return ret;
2159c2c66affSColin Finck }
2160c2c66affSColin Finck 
2161c2c66affSColin Finck 
2162c2c66affSColin Finck /***********************************************************************
2163c2c66affSColin Finck  * CM_Enumerate_EnumeratorsA [SETUPAPI.@]
2164c2c66affSColin Finck  */
2165c7fc2ef4SEric Kohl CONFIGRET
2166c7fc2ef4SEric Kohl WINAPI
2167c7fc2ef4SEric Kohl CM_Enumerate_EnumeratorsA(
2168c7fc2ef4SEric Kohl     _In_ ULONG ulEnumIndex,
216965d3bf74SEric Kohl     _Out_writes_(*pulLength) PCHAR Buffer,
2170c7fc2ef4SEric Kohl     _Inout_ PULONG pulLength,
2171c7fc2ef4SEric Kohl     _In_ ULONG ulFlags)
2172c2c66affSColin Finck {
2173c7fc2ef4SEric Kohl     TRACE("CM_Enumerate_EnumeratorsA(%lu %p %p %lx)\n",
2174c7fc2ef4SEric Kohl           ulEnumIndex, Buffer, pulLength, ulFlags);
2175c7fc2ef4SEric Kohl 
2176c2c66affSColin Finck     return CM_Enumerate_Enumerators_ExA(ulEnumIndex, Buffer, pulLength,
2177c2c66affSColin Finck                                         ulFlags, NULL);
2178c2c66affSColin Finck }
2179c2c66affSColin Finck 
2180c2c66affSColin Finck 
2181c2c66affSColin Finck /***********************************************************************
2182c2c66affSColin Finck  * CM_Enumerate_EnumeratorsW [SETUPAPI.@]
2183c2c66affSColin Finck  */
2184c7fc2ef4SEric Kohl CONFIGRET
2185c7fc2ef4SEric Kohl WINAPI
2186c7fc2ef4SEric Kohl CM_Enumerate_EnumeratorsW(
2187c7fc2ef4SEric Kohl     _In_ ULONG ulEnumIndex,
218865d3bf74SEric Kohl     _Out_writes_(*pulLength) PWCHAR Buffer,
2189c7fc2ef4SEric Kohl     _Inout_ PULONG pulLength,
2190c7fc2ef4SEric Kohl     _In_ ULONG ulFlags)
2191c2c66affSColin Finck {
2192c7fc2ef4SEric Kohl     TRACE("CM_Enumerate_EnumeratorsW(%lu %p %p %lx)\n",
2193c7fc2ef4SEric Kohl           ulEnumIndex, Buffer, pulLength, ulFlags);
2194c7fc2ef4SEric Kohl 
2195c2c66affSColin Finck     return CM_Enumerate_Enumerators_ExW(ulEnumIndex, Buffer, pulLength,
2196c2c66affSColin Finck                                         ulFlags, NULL);
2197c2c66affSColin Finck }
2198c2c66affSColin Finck 
2199c2c66affSColin Finck 
2200c2c66affSColin Finck /***********************************************************************
2201c2c66affSColin Finck  * CM_Enumerate_Enumerators_ExA [SETUPAPI.@]
2202c2c66affSColin Finck  */
2203c7fc2ef4SEric Kohl CONFIGRET
2204c7fc2ef4SEric Kohl WINAPI
2205c7fc2ef4SEric Kohl CM_Enumerate_Enumerators_ExA(
2206c7fc2ef4SEric Kohl     _In_ ULONG ulEnumIndex,
220765d3bf74SEric Kohl     _Out_writes_(*pulLength) PCHAR Buffer,
2208c7fc2ef4SEric Kohl     _Inout_ PULONG pulLength,
2209c7fc2ef4SEric Kohl     _In_ ULONG ulFlags,
2210c7fc2ef4SEric Kohl     _In_opt_ HMACHINE hMachine)
2211c2c66affSColin Finck {
2212c2c66affSColin Finck     WCHAR szBuffer[MAX_DEVICE_ID_LEN];
2213c2c66affSColin Finck     ULONG ulOrigLength;
2214c2c66affSColin Finck     ULONG ulLength;
2215c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
2216c2c66affSColin Finck 
221760a21894SEric Kohl     TRACE("CM_Enumerate_Enumerators_ExA(%lu %p %p %lx %p)\n",
2218c7fc2ef4SEric Kohl           ulEnumIndex, Buffer, pulLength, ulFlags, hMachine);
2219c2c66affSColin Finck 
2220c2c66affSColin Finck     if (Buffer == NULL || pulLength == NULL)
2221c2c66affSColin Finck         return CR_INVALID_POINTER;
2222c2c66affSColin Finck 
2223c2c66affSColin Finck     if (ulFlags != 0)
2224c2c66affSColin Finck         return CR_INVALID_FLAG;
2225c2c66affSColin Finck 
2226c2c66affSColin Finck     ulOrigLength = *pulLength;
2227c2c66affSColin Finck     *pulLength = 0;
2228c2c66affSColin Finck 
2229c2c66affSColin Finck     ulLength = MAX_DEVICE_ID_LEN;
2230c2c66affSColin Finck     ret = CM_Enumerate_Enumerators_ExW(ulEnumIndex, szBuffer, &ulLength,
2231c2c66affSColin Finck                                        ulFlags, hMachine);
2232c2c66affSColin Finck     if (ret == CR_SUCCESS)
2233c2c66affSColin Finck     {
2234c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
2235c2c66affSColin Finck                                 0,
2236c2c66affSColin Finck                                 szBuffer,
2237c2c66affSColin Finck                                 ulLength,
2238c2c66affSColin Finck                                 Buffer,
2239c2c66affSColin Finck                                 ulOrigLength,
2240c2c66affSColin Finck                                 NULL,
2241c2c66affSColin Finck                                 NULL) == 0)
2242c2c66affSColin Finck             ret = CR_FAILURE;
2243c2c66affSColin Finck         else
2244c2c66affSColin Finck             *pulLength = lstrlenA(Buffer) + 1;
2245c2c66affSColin Finck     }
2246c2c66affSColin Finck 
2247c2c66affSColin Finck     return ret;
2248c2c66affSColin Finck }
2249c2c66affSColin Finck 
2250c2c66affSColin Finck 
2251c2c66affSColin Finck /***********************************************************************
2252c2c66affSColin Finck  * CM_Enumerate_Enumerators_ExW [SETUPAPI.@]
2253c2c66affSColin Finck  */
2254c7fc2ef4SEric Kohl CONFIGRET
2255c7fc2ef4SEric Kohl WINAPI
2256c7fc2ef4SEric Kohl CM_Enumerate_Enumerators_ExW(
2257c7fc2ef4SEric Kohl     _In_ ULONG ulEnumIndex,
225865d3bf74SEric Kohl     _Out_writes_(*pulLength) PWCHAR Buffer,
2259c7fc2ef4SEric Kohl     _Inout_ PULONG pulLength,
2260c7fc2ef4SEric Kohl     _In_ ULONG ulFlags,
2261c7fc2ef4SEric Kohl     _In_opt_ HMACHINE hMachine)
2262c2c66affSColin Finck {
2263c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
2264c2c66affSColin Finck     CONFIGRET ret;
2265c2c66affSColin Finck 
226660a21894SEric Kohl     TRACE("CM_Enumerate_Enumerators_ExW(%lu %p %p %lx %p)\n",
2267c7fc2ef4SEric Kohl           ulEnumIndex, Buffer, pulLength, ulFlags, hMachine);
2268c2c66affSColin Finck 
2269c2c66affSColin Finck     if (Buffer == NULL || pulLength == NULL)
2270c2c66affSColin Finck         return CR_INVALID_POINTER;
2271c2c66affSColin Finck 
2272c2c66affSColin Finck     if (ulFlags != 0)
2273c2c66affSColin Finck         return CR_INVALID_FLAG;
2274c2c66affSColin Finck 
2275c2c66affSColin Finck     *Buffer = UNICODE_NULL;
2276c2c66affSColin Finck 
2277c2c66affSColin Finck     if (hMachine != NULL)
2278c2c66affSColin Finck     {
2279c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2280c2c66affSColin Finck         if (BindingHandle == NULL)
2281c2c66affSColin Finck             return CR_FAILURE;
2282c2c66affSColin Finck     }
2283c2c66affSColin Finck     else
2284c2c66affSColin Finck     {
2285c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
2286c2c66affSColin Finck             return CR_FAILURE;
2287c2c66affSColin Finck     }
2288c2c66affSColin Finck 
2289c2c66affSColin Finck     RpcTryExcept
2290c2c66affSColin Finck     {
2291c2c66affSColin Finck         ret = PNP_EnumerateSubKeys(BindingHandle,
2292c2c66affSColin Finck                                    PNP_ENUMERATOR_SUBKEYS,
2293c2c66affSColin Finck                                    ulEnumIndex,
2294c2c66affSColin Finck                                    Buffer,
2295c2c66affSColin Finck                                    *pulLength,
2296c2c66affSColin Finck                                    pulLength,
2297c2c66affSColin Finck                                    ulFlags);
2298c2c66affSColin Finck     }
2299c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2300c2c66affSColin Finck     {
2301c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2302c2c66affSColin Finck     }
2303c2c66affSColin Finck     RpcEndExcept;
2304c2c66affSColin Finck 
2305c2c66affSColin Finck     return ret;
2306c2c66affSColin Finck }
2307c2c66affSColin Finck 
2308c2c66affSColin Finck 
2309c2c66affSColin Finck /***********************************************************************
2310c2c66affSColin Finck  * CM_Find_Range [SETUPAPI.@]
2311c2c66affSColin Finck  */
2312c2c66affSColin Finck CONFIGRET
2313c2c66affSColin Finck WINAPI
2314c2c66affSColin Finck CM_Find_Range(
2315c2c66affSColin Finck     _Out_ PDWORDLONG pullStart,
2316c2c66affSColin Finck     _In_ DWORDLONG ullStart,
2317c2c66affSColin Finck     _In_ ULONG ulLength,
2318c2c66affSColin Finck     _In_ DWORDLONG ullAlignment,
2319c2c66affSColin Finck     _In_ DWORDLONG ullEnd,
2320c2c66affSColin Finck     _In_ RANGE_LIST rlh,
2321c2c66affSColin Finck     _In_ ULONG ulFlags)
2322c2c66affSColin Finck {
2323c2c66affSColin Finck     FIXME("CM_Find_Range(%p %I64u %lu %I64u %I64u %p %lx)\n",
2324c2c66affSColin Finck           pullStart, ullStart, ulLength, ullAlignment, ullEnd, rlh, ulFlags);
232565d3bf74SEric Kohl 
2326c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
2327c2c66affSColin Finck }
2328c2c66affSColin Finck 
2329c2c66affSColin Finck 
2330c2c66affSColin Finck /***********************************************************************
2331c2c66affSColin Finck  * CM_First_Range [SETUPAPI.@]
2332c2c66affSColin Finck  */
2333c2c66affSColin Finck CONFIGRET
2334c2c66affSColin Finck WINAPI
2335c2c66affSColin Finck CM_First_Range(
2336c2c66affSColin Finck     _In_ RANGE_LIST rlh,
2337c2c66affSColin Finck     _Out_ PDWORDLONG pullStart,
2338c2c66affSColin Finck     _Out_ PDWORDLONG pullEnd,
2339c2c66affSColin Finck     _Out_ PRANGE_ELEMENT preElement,
2340c2c66affSColin Finck     _In_ ULONG ulFlags)
2341c2c66affSColin Finck {
23423ad5c7fdSEric Kohl     PINTERNAL_RANGE_LIST pRangeList;
23433ad5c7fdSEric Kohl     PINTERNAL_RANGE pRange;
23443ad5c7fdSEric Kohl     PLIST_ENTRY ListEntry;
23453ad5c7fdSEric Kohl     CONFIGRET ret = CR_SUCCESS;
23463ad5c7fdSEric Kohl 
2347c2c66affSColin Finck     FIXME("CM_First_Range(%p %p %p %p %lx)\n",
2348c2c66affSColin Finck           rlh, pullStart, pullEnd, preElement, ulFlags);
23493ad5c7fdSEric Kohl 
23503ad5c7fdSEric Kohl     pRangeList = (PINTERNAL_RANGE_LIST)rlh;
23513ad5c7fdSEric Kohl 
23523ad5c7fdSEric Kohl     if (!IsValidRangeList(pRangeList))
23533ad5c7fdSEric Kohl         return CR_INVALID_RANGE_LIST;
23543ad5c7fdSEric Kohl 
23553ad5c7fdSEric Kohl     if (pullStart == NULL || pullEnd == NULL || preElement == NULL)
23563ad5c7fdSEric Kohl         return CR_INVALID_POINTER;
23573ad5c7fdSEric Kohl 
23583ad5c7fdSEric Kohl     if (ulFlags != 0)
23593ad5c7fdSEric Kohl         return CR_INVALID_FLAG;
23603ad5c7fdSEric Kohl 
23613ad5c7fdSEric Kohl     /* Lock the range list */
23623ad5c7fdSEric Kohl     WaitForSingleObject(pRangeList->hMutex, INFINITE);
23633ad5c7fdSEric Kohl 
23643ad5c7fdSEric Kohl     /* Fail, if the list is empty */
23653ad5c7fdSEric Kohl     if (IsListEmpty(&pRangeList->ListHead))
23663ad5c7fdSEric Kohl     {
23673ad5c7fdSEric Kohl         ret = CR_FAILURE;
23683ad5c7fdSEric Kohl         goto done;
23693ad5c7fdSEric Kohl     }
23703ad5c7fdSEric Kohl 
23713ad5c7fdSEric Kohl     /* Get the first range */
23723ad5c7fdSEric Kohl     ListEntry = pRangeList->ListHead.Flink;
23733ad5c7fdSEric Kohl     pRange = CONTAINING_RECORD(ListEntry, INTERNAL_RANGE, ListEntry);
23743ad5c7fdSEric Kohl 
23753ad5c7fdSEric Kohl     /* Return the range data */
23763ad5c7fdSEric Kohl     *pullStart = pRange->ullStart;
23773ad5c7fdSEric Kohl     *pullEnd = pRange->ullEnd;
23783ad5c7fdSEric Kohl     *preElement = (RANGE_ELEMENT)pRange;
23793ad5c7fdSEric Kohl 
23803ad5c7fdSEric Kohl done:
23813ad5c7fdSEric Kohl     /* Unlock the range list */
23823ad5c7fdSEric Kohl     ReleaseMutex(pRangeList->hMutex);
23833ad5c7fdSEric Kohl 
23843ad5c7fdSEric Kohl     return ret;
2385c2c66affSColin Finck }
2386c2c66affSColin Finck 
2387c2c66affSColin Finck 
2388c2c66affSColin Finck /***********************************************************************
2389c2c66affSColin Finck  * CM_Free_Log_Conf [SETUPAPI.@]
2390c2c66affSColin Finck  */
2391c7fc2ef4SEric Kohl CONFIGRET
2392c7fc2ef4SEric Kohl WINAPI
2393c7fc2ef4SEric Kohl CM_Free_Log_Conf(
2394c7fc2ef4SEric Kohl     _In_ LOG_CONF lcLogConfToBeFreed,
2395c7fc2ef4SEric Kohl     _In_ ULONG ulFlags)
2396c2c66affSColin Finck {
2397c7fc2ef4SEric Kohl     TRACE("CM_Free_Log_Conf(%lx %lx)\n",
2398c7fc2ef4SEric Kohl           lcLogConfToBeFreed, ulFlags);
2399c7fc2ef4SEric Kohl 
2400c2c66affSColin Finck     return CM_Free_Log_Conf_Ex(lcLogConfToBeFreed, ulFlags, NULL);
2401c2c66affSColin Finck }
2402c2c66affSColin Finck 
2403c2c66affSColin Finck 
2404c2c66affSColin Finck /***********************************************************************
2405c2c66affSColin Finck  * CM_Free_Log_Conf_Ex [SETUPAPI.@]
2406c2c66affSColin Finck  */
2407c7fc2ef4SEric Kohl CONFIGRET
2408c7fc2ef4SEric Kohl WINAPI
2409c7fc2ef4SEric Kohl CM_Free_Log_Conf_Ex(
2410c7fc2ef4SEric Kohl     _In_ LOG_CONF lcLogConfToBeFreed,
2411c7fc2ef4SEric Kohl     _In_ ULONG ulFlags,
2412c7fc2ef4SEric Kohl     _In_opt_ HMACHINE hMachine)
2413c2c66affSColin Finck {
2414c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
2415c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
2416c2c66affSColin Finck     LPWSTR lpDevInst;
2417c2c66affSColin Finck     PLOG_CONF_INFO pLogConfInfo;
2418c2c66affSColin Finck     CONFIGRET ret;
2419c2c66affSColin Finck 
242060a21894SEric Kohl     TRACE("CM_Free_Log_Conf_Ex(%lx %lx %p)\n",
2421c7fc2ef4SEric Kohl           lcLogConfToBeFreed, ulFlags, hMachine);
2422c2c66affSColin Finck 
2423c2c66affSColin Finck     if (!pSetupIsUserAdmin())
2424c2c66affSColin Finck         return CR_ACCESS_DENIED;
2425c2c66affSColin Finck 
2426c2c66affSColin Finck     pLogConfInfo = (PLOG_CONF_INFO)lcLogConfToBeFreed;
242719fc20f2SEric Kohl     if (!IsValidLogConf(pLogConfInfo))
2428c2c66affSColin Finck         return CR_INVALID_LOG_CONF;
2429c2c66affSColin Finck 
2430c2c66affSColin Finck     if (ulFlags != 0)
2431c2c66affSColin Finck         return CR_INVALID_FLAG;
2432c2c66affSColin Finck 
2433c2c66affSColin Finck     if (hMachine != NULL)
2434c2c66affSColin Finck     {
2435c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2436c2c66affSColin Finck         if (BindingHandle == NULL)
2437c2c66affSColin Finck             return CR_FAILURE;
2438c2c66affSColin Finck 
2439c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2440c2c66affSColin Finck         if (StringTable == 0)
2441c2c66affSColin Finck             return CR_FAILURE;
2442c2c66affSColin Finck     }
2443c2c66affSColin Finck     else
2444c2c66affSColin Finck     {
2445c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2446c2c66affSColin Finck             return CR_FAILURE;
2447c2c66affSColin Finck     }
2448c2c66affSColin Finck 
2449c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
2450c2c66affSColin Finck     if (lpDevInst == NULL)
2451c2c66affSColin Finck         return CR_INVALID_DEVNODE;
2452c2c66affSColin Finck 
2453c2c66affSColin Finck     RpcTryExcept
2454c2c66affSColin Finck     {
24556efb3cbeSEric Kohl         ret = PNP_FreeLogConf(BindingHandle,
24566efb3cbeSEric Kohl                               lpDevInst,
24576efb3cbeSEric Kohl                               pLogConfInfo->ulType,
24586efb3cbeSEric Kohl                               pLogConfInfo->ulTag,
24596efb3cbeSEric Kohl                               0);
2460c2c66affSColin Finck     }
2461c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2462c2c66affSColin Finck     {
2463c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2464c2c66affSColin Finck     }
2465c2c66affSColin Finck     RpcEndExcept;
2466c2c66affSColin Finck 
2467c2c66affSColin Finck     return ret;
2468c2c66affSColin Finck }
2469c2c66affSColin Finck 
2470c2c66affSColin Finck 
2471c2c66affSColin Finck /***********************************************************************
2472c2c66affSColin Finck  * CM_Free_Log_Conf_Handle [SETUPAPI.@]
2473c2c66affSColin Finck  */
2474c7fc2ef4SEric Kohl CONFIGRET
2475c7fc2ef4SEric Kohl WINAPI
2476c7fc2ef4SEric Kohl CM_Free_Log_Conf_Handle(
2477c7fc2ef4SEric Kohl     _In_ LOG_CONF lcLogConf)
2478c2c66affSColin Finck {
2479c2c66affSColin Finck     PLOG_CONF_INFO pLogConfInfo;
2480c2c66affSColin Finck 
2481c7fc2ef4SEric Kohl     TRACE("CM_Free_Log_Conf_Handle(%lx)\n", lcLogConf);
2482c2c66affSColin Finck 
2483c2c66affSColin Finck     pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
248419fc20f2SEric Kohl     if (!IsValidLogConf(pLogConfInfo))
2485c2c66affSColin Finck         return CR_INVALID_LOG_CONF;
2486c2c66affSColin Finck 
2487c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, pLogConfInfo);
2488c2c66affSColin Finck 
2489c2c66affSColin Finck     return CR_SUCCESS;
2490c2c66affSColin Finck }
2491c2c66affSColin Finck 
2492c2c66affSColin Finck 
2493c2c66affSColin Finck /***********************************************************************
2494c2c66affSColin Finck  * CM_Free_Range_List [SETUPAPI.@]
2495c2c66affSColin Finck  */
2496c2c66affSColin Finck CONFIGRET
2497c2c66affSColin Finck WINAPI
2498c2c66affSColin Finck CM_Free_Range_List(
2499c2c66affSColin Finck     _In_ RANGE_LIST RangeList,
2500c2c66affSColin Finck     _In_ ULONG ulFlags)
2501c2c66affSColin Finck {
2502c2c66affSColin Finck     PINTERNAL_RANGE_LIST pRangeList;
25033ad5c7fdSEric Kohl     PINTERNAL_RANGE pRange;
25043ad5c7fdSEric Kohl     PLIST_ENTRY ListEntry;
2505c2c66affSColin Finck 
25063ad5c7fdSEric Kohl     FIXME("CM_Free_Range_List(%p %lx)\n",
25073ad5c7fdSEric Kohl           RangeList, ulFlags);
2508c2c66affSColin Finck 
2509c2c66affSColin Finck     pRangeList = (PINTERNAL_RANGE_LIST)RangeList;
2510c2c66affSColin Finck 
25113ad5c7fdSEric Kohl     if (!IsValidRangeList(pRangeList))
2512c2c66affSColin Finck         return CR_INVALID_RANGE_LIST;
2513c2c66affSColin Finck 
2514c2c66affSColin Finck     if (ulFlags != 0)
2515c2c66affSColin Finck         return CR_INVALID_FLAG;
2516c2c66affSColin Finck 
25173ad5c7fdSEric Kohl     /* Lock the range list */
25183ad5c7fdSEric Kohl     WaitForSingleObject(pRangeList->hMutex, INFINITE);
2519c2c66affSColin Finck 
25203ad5c7fdSEric Kohl     /* Free the list of ranges */
25213ad5c7fdSEric Kohl     while (!IsListEmpty(&pRangeList->ListHead))
25223ad5c7fdSEric Kohl     {
25233ad5c7fdSEric Kohl         ListEntry = RemoveHeadList(&pRangeList->ListHead);
25243ad5c7fdSEric Kohl         pRange = CONTAINING_RECORD(ListEntry, INTERNAL_RANGE, ListEntry);
25253ad5c7fdSEric Kohl         HeapFree(GetProcessHeap(), 0, pRange);
25263ad5c7fdSEric Kohl     }
25273ad5c7fdSEric Kohl 
25283ad5c7fdSEric Kohl     /* Unlock the range list */
25293ad5c7fdSEric Kohl     ReleaseMutex(pRangeList->hMutex);
25303ad5c7fdSEric Kohl 
25313ad5c7fdSEric Kohl     /* Close the mutex */
25323ad5c7fdSEric Kohl     CloseHandle(pRangeList->hMutex);
25333ad5c7fdSEric Kohl 
25343ad5c7fdSEric Kohl     /* Free the range list */
2535c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, pRangeList);
2536c2c66affSColin Finck 
2537c2c66affSColin Finck     return CR_SUCCESS;
2538c2c66affSColin Finck }
2539c2c66affSColin Finck 
2540c2c66affSColin Finck 
2541c2c66affSColin Finck /***********************************************************************
2542c2c66affSColin Finck  * CM_Free_Res_Des [SETUPAPI.@]
2543c2c66affSColin Finck  */
2544c7fc2ef4SEric Kohl CONFIGRET
2545c7fc2ef4SEric Kohl WINAPI
2546c7fc2ef4SEric Kohl CM_Free_Res_Des(
2547c7fc2ef4SEric Kohl     _Out_ PRES_DES prdResDes,
2548c7fc2ef4SEric Kohl     _In_ RES_DES rdResDes,
2549c7fc2ef4SEric Kohl     _In_ ULONG ulFlags)
2550c2c66affSColin Finck {
2551c7fc2ef4SEric Kohl     TRACE("CM_Free_Res_Des(%p %p %lx)\n",
2552c7fc2ef4SEric Kohl           prdResDes, rdResDes, ulFlags);
2553c7fc2ef4SEric Kohl 
2554c2c66affSColin Finck     return CM_Free_Res_Des_Ex(prdResDes, rdResDes, ulFlags, NULL);
2555c2c66affSColin Finck }
2556c2c66affSColin Finck 
2557c2c66affSColin Finck 
2558c2c66affSColin Finck /***********************************************************************
2559c2c66affSColin Finck  * CM_Free_Res_Des_Ex [SETUPAPI.@]
2560c2c66affSColin Finck  */
2561c7fc2ef4SEric Kohl CONFIGRET
2562c7fc2ef4SEric Kohl WINAPI
2563c7fc2ef4SEric Kohl CM_Free_Res_Des_Ex(
2564c7fc2ef4SEric Kohl     _Out_ PRES_DES prdResDes,
2565c7fc2ef4SEric Kohl     _In_ RES_DES rdResDes,
2566c7fc2ef4SEric Kohl     _In_ ULONG ulFlags,
2567c7fc2ef4SEric Kohl     _In_opt_ HMACHINE hMachine)
2568c2c66affSColin Finck {
256960a21894SEric Kohl     FIXME("CM_Free_Res_Des_Ex(%p %p %lx %p)\n",
2570c7fc2ef4SEric Kohl           prdResDes, rdResDes, ulFlags, hMachine);
2571c2c66affSColin Finck 
2572c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
2573c2c66affSColin Finck }
2574c2c66affSColin Finck 
2575c2c66affSColin Finck 
2576c2c66affSColin Finck /***********************************************************************
2577c2c66affSColin Finck  * CM_Free_Res_Des_Handle [SETUPAPI.@]
2578c2c66affSColin Finck  */
2579c7fc2ef4SEric Kohl CONFIGRET
2580c7fc2ef4SEric Kohl WINAPI
2581c7fc2ef4SEric Kohl CM_Free_Res_Des_Handle(
2582c7fc2ef4SEric Kohl     _In_ RES_DES rdResDes)
2583c2c66affSColin Finck {
2584894ad4f1SEric Kohl     PRES_DES_INFO pResDesInfo;
2585894ad4f1SEric Kohl 
2586c7fc2ef4SEric Kohl     FIXME("CM_Free_Res_Des_Handle(%p)\n", rdResDes);
2587c2c66affSColin Finck 
2588894ad4f1SEric Kohl     pResDesInfo = (PRES_DES_INFO)rdResDes;
2589894ad4f1SEric Kohl     if (!IsValidResDes(pResDesInfo))
2590894ad4f1SEric Kohl         return CR_INVALID_RES_DES;
2591894ad4f1SEric Kohl 
2592894ad4f1SEric Kohl     HeapFree(GetProcessHeap(), 0, pResDesInfo);
2593894ad4f1SEric Kohl 
2594894ad4f1SEric Kohl     return CR_SUCCESS;
2595c2c66affSColin Finck }
2596c2c66affSColin Finck 
2597c2c66affSColin Finck 
2598c2c66affSColin Finck /***********************************************************************
2599d7e40954SEric Kohl  * CM_Free_Resource_Conflict_Handle [SETUPAPI.@]
2600d7e40954SEric Kohl  */
2601d7e40954SEric Kohl CONFIGRET
2602d7e40954SEric Kohl WINAPI
2603d7e40954SEric Kohl CM_Free_Resource_Conflict_Handle(
2604d7e40954SEric Kohl     _In_ CONFLICT_LIST clConflictList)
2605d7e40954SEric Kohl {
2606cee1817eSEric Kohl     PCONFLICT_DATA pConflictData;
2607d7e40954SEric Kohl 
2608cee1817eSEric Kohl     FIXME("CM_Free_Resource_Conflict_Handle(%p)\n",
2609cee1817eSEric Kohl           clConflictList);
2610cee1817eSEric Kohl 
2611cee1817eSEric Kohl     pConflictData = (PCONFLICT_DATA)clConflictList;
2612cee1817eSEric Kohl     if (!IsValidConflictData(pConflictData))
2613cee1817eSEric Kohl         return CR_INVALID_CONFLICT_LIST;
2614cee1817eSEric Kohl 
2615cee1817eSEric Kohl     if (pConflictData->pConflictList != NULL)
2616cee1817eSEric Kohl         MyFree(pConflictData->pConflictList);
2617cee1817eSEric Kohl 
2618cee1817eSEric Kohl     MyFree(pConflictData);
2619cee1817eSEric Kohl 
2620cee1817eSEric Kohl     return CR_SUCCESS;
2621d7e40954SEric Kohl }
2622d7e40954SEric Kohl 
2623d7e40954SEric Kohl 
2624d7e40954SEric Kohl /***********************************************************************
2625c2c66affSColin Finck  * CM_Get_Child [SETUPAPI.@]
2626c2c66affSColin Finck  */
2627c7fc2ef4SEric Kohl CONFIGRET
2628c7fc2ef4SEric Kohl WINAPI
2629c7fc2ef4SEric Kohl CM_Get_Child(
2630c7fc2ef4SEric Kohl     _Out_ PDEVINST pdnDevInst,
2631c7fc2ef4SEric Kohl     _In_ DEVINST dnDevInst,
2632c7fc2ef4SEric Kohl     _In_ ULONG ulFlags)
2633c2c66affSColin Finck {
2634c7fc2ef4SEric Kohl     TRACE("CM_Get_Child(%p %p %lx)\n",
2635c7fc2ef4SEric Kohl           pdnDevInst, dnDevInst, ulFlags);
2636c7fc2ef4SEric Kohl 
2637c2c66affSColin Finck     return CM_Get_Child_Ex(pdnDevInst, dnDevInst, ulFlags, NULL);
2638c2c66affSColin Finck }
2639c2c66affSColin Finck 
2640c2c66affSColin Finck 
2641c2c66affSColin Finck /***********************************************************************
2642c2c66affSColin Finck  * CM_Get_Child_Ex [SETUPAPI.@]
2643c2c66affSColin Finck  */
2644c7fc2ef4SEric Kohl CONFIGRET
2645c7fc2ef4SEric Kohl WINAPI
2646c7fc2ef4SEric Kohl CM_Get_Child_Ex(
2647c7fc2ef4SEric Kohl     _Out_ PDEVINST pdnDevInst,
2648c7fc2ef4SEric Kohl     _In_ DEVINST dnDevInst,
2649c7fc2ef4SEric Kohl     _In_ ULONG ulFlags,
2650c7fc2ef4SEric Kohl     _In_opt_ HMACHINE hMachine)
2651c2c66affSColin Finck {
2652c2c66affSColin Finck     WCHAR szRelatedDevInst[MAX_DEVICE_ID_LEN];
2653c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
2654c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
2655c2c66affSColin Finck     LPWSTR lpDevInst;
2656c2c66affSColin Finck     DWORD dwIndex, dwLength = MAX_DEVICE_ID_LEN;
2657c2c66affSColin Finck     CONFIGRET ret;
2658c2c66affSColin Finck 
265960a21894SEric Kohl     TRACE("CM_Get_Child_Ex(%p %lx %lx %p)\n",
2660c7fc2ef4SEric Kohl           pdnDevInst, dnDevInst, ulFlags, hMachine);
2661c2c66affSColin Finck 
2662c2c66affSColin Finck     if (pdnDevInst == NULL)
2663c2c66affSColin Finck         return CR_INVALID_POINTER;
2664c2c66affSColin Finck 
2665c2c66affSColin Finck     if (dnDevInst == 0)
2666c2c66affSColin Finck         return CR_INVALID_DEVINST;
2667c2c66affSColin Finck 
2668c2c66affSColin Finck     if (ulFlags != 0)
2669c2c66affSColin Finck         return CR_INVALID_FLAG;
2670c2c66affSColin Finck 
2671c2c66affSColin Finck     *pdnDevInst = -1;
2672c2c66affSColin Finck 
2673c2c66affSColin Finck     if (hMachine != NULL)
2674c2c66affSColin Finck     {
2675c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2676c2c66affSColin Finck         if (BindingHandle == NULL)
2677c2c66affSColin Finck             return CR_FAILURE;
2678c2c66affSColin Finck 
2679c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2680c2c66affSColin Finck         if (StringTable == 0)
2681c2c66affSColin Finck             return CR_FAILURE;
2682c2c66affSColin Finck     }
2683c2c66affSColin Finck     else
2684c2c66affSColin Finck     {
2685c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2686c2c66affSColin Finck             return CR_FAILURE;
2687c2c66affSColin Finck     }
2688c2c66affSColin Finck 
2689c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2690c2c66affSColin Finck     if (lpDevInst == NULL)
2691c2c66affSColin Finck         return CR_INVALID_DEVNODE;
2692c2c66affSColin Finck 
2693c2c66affSColin Finck     RpcTryExcept
2694c2c66affSColin Finck     {
2695c2c66affSColin Finck         ret = PNP_GetRelatedDeviceInstance(BindingHandle,
2696c2c66affSColin Finck                                            PNP_GET_CHILD_DEVICE_INSTANCE,
2697c2c66affSColin Finck                                            lpDevInst,
2698c2c66affSColin Finck                                            szRelatedDevInst,
2699c2c66affSColin Finck                                            &dwLength,
2700c2c66affSColin Finck                                            0);
2701c2c66affSColin Finck     }
2702c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2703c2c66affSColin Finck     {
2704c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2705c2c66affSColin Finck     }
2706c2c66affSColin Finck     RpcEndExcept;
2707c2c66affSColin Finck 
2708c2c66affSColin Finck     if (ret != CR_SUCCESS)
2709c2c66affSColin Finck         return ret;
2710c2c66affSColin Finck 
2711c2c66affSColin Finck     TRACE("szRelatedDevInst: %s\n", debugstr_w(szRelatedDevInst));
2712c2c66affSColin Finck 
2713c2c66affSColin Finck     dwIndex = pSetupStringTableAddString(StringTable, szRelatedDevInst, 1);
2714c2c66affSColin Finck     if (dwIndex == -1)
2715c2c66affSColin Finck         return CR_FAILURE;
2716c2c66affSColin Finck 
2717c2c66affSColin Finck     *pdnDevInst = dwIndex;
2718c2c66affSColin Finck 
2719c2c66affSColin Finck     return CR_SUCCESS;
2720c2c66affSColin Finck }
2721c2c66affSColin Finck 
2722c2c66affSColin Finck 
2723c2c66affSColin Finck /***********************************************************************
2724c2c66affSColin Finck  * CM_Get_Class_Key_NameA [SETUPAPI.@]
2725c2c66affSColin Finck  */
272665d3bf74SEric Kohl CONFIGRET
272765d3bf74SEric Kohl WINAPI
272865d3bf74SEric Kohl CM_Get_Class_Key_NameA(
272965d3bf74SEric Kohl     _In_ LPGUID ClassGuid,
273065d3bf74SEric Kohl     _Out_writes_opt_(*pulLength) LPSTR pszKeyName,
273165d3bf74SEric Kohl     _Inout_ PULONG pulLength,
273265d3bf74SEric Kohl     _In_ ULONG ulFlags)
2733c2c66affSColin Finck {
273465d3bf74SEric Kohl     TRACE("CM_Get_Class_Key_NameA(%p %p %p %lx)\n",
2735c2c66affSColin Finck           ClassGuid, pszKeyName, pulLength, ulFlags);
273665d3bf74SEric Kohl 
2737c2c66affSColin Finck     return CM_Get_Class_Key_Name_ExA(ClassGuid, pszKeyName, pulLength,
2738c2c66affSColin Finck                                      ulFlags, NULL);
2739c2c66affSColin Finck }
2740c2c66affSColin Finck 
2741c2c66affSColin Finck 
2742c2c66affSColin Finck /***********************************************************************
2743c2c66affSColin Finck  * CM_Get_Class_Key_NameW [SETUPAPI.@]
2744c2c66affSColin Finck  */
274565d3bf74SEric Kohl CONFIGRET
274665d3bf74SEric Kohl WINAPI
274765d3bf74SEric Kohl CM_Get_Class_Key_NameW(
274865d3bf74SEric Kohl     _In_ LPGUID ClassGuid,
274965d3bf74SEric Kohl     _Out_writes_opt_(*pulLength) LPWSTR pszKeyName,
275065d3bf74SEric Kohl     _Inout_ PULONG pulLength,
275165d3bf74SEric Kohl     _In_ ULONG ulFlags)
2752c2c66affSColin Finck {
275365d3bf74SEric Kohl     TRACE("CM_Get_Class_Key_NameW(%p %p %p %lx)\n",
2754c2c66affSColin Finck           ClassGuid, pszKeyName, pulLength, ulFlags);
275565d3bf74SEric Kohl 
2756c2c66affSColin Finck     return CM_Get_Class_Key_Name_ExW(ClassGuid, pszKeyName, pulLength,
2757c2c66affSColin Finck                                      ulFlags, NULL);
2758c2c66affSColin Finck }
2759c2c66affSColin Finck 
2760c2c66affSColin Finck 
2761c2c66affSColin Finck /***********************************************************************
2762c2c66affSColin Finck  * CM_Get_Class_Key_Name_ExA [SETUPAPI.@]
2763c2c66affSColin Finck  */
276465d3bf74SEric Kohl CONFIGRET
276565d3bf74SEric Kohl WINAPI
276665d3bf74SEric Kohl CM_Get_Class_Key_Name_ExA(
276765d3bf74SEric Kohl     _In_ LPGUID ClassGuid,
276865d3bf74SEric Kohl     _Out_writes_opt_(*pulLength) LPSTR pszKeyName,
276965d3bf74SEric Kohl     _Inout_ PULONG pulLength,
277065d3bf74SEric Kohl     _In_ ULONG ulFlags,
277165d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
2772c2c66affSColin Finck {
2773c2c66affSColin Finck     WCHAR szBuffer[MAX_GUID_STRING_LEN];
2774c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
2775c2c66affSColin Finck     ULONG ulLength;
2776c2c66affSColin Finck     ULONG ulOrigLength;
2777c2c66affSColin Finck 
277860a21894SEric Kohl     TRACE("CM_Get_Class_Key_Name_ExA(%p %p %p %lx %p)\n",
2779c2c66affSColin Finck           ClassGuid, pszKeyName, pulLength, ulFlags, hMachine);
2780c2c66affSColin Finck 
2781c2c66affSColin Finck     if (ClassGuid == NULL || pszKeyName == NULL || pulLength == NULL)
2782c2c66affSColin Finck         return CR_INVALID_POINTER;
2783c2c66affSColin Finck 
2784c2c66affSColin Finck     ulOrigLength = *pulLength;
2785c2c66affSColin Finck     *pulLength = 0;
2786c2c66affSColin Finck 
2787c2c66affSColin Finck     ulLength = MAX_GUID_STRING_LEN;
2788c2c66affSColin Finck     ret = CM_Get_Class_Key_Name_ExW(ClassGuid, szBuffer, &ulLength,
2789c2c66affSColin Finck                                     ulFlags, hMachine);
2790c2c66affSColin Finck     if (ret == CR_SUCCESS)
2791c2c66affSColin Finck     {
2792c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
2793c2c66affSColin Finck                                 0,
2794c2c66affSColin Finck                                 szBuffer,
2795c2c66affSColin Finck                                 ulLength,
2796c2c66affSColin Finck                                 pszKeyName,
2797c2c66affSColin Finck                                 ulOrigLength,
2798c2c66affSColin Finck                                 NULL,
2799c2c66affSColin Finck                                 NULL) == 0)
2800c2c66affSColin Finck             ret = CR_FAILURE;
2801c2c66affSColin Finck         else
2802c2c66affSColin Finck             *pulLength = lstrlenA(pszKeyName) + 1;
2803c2c66affSColin Finck     }
2804c2c66affSColin Finck 
2805c2c66affSColin Finck     return CR_SUCCESS;
2806c2c66affSColin Finck }
2807c2c66affSColin Finck 
2808c2c66affSColin Finck 
2809c2c66affSColin Finck /***********************************************************************
2810c2c66affSColin Finck  * CM_Get_Class_Key_Name_ExW [SETUPAPI.@]
2811c2c66affSColin Finck  */
281265d3bf74SEric Kohl CONFIGRET
281365d3bf74SEric Kohl WINAPI
281465d3bf74SEric Kohl CM_Get_Class_Key_Name_ExW(
281565d3bf74SEric Kohl     _In_ LPGUID ClassGuid,
281665d3bf74SEric Kohl     _Out_writes_opt_(*pulLength) LPWSTR pszKeyName,
281765d3bf74SEric Kohl     _Inout_ PULONG pulLength,
281865d3bf74SEric Kohl     _In_ ULONG ulFlags,
281965d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
2820c2c66affSColin Finck {
282160a21894SEric Kohl     TRACE("CM_Get_Class_Key_Name_ExW(%p %p %p %lx %p)\n",
2822c2c66affSColin Finck           ClassGuid, pszKeyName, pulLength, ulFlags, hMachine);
2823c2c66affSColin Finck 
2824c2c66affSColin Finck     if (ClassGuid == NULL || pszKeyName == NULL || pulLength == NULL)
2825c2c66affSColin Finck         return CR_INVALID_POINTER;
2826c2c66affSColin Finck 
2827c2c66affSColin Finck     if (ulFlags != 0)
2828c2c66affSColin Finck         return CR_INVALID_FLAG;
2829c2c66affSColin Finck 
2830c2c66affSColin Finck     if (*pulLength < MAX_GUID_STRING_LEN)
2831c2c66affSColin Finck     {
2832c2c66affSColin Finck         *pulLength = 0;
2833c2c66affSColin Finck         return CR_BUFFER_SMALL;
2834c2c66affSColin Finck     }
2835c2c66affSColin Finck 
2836c2c66affSColin Finck     if (!GuidToString(ClassGuid, pszKeyName))
2837c2c66affSColin Finck         return CR_INVALID_DATA;
2838c2c66affSColin Finck 
2839c2c66affSColin Finck     *pulLength = MAX_GUID_STRING_LEN;
2840c2c66affSColin Finck 
2841c2c66affSColin Finck     return CR_SUCCESS;
2842c2c66affSColin Finck }
2843c2c66affSColin Finck 
2844c2c66affSColin Finck 
2845c2c66affSColin Finck /***********************************************************************
2846c2c66affSColin Finck  * CM_Get_Class_NameA [SETUPAPI.@]
2847c2c66affSColin Finck  */
284865d3bf74SEric Kohl CONFIGRET
284965d3bf74SEric Kohl WINAPI
285065d3bf74SEric Kohl CM_Get_Class_NameA(
285165d3bf74SEric Kohl     _In_ LPGUID ClassGuid,
285265d3bf74SEric Kohl     _Out_writes_opt_(*pulLength) PCHAR Buffer,
285365d3bf74SEric Kohl     _Inout_ PULONG pulLength,
285465d3bf74SEric Kohl     _In_ ULONG ulFlags)
2855c2c66affSColin Finck {
285665d3bf74SEric Kohl     TRACE("CM_Get_Class_NameA(%p %p %p %lx)\n",
285765d3bf74SEric Kohl           ClassGuid, Buffer, pulLength, ulFlags);
285865d3bf74SEric Kohl 
2859c2c66affSColin Finck     return CM_Get_Class_Name_ExA(ClassGuid, Buffer, pulLength, ulFlags,
2860c2c66affSColin Finck                                  NULL);
2861c2c66affSColin Finck }
2862c2c66affSColin Finck 
2863c2c66affSColin Finck 
2864c2c66affSColin Finck /***********************************************************************
2865c2c66affSColin Finck  * CM_Get_Class_NameW [SETUPAPI.@]
2866c2c66affSColin Finck  */
286765d3bf74SEric Kohl CONFIGRET
286865d3bf74SEric Kohl WINAPI
286965d3bf74SEric Kohl CM_Get_Class_NameW(
287065d3bf74SEric Kohl     _In_ LPGUID ClassGuid,
287165d3bf74SEric Kohl     _Out_writes_opt_(*pulLength) PWCHAR Buffer,
287265d3bf74SEric Kohl     _Inout_ PULONG pulLength,
287365d3bf74SEric Kohl     _In_ ULONG ulFlags)
2874c2c66affSColin Finck {
287565d3bf74SEric Kohl     TRACE("CM_Get_Class_NameW(%p %p %p %lx)\n",
287665d3bf74SEric Kohl           ClassGuid, Buffer, pulLength, ulFlags);
287765d3bf74SEric Kohl 
2878c2c66affSColin Finck     return CM_Get_Class_Name_ExW(ClassGuid, Buffer, pulLength, ulFlags,
2879c2c66affSColin Finck                                  NULL);
2880c2c66affSColin Finck }
2881c2c66affSColin Finck 
2882c2c66affSColin Finck 
2883c2c66affSColin Finck /***********************************************************************
2884c2c66affSColin Finck  * CM_Get_Class_Name_ExA [SETUPAPI.@]
2885c2c66affSColin Finck  */
288665d3bf74SEric Kohl CONFIGRET
288765d3bf74SEric Kohl WINAPI
288865d3bf74SEric Kohl CM_Get_Class_Name_ExA(
288965d3bf74SEric Kohl     _In_ LPGUID ClassGuid,
289065d3bf74SEric Kohl     _Out_writes_opt_(*pulLength) PCHAR Buffer,
289165d3bf74SEric Kohl     _Inout_ PULONG pulLength,
289265d3bf74SEric Kohl     _In_ ULONG ulFlags,
289365d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
2894c2c66affSColin Finck {
2895c2c66affSColin Finck     WCHAR szBuffer[MAX_CLASS_NAME_LEN];
2896c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
2897c2c66affSColin Finck     ULONG ulLength;
2898c2c66affSColin Finck     ULONG ulOrigLength;
2899c2c66affSColin Finck 
290060a21894SEric Kohl     TRACE("CM_Get_Class_Name_ExA(%p %p %p %lx %p)\n",
2901c2c66affSColin Finck           ClassGuid, Buffer, pulLength, ulFlags, hMachine);
2902c2c66affSColin Finck 
2903c2c66affSColin Finck     if (ClassGuid == NULL || Buffer == NULL || pulLength == NULL)
2904c2c66affSColin Finck         return CR_INVALID_POINTER;
2905c2c66affSColin Finck 
2906c2c66affSColin Finck     ulOrigLength = *pulLength;
2907c2c66affSColin Finck     *pulLength = 0;
2908c2c66affSColin Finck 
2909c2c66affSColin Finck     ulLength = MAX_CLASS_NAME_LEN;
2910c2c66affSColin Finck     ret = CM_Get_Class_Name_ExW(ClassGuid, szBuffer, &ulLength,
2911c2c66affSColin Finck                                 ulFlags, hMachine);
2912c2c66affSColin Finck     if (ret == CR_SUCCESS)
2913c2c66affSColin Finck     {
2914c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
2915c2c66affSColin Finck                                 0,
2916c2c66affSColin Finck                                 szBuffer,
2917c2c66affSColin Finck                                 ulLength,
2918c2c66affSColin Finck                                 Buffer,
2919c2c66affSColin Finck                                 ulOrigLength,
2920c2c66affSColin Finck                                 NULL,
2921c2c66affSColin Finck                                 NULL) == 0)
2922c2c66affSColin Finck             ret = CR_FAILURE;
2923c2c66affSColin Finck         else
2924c2c66affSColin Finck             *pulLength = lstrlenA(Buffer) + 1;
2925c2c66affSColin Finck     }
2926c2c66affSColin Finck 
2927c2c66affSColin Finck     return ret;
2928c2c66affSColin Finck }
2929c2c66affSColin Finck 
2930c2c66affSColin Finck 
2931c2c66affSColin Finck /***********************************************************************
2932c2c66affSColin Finck  * CM_Get_Class_Name_ExW [SETUPAPI.@]
2933c2c66affSColin Finck  */
293465d3bf74SEric Kohl CONFIGRET
293565d3bf74SEric Kohl WINAPI
2936c2c66affSColin Finck CM_Get_Class_Name_ExW(
293765d3bf74SEric Kohl     _In_ LPGUID ClassGuid,
293865d3bf74SEric Kohl     _Out_writes_opt_(*pulLength) PWCHAR Buffer,
293965d3bf74SEric Kohl     _Inout_ PULONG pulLength,
294065d3bf74SEric Kohl     _In_ ULONG ulFlags,
294165d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
2942c2c66affSColin Finck {
2943c2c66affSColin Finck     WCHAR szGuidString[MAX_GUID_STRING_LEN];
2944c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
2945c2c66affSColin Finck     CONFIGRET ret;
2946c2c66affSColin Finck 
294760a21894SEric Kohl     TRACE("CM_Get_Class_Name_ExW(%p %p %p %lx %p\n",
2948c2c66affSColin Finck           ClassGuid, Buffer, pulLength, ulFlags, hMachine);
2949c2c66affSColin Finck 
2950c2c66affSColin Finck     if (ClassGuid == NULL || Buffer == NULL || pulLength == NULL)
2951c2c66affSColin Finck         return CR_INVALID_POINTER;
2952c2c66affSColin Finck 
2953c2c66affSColin Finck     if (ulFlags != 0)
2954c2c66affSColin Finck         return CR_INVALID_FLAG;
2955c2c66affSColin Finck 
2956c2c66affSColin Finck     if (!GuidToString(ClassGuid, szGuidString))
2957c2c66affSColin Finck         return CR_INVALID_DATA;
2958c2c66affSColin Finck 
2959c2c66affSColin Finck     TRACE("Guid %s\n", debugstr_w(szGuidString));
2960c2c66affSColin Finck 
2961c2c66affSColin Finck     if (hMachine != NULL)
2962c2c66affSColin Finck     {
2963c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2964c2c66affSColin Finck         if (BindingHandle == NULL)
2965c2c66affSColin Finck             return CR_FAILURE;
2966c2c66affSColin Finck     }
2967c2c66affSColin Finck     else
2968c2c66affSColin Finck     {
2969c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
2970c2c66affSColin Finck             return CR_FAILURE;
2971c2c66affSColin Finck     }
2972c2c66affSColin Finck 
2973c2c66affSColin Finck     RpcTryExcept
2974c2c66affSColin Finck     {
2975c2c66affSColin Finck         ret = PNP_GetClassName(BindingHandle,
2976c2c66affSColin Finck                                szGuidString,
2977c2c66affSColin Finck                                Buffer,
2978c2c66affSColin Finck                                pulLength,
2979c2c66affSColin Finck                                ulFlags);
2980c2c66affSColin Finck     }
2981c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2982c2c66affSColin Finck     {
2983c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
2984c2c66affSColin Finck     }
2985c2c66affSColin Finck     RpcEndExcept;
2986c2c66affSColin Finck 
2987c2c66affSColin Finck     return ret;
2988c2c66affSColin Finck }
2989c2c66affSColin Finck 
2990c2c66affSColin Finck 
2991c2c66affSColin Finck /***********************************************************************
2992c2c66affSColin Finck  * CM_Get_Class_Registry_PropertyA [SETUPAPI.@]
2993c2c66affSColin Finck  */
299465d3bf74SEric Kohl CONFIGRET
299565d3bf74SEric Kohl WINAPI
299665d3bf74SEric Kohl CM_Get_Class_Registry_PropertyA(
299765d3bf74SEric Kohl     LPGUID ClassGuid,
299865d3bf74SEric Kohl     ULONG ulProperty,
299965d3bf74SEric Kohl     PULONG pulRegDataType,
300065d3bf74SEric Kohl     PVOID Buffer,
300165d3bf74SEric Kohl     PULONG pulLength,
300265d3bf74SEric Kohl     ULONG ulFlags,
300365d3bf74SEric Kohl     HMACHINE hMachine)
3004c2c66affSColin Finck {
30058943354dSSerge Gautherie     PWSTR BufferW;
3006c2c66affSColin Finck     ULONG ulLength = 0;
3007c2c66affSColin Finck     ULONG ulType;
3008c2c66affSColin Finck     CONFIGRET ret;
3009c2c66affSColin Finck 
301060a21894SEric Kohl     TRACE("CM_Get_Class_Registry_PropertyA(%p %lu %p %p %p %lx %p)\n",
3011c2c66affSColin Finck           ClassGuid, ulProperty, pulRegDataType, Buffer, pulLength,
3012c2c66affSColin Finck           ulFlags, hMachine);
3013c2c66affSColin Finck 
3014c2c66affSColin Finck     if (pulLength == NULL)
3015c2c66affSColin Finck         return CR_INVALID_POINTER;
3016c2c66affSColin Finck 
3017c2c66affSColin Finck     if (ulProperty < CM_CRP_MIN || ulProperty > CM_CRP_MAX)
3018c2c66affSColin Finck         return CR_INVALID_PROPERTY;
3019c2c66affSColin Finck 
3020c2c66affSColin Finck     ulType = GetRegistryPropertyType(ulProperty);
3021c2c66affSColin Finck     if (ulType == REG_SZ || ulType == REG_MULTI_SZ)
3022c2c66affSColin Finck     {
3023c2c66affSColin Finck         /* Get the required buffer size */
3024c2c66affSColin Finck         ret = CM_Get_Class_Registry_PropertyW(ClassGuid, ulProperty, pulRegDataType,
3025c2c66affSColin Finck                                               NULL, &ulLength, ulFlags, hMachine);
3026c2c66affSColin Finck         if (ret != CR_BUFFER_SMALL)
3027c2c66affSColin Finck             return ret;
3028c2c66affSColin Finck 
3029c2c66affSColin Finck         /* Allocate the unicode buffer */
3030c2c66affSColin Finck         BufferW = HeapAlloc(GetProcessHeap(), 0, ulLength);
3031c2c66affSColin Finck         if (BufferW == NULL)
3032c2c66affSColin Finck             return CR_OUT_OF_MEMORY;
3033c2c66affSColin Finck 
3034c2c66affSColin Finck         /* Get the property */
3035c2c66affSColin Finck         ret = CM_Get_Class_Registry_PropertyW(ClassGuid, ulProperty, pulRegDataType,
3036c2c66affSColin Finck                                               BufferW, &ulLength, ulFlags, hMachine);
3037c2c66affSColin Finck         if (ret != CR_SUCCESS)
3038c2c66affSColin Finck         {
3039c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, BufferW);
3040c2c66affSColin Finck             return ret;
3041c2c66affSColin Finck         }
3042c2c66affSColin Finck 
3043c2c66affSColin Finck         /* Do W->A conversion */
3044c2c66affSColin Finck         *pulLength = WideCharToMultiByte(CP_ACP,
3045c2c66affSColin Finck                                          0,
3046c2c66affSColin Finck                                          BufferW,
3047aa056499SVictor Perevertkin                                          ulLength,
3048c2c66affSColin Finck                                          Buffer,
3049c2c66affSColin Finck                                          *pulLength,
3050c2c66affSColin Finck                                          NULL,
3051c2c66affSColin Finck                                          NULL);
3052c2c66affSColin Finck 
3053c2c66affSColin Finck         /* Release the unicode buffer */
3054c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, BufferW);
3055c2c66affSColin Finck 
3056c2c66affSColin Finck         if (*pulLength == 0)
3057c2c66affSColin Finck             ret = CR_FAILURE;
3058c2c66affSColin Finck     }
3059c2c66affSColin Finck     else
3060c2c66affSColin Finck     {
3061c2c66affSColin Finck         /* Get the property */
3062c2c66affSColin Finck         ret = CM_Get_Class_Registry_PropertyW(ClassGuid, ulProperty, pulRegDataType,
3063c2c66affSColin Finck                                               Buffer, pulLength, ulFlags, hMachine);
3064c2c66affSColin Finck     }
3065c2c66affSColin Finck 
3066c2c66affSColin Finck     return ret;
3067c2c66affSColin Finck }
3068c2c66affSColin Finck 
3069c2c66affSColin Finck 
3070c2c66affSColin Finck /***********************************************************************
3071c2c66affSColin Finck  * CM_Get_Class_Registry_PropertyW [SETUPAPI.@]
3072c2c66affSColin Finck  */
307365d3bf74SEric Kohl CONFIGRET
307465d3bf74SEric Kohl WINAPI
307565d3bf74SEric Kohl CM_Get_Class_Registry_PropertyW(
307665d3bf74SEric Kohl     LPGUID ClassGuid,
307765d3bf74SEric Kohl     ULONG ulProperty,
307865d3bf74SEric Kohl     PULONG pulRegDataType,
307965d3bf74SEric Kohl     PVOID Buffer,
308065d3bf74SEric Kohl     PULONG pulLength,
308165d3bf74SEric Kohl     ULONG ulFlags,
308265d3bf74SEric Kohl     HMACHINE hMachine)
3083c2c66affSColin Finck {
3084c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3085c2c66affSColin Finck     WCHAR szGuidString[PNP_MAX_GUID_STRING_LEN + 1];
3086c2c66affSColin Finck     ULONG ulType = 0;
3087c2c66affSColin Finck     ULONG ulTransferLength = 0;
3088c2c66affSColin Finck     CONFIGRET ret;
3089c2c66affSColin Finck 
309060a21894SEric Kohl     TRACE("CM_Get_Class_Registry_PropertyW(%p %lu %p %p %p %lx %p)\n",
3091c2c66affSColin Finck           ClassGuid, ulProperty, pulRegDataType, Buffer, pulLength,
3092c2c66affSColin Finck           ulFlags, hMachine);
3093c2c66affSColin Finck 
3094c2c66affSColin Finck     if (ClassGuid == NULL || pulLength == NULL)
3095c2c66affSColin Finck         return CR_INVALID_POINTER;
3096c2c66affSColin Finck 
3097c2c66affSColin Finck     if (ulFlags != 0)
3098c2c66affSColin Finck         return CR_INVALID_FLAG;
3099c2c66affSColin Finck 
3100c2c66affSColin Finck     if (pSetupStringFromGuid(ClassGuid,
3101c2c66affSColin Finck                              szGuidString,
3102c2c66affSColin Finck                              PNP_MAX_GUID_STRING_LEN) != 0)
3103c2c66affSColin Finck         return CR_INVALID_DATA;
3104c2c66affSColin Finck 
3105c2c66affSColin Finck     if (ulProperty < CM_CRP_MIN || ulProperty > CM_CRP_MAX)
3106c2c66affSColin Finck         return CR_INVALID_PROPERTY;
3107c2c66affSColin Finck 
3108c2c66affSColin Finck     if (hMachine != NULL)
3109c2c66affSColin Finck     {
3110c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3111c2c66affSColin Finck         if (BindingHandle == NULL)
3112c2c66affSColin Finck             return CR_FAILURE;
3113c2c66affSColin Finck     }
3114c2c66affSColin Finck     else
3115c2c66affSColin Finck     {
3116c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
3117c2c66affSColin Finck             return CR_FAILURE;
3118c2c66affSColin Finck     }
3119c2c66affSColin Finck 
3120c2c66affSColin Finck     ulTransferLength = *pulLength;
3121c2c66affSColin Finck 
3122c2c66affSColin Finck     RpcTryExcept
3123c2c66affSColin Finck     {
3124c2c66affSColin Finck         ret = PNP_GetClassRegProp(BindingHandle,
3125c2c66affSColin Finck                                   szGuidString,
3126c2c66affSColin Finck                                   ulProperty,
3127c2c66affSColin Finck                                   &ulType,
3128c2c66affSColin Finck                                   Buffer,
3129c2c66affSColin Finck                                   &ulTransferLength,
3130c2c66affSColin Finck                                   pulLength,
3131c2c66affSColin Finck                                   ulFlags);
3132c2c66affSColin Finck     }
3133c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3134c2c66affSColin Finck     {
3135c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3136c2c66affSColin Finck     }
3137c2c66affSColin Finck     RpcEndExcept;
3138c2c66affSColin Finck 
3139c2c66affSColin Finck     if (ret == CR_SUCCESS)
3140c2c66affSColin Finck     {
3141c2c66affSColin Finck         if (pulRegDataType != NULL)
3142c2c66affSColin Finck             *pulRegDataType = ulType;
3143c2c66affSColin Finck     }
3144c2c66affSColin Finck 
3145c2c66affSColin Finck     return ret;
3146c2c66affSColin Finck }
3147c2c66affSColin Finck 
3148c2c66affSColin Finck 
3149c2c66affSColin Finck /***********************************************************************
3150c2c66affSColin Finck  * CM_Get_Depth [SETUPAPI.@]
3151c2c66affSColin Finck  */
315265d3bf74SEric Kohl CONFIGRET
315365d3bf74SEric Kohl WINAPI
315465d3bf74SEric Kohl CM_Get_Depth(
315565d3bf74SEric Kohl     _Out_ PULONG pulDepth,
315665d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
315765d3bf74SEric Kohl     _In_ ULONG ulFlags)
3158c2c66affSColin Finck {
315965d3bf74SEric Kohl     TRACE("CM_Get_Depth(%p %lx %lx)\n",
316065d3bf74SEric Kohl           pulDepth, dnDevInst, ulFlags);
316165d3bf74SEric Kohl 
3162c2c66affSColin Finck     return CM_Get_Depth_Ex(pulDepth, dnDevInst, ulFlags, NULL);
3163c2c66affSColin Finck }
3164c2c66affSColin Finck 
3165c2c66affSColin Finck 
3166c2c66affSColin Finck /***********************************************************************
3167c2c66affSColin Finck  * CM_Get_Depth_Ex [SETUPAPI.@]
3168c2c66affSColin Finck  */
316965d3bf74SEric Kohl CONFIGRET
317065d3bf74SEric Kohl WINAPI
317165d3bf74SEric Kohl CM_Get_Depth_Ex(
317265d3bf74SEric Kohl     _Out_ PULONG pulDepth,
317365d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
317465d3bf74SEric Kohl     _In_ ULONG ulFlags,
317565d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
3176c2c66affSColin Finck {
3177c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3178c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
3179c2c66affSColin Finck     LPWSTR lpDevInst;
3180c2c66affSColin Finck     CONFIGRET ret;
3181c2c66affSColin Finck 
318260a21894SEric Kohl     TRACE("CM_Get_Depth_Ex(%p %lx %lx %p)\n",
3183c2c66affSColin Finck           pulDepth, dnDevInst, ulFlags, hMachine);
3184c2c66affSColin Finck 
3185c2c66affSColin Finck     if (pulDepth == NULL)
3186c2c66affSColin Finck         return CR_INVALID_POINTER;
3187c2c66affSColin Finck 
3188c2c66affSColin Finck     if (dnDevInst == 0)
3189c2c66affSColin Finck         return CR_INVALID_DEVINST;
3190c2c66affSColin Finck 
3191c2c66affSColin Finck     if (ulFlags != 0)
3192c2c66affSColin Finck         return CR_INVALID_FLAG;
3193c2c66affSColin Finck 
3194c2c66affSColin Finck     if (hMachine != NULL)
3195c2c66affSColin Finck     {
3196c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3197c2c66affSColin Finck         if (BindingHandle == NULL)
3198c2c66affSColin Finck             return CR_FAILURE;
3199c2c66affSColin Finck 
3200c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3201c2c66affSColin Finck         if (StringTable == 0)
3202c2c66affSColin Finck             return CR_FAILURE;
3203c2c66affSColin Finck     }
3204c2c66affSColin Finck     else
3205c2c66affSColin Finck     {
3206c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
3207c2c66affSColin Finck             return CR_FAILURE;
3208c2c66affSColin Finck     }
3209c2c66affSColin Finck 
3210c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
3211c2c66affSColin Finck     if (lpDevInst == NULL)
3212c2c66affSColin Finck         return CR_INVALID_DEVNODE;
3213c2c66affSColin Finck 
3214c2c66affSColin Finck     RpcTryExcept
3215c2c66affSColin Finck     {
3216c2c66affSColin Finck         ret = PNP_GetDepth(BindingHandle,
3217c2c66affSColin Finck                            lpDevInst,
3218c2c66affSColin Finck                            pulDepth,
3219c2c66affSColin Finck                            ulFlags);
3220c2c66affSColin Finck     }
3221c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3222c2c66affSColin Finck     {
3223c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3224c2c66affSColin Finck     }
3225c2c66affSColin Finck     RpcEndExcept;
3226c2c66affSColin Finck 
3227c2c66affSColin Finck     return ret;
3228c2c66affSColin Finck }
3229c2c66affSColin Finck 
3230c2c66affSColin Finck 
3231c2c66affSColin Finck /***********************************************************************
3232c2c66affSColin Finck  * CM_Get_DevNode_Custom_PropertyA [SETUPAPI.@]
3233c2c66affSColin Finck  */
323465d3bf74SEric Kohl CONFIGRET
323565d3bf74SEric Kohl WINAPI
323665d3bf74SEric Kohl CM_Get_DevNode_Custom_PropertyA(
323765d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
323865d3bf74SEric Kohl     _In_ PCSTR pszCustomPropertyName,
323965d3bf74SEric Kohl     _Out_opt_ PULONG pulRegDataType,
324065d3bf74SEric Kohl     _Out_writes_bytes_opt_(*pulLength) PVOID Buffer,
324165d3bf74SEric Kohl     _Inout_ PULONG pulLength,
324265d3bf74SEric Kohl     _In_ ULONG ulFlags)
3243c2c66affSColin Finck {
324465d3bf74SEric Kohl     TRACE("CM_Get_DevNode_Custom_PropertyA(%lx %s %p %p %p %lx)\n",
324565d3bf74SEric Kohl           dnDevInst, pszCustomPropertyName, pulRegDataType,
324665d3bf74SEric Kohl           Buffer, pulLength, ulFlags);
324765d3bf74SEric Kohl 
3248c2c66affSColin Finck     return CM_Get_DevNode_Custom_Property_ExA(dnDevInst, pszCustomPropertyName,
3249c2c66affSColin Finck                                               pulRegDataType, Buffer,
3250c2c66affSColin Finck                                               pulLength, ulFlags, NULL);
3251c2c66affSColin Finck }
3252c2c66affSColin Finck 
3253c2c66affSColin Finck 
3254c2c66affSColin Finck /***********************************************************************
3255c2c66affSColin Finck  * CM_Get_DevNode_Custom_PropertyW [SETUPAPI.@]
3256c2c66affSColin Finck  */
325765d3bf74SEric Kohl CONFIGRET
325865d3bf74SEric Kohl WINAPI
325965d3bf74SEric Kohl CM_Get_DevNode_Custom_PropertyW(
326065d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
326165d3bf74SEric Kohl     _In_ PCWSTR pszCustomPropertyName,
326265d3bf74SEric Kohl     _Out_opt_ PULONG pulRegDataType,
326365d3bf74SEric Kohl     _Out_writes_bytes_opt_(*pulLength) PVOID Buffer,
326465d3bf74SEric Kohl     _Inout_ PULONG pulLength,
326565d3bf74SEric Kohl     _In_ ULONG ulFlags)
3266c2c66affSColin Finck {
326765d3bf74SEric Kohl     TRACE("CM_Get_DevNode_Custom_PropertyW(%lx %s %p %p %p %lx)\n",
326865d3bf74SEric Kohl           dnDevInst, debugstr_w(pszCustomPropertyName), pulRegDataType,
326965d3bf74SEric Kohl           Buffer, pulLength, ulFlags);
327065d3bf74SEric Kohl 
3271c2c66affSColin Finck     return CM_Get_DevNode_Custom_Property_ExW(dnDevInst, pszCustomPropertyName,
3272c2c66affSColin Finck                                               pulRegDataType, Buffer,
3273c2c66affSColin Finck                                               pulLength, ulFlags, NULL);
3274c2c66affSColin Finck }
3275c2c66affSColin Finck 
3276c2c66affSColin Finck 
3277c2c66affSColin Finck /***********************************************************************
3278c2c66affSColin Finck  * CM_Get_DevNode_Custom_Property_ExA [SETUPAPI.@]
3279c2c66affSColin Finck  */
328065d3bf74SEric Kohl CONFIGRET
328165d3bf74SEric Kohl WINAPI
328265d3bf74SEric Kohl CM_Get_DevNode_Custom_Property_ExA(
328365d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
328465d3bf74SEric Kohl     _In_ PCSTR pszCustomPropertyName,
328565d3bf74SEric Kohl     _Out_opt_ PULONG pulRegDataType,
328665d3bf74SEric Kohl     _Out_writes_bytes_opt_(*pulLength) PVOID Buffer,
328765d3bf74SEric Kohl     _Inout_ PULONG pulLength,
328865d3bf74SEric Kohl     _In_ ULONG ulFlags,
328965d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
3290c2c66affSColin Finck {
32918943354dSSerge Gautherie     LPWSTR pszPropertyNameW;
3292c2c66affSColin Finck     PVOID BufferW;
3293c2c66affSColin Finck     ULONG ulLengthW;
3294c2c66affSColin Finck     ULONG ulDataType = REG_NONE;
3295c2c66affSColin Finck     CONFIGRET ret;
3296c2c66affSColin Finck 
329765d3bf74SEric Kohl     TRACE("CM_Get_DevNode_Custom_Property_ExA(%lx %s %p %p %p %lx %p)\n",
329865d3bf74SEric Kohl           dnDevInst, pszCustomPropertyName, pulRegDataType,
329965d3bf74SEric Kohl           Buffer, pulLength, ulFlags, hMachine);
3300c2c66affSColin Finck 
3301c2c66affSColin Finck     if (!pulLength)
3302c2c66affSColin Finck         return CR_INVALID_POINTER;
3303c2c66affSColin Finck 
3304c2c66affSColin Finck     ulLengthW = *pulLength * sizeof(WCHAR);
3305c2c66affSColin Finck     BufferW = HeapAlloc(GetProcessHeap(), 0, ulLengthW);
3306c2c66affSColin Finck     if (!BufferW)
3307c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
3308c2c66affSColin Finck 
3309c2c66affSColin Finck     pszPropertyNameW = pSetupMultiByteToUnicode(pszCustomPropertyName,
3310c2c66affSColin Finck                                                 CP_ACP);
3311c2c66affSColin Finck     if (pszPropertyNameW == NULL)
3312c2c66affSColin Finck     {
3313c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, BufferW);
3314c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
3315c2c66affSColin Finck     }
3316c2c66affSColin Finck 
3317c2c66affSColin Finck     ret = CM_Get_DevNode_Custom_Property_ExW(dnDevInst,
3318c2c66affSColin Finck                                              pszPropertyNameW,
3319c2c66affSColin Finck                                              &ulDataType,
3320c2c66affSColin Finck                                              BufferW,
3321c2c66affSColin Finck                                              &ulLengthW,
3322c2c66affSColin Finck                                              ulFlags,
3323c2c66affSColin Finck                                              hMachine);
3324c2c66affSColin Finck     if (ret == CR_SUCCESS)
3325c2c66affSColin Finck     {
3326c2c66affSColin Finck         if (ulDataType == REG_SZ ||
3327c2c66affSColin Finck             ulDataType == REG_EXPAND_SZ ||
3328c2c66affSColin Finck             ulDataType == REG_MULTI_SZ)
3329c2c66affSColin Finck         {
3330c2c66affSColin Finck             /* Do W->A conversion */
3331c2c66affSColin Finck             *pulLength = WideCharToMultiByte(CP_ACP,
3332c2c66affSColin Finck                                              0,
3333c2c66affSColin Finck                                              BufferW,
3334c2c66affSColin Finck                                              lstrlenW(BufferW) + 1,
3335c2c66affSColin Finck                                              Buffer,
3336c2c66affSColin Finck                                              *pulLength,
3337c2c66affSColin Finck                                              NULL,
3338c2c66affSColin Finck                                              NULL);
3339c2c66affSColin Finck             if (*pulLength == 0)
3340c2c66affSColin Finck                 ret = CR_FAILURE;
3341c2c66affSColin Finck         }
3342c2c66affSColin Finck         else
3343c2c66affSColin Finck         {
3344c2c66affSColin Finck             /* Directly copy the value */
3345c2c66affSColin Finck             if (ulLengthW <= *pulLength)
3346c2c66affSColin Finck                 memcpy(Buffer, BufferW, ulLengthW);
3347c2c66affSColin Finck             else
3348c2c66affSColin Finck             {
3349c2c66affSColin Finck                 *pulLength = ulLengthW;
3350c2c66affSColin Finck                 ret = CR_BUFFER_SMALL;
3351c2c66affSColin Finck             }
3352c2c66affSColin Finck         }
3353c2c66affSColin Finck     }
3354c2c66affSColin Finck 
3355c2c66affSColin Finck     if (pulRegDataType)
3356c2c66affSColin Finck         *pulRegDataType = ulDataType;
3357c2c66affSColin Finck 
3358c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, BufferW);
3359c2c66affSColin Finck     MyFree(pszPropertyNameW);
3360c2c66affSColin Finck 
3361c2c66affSColin Finck     return ret;
3362c2c66affSColin Finck }
3363c2c66affSColin Finck 
3364c2c66affSColin Finck 
3365c2c66affSColin Finck /***********************************************************************
3366c2c66affSColin Finck  * CM_Get_DevNode_Custom_Property_ExW [SETUPAPI.@]
3367c2c66affSColin Finck  */
336865d3bf74SEric Kohl CONFIGRET
336965d3bf74SEric Kohl WINAPI
337065d3bf74SEric Kohl CM_Get_DevNode_Custom_Property_ExW(
337165d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
337265d3bf74SEric Kohl     _In_ PCWSTR pszCustomPropertyName,
337365d3bf74SEric Kohl     _Out_opt_ PULONG pulRegDataType,
337465d3bf74SEric Kohl     _Out_writes_bytes_opt_(*pulLength) PVOID Buffer,
337565d3bf74SEric Kohl     _Inout_ PULONG pulLength,
337665d3bf74SEric Kohl     _In_ ULONG ulFlags,
337765d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
3378c2c66affSColin Finck {
3379c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3380c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
3381c2c66affSColin Finck     LPWSTR lpDevInst;
3382c2c66affSColin Finck     ULONG ulDataType = REG_NONE;
3383c2c66affSColin Finck     ULONG ulTransferLength;
3384c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
3385c2c66affSColin Finck 
338665d3bf74SEric Kohl     TRACE("CM_Get_DevNode_Custom_Property_ExW(%lx %s %p %p %p %lx %p)\n",
338765d3bf74SEric Kohl           dnDevInst, debugstr_w(pszCustomPropertyName), pulRegDataType,
338865d3bf74SEric Kohl           Buffer, pulLength, ulFlags, hMachine);
3389c2c66affSColin Finck 
3390c2c66affSColin Finck     if (dnDevInst == 0)
3391c2c66affSColin Finck         return CR_INVALID_DEVNODE;
3392c2c66affSColin Finck 
3393c2c66affSColin Finck     if (pszCustomPropertyName == NULL ||
3394c2c66affSColin Finck         pulLength == NULL ||
3395c2c66affSColin Finck         *pulLength == 0)
3396c2c66affSColin Finck         return CR_INVALID_POINTER;
3397c2c66affSColin Finck 
3398c2c66affSColin Finck     if (ulFlags & ~CM_CUSTOMDEVPROP_BITS)
3399c2c66affSColin Finck         return CR_INVALID_FLAG;
3400c2c66affSColin Finck 
3401c2c66affSColin Finck     if (hMachine != NULL)
3402c2c66affSColin Finck     {
3403c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3404c2c66affSColin Finck         if (BindingHandle == NULL)
3405c2c66affSColin Finck             return CR_FAILURE;
3406c2c66affSColin Finck 
3407c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3408c2c66affSColin Finck         if (StringTable == 0)
3409c2c66affSColin Finck             return CR_FAILURE;
3410c2c66affSColin Finck     }
3411c2c66affSColin Finck     else
3412c2c66affSColin Finck     {
3413c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
3414c2c66affSColin Finck             return CR_FAILURE;
3415c2c66affSColin Finck     }
3416c2c66affSColin Finck 
3417c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
3418c2c66affSColin Finck     if (lpDevInst == NULL)
3419c2c66affSColin Finck         return CR_INVALID_DEVNODE;
3420c2c66affSColin Finck 
3421c2c66affSColin Finck     ulTransferLength = *pulLength;
3422c2c66affSColin Finck 
3423c2c66affSColin Finck     RpcTryExcept
3424c2c66affSColin Finck     {
3425c2c66affSColin Finck         ret = PNP_GetCustomDevProp(BindingHandle,
3426c2c66affSColin Finck                                    lpDevInst,
3427c2c66affSColin Finck                                    (LPWSTR)pszCustomPropertyName,
3428c2c66affSColin Finck                                    &ulDataType,
3429c2c66affSColin Finck                                    Buffer,
3430c2c66affSColin Finck                                    &ulTransferLength,
3431c2c66affSColin Finck                                    pulLength,
3432c2c66affSColin Finck                                    ulFlags);
3433c2c66affSColin Finck     }
3434c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3435c2c66affSColin Finck     {
3436c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3437c2c66affSColin Finck     }
3438c2c66affSColin Finck     RpcEndExcept;
3439c2c66affSColin Finck 
3440c2c66affSColin Finck     if (ret == CR_SUCCESS)
3441c2c66affSColin Finck     {
3442c2c66affSColin Finck         if (pulRegDataType != NULL)
3443c2c66affSColin Finck             *pulRegDataType = ulDataType;
3444c2c66affSColin Finck     }
3445c2c66affSColin Finck 
3446c2c66affSColin Finck     return ret;
3447c2c66affSColin Finck }
3448c2c66affSColin Finck 
3449c2c66affSColin Finck 
3450c2c66affSColin Finck /***********************************************************************
3451c2c66affSColin Finck  * CM_Get_DevNode_Registry_PropertyA [SETUPAPI.@]
3452c2c66affSColin Finck  */
345365d3bf74SEric Kohl CONFIGRET
345465d3bf74SEric Kohl WINAPI
345565d3bf74SEric Kohl CM_Get_DevNode_Registry_PropertyA(
345665d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
345765d3bf74SEric Kohl     _In_ ULONG ulProperty,
345865d3bf74SEric Kohl     _Out_opt_ PULONG pulRegDataType,
345965d3bf74SEric Kohl     _Out_writes_bytes_opt_(*pulLength) PVOID Buffer,
346065d3bf74SEric Kohl     _Inout_ PULONG pulLength,
346165d3bf74SEric Kohl     _In_ ULONG ulFlags)
3462c2c66affSColin Finck {
346365d3bf74SEric Kohl     TRACE("CM_Get_DevNode_Registry_PropertyA(%lx %lu %p %p %p %lx)\n",
3464c2c66affSColin Finck           dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength, ulFlags);
3465c2c66affSColin Finck 
3466c2c66affSColin Finck     return CM_Get_DevNode_Registry_Property_ExA(dnDevInst, ulProperty,
3467c2c66affSColin Finck                                                 pulRegDataType, Buffer,
3468c2c66affSColin Finck                                                 pulLength, ulFlags, NULL);
3469c2c66affSColin Finck }
3470c2c66affSColin Finck 
3471c2c66affSColin Finck 
3472c2c66affSColin Finck /***********************************************************************
3473c2c66affSColin Finck  * CM_Get_DevNode_Registry_PropertyW [SETUPAPI.@]
3474c2c66affSColin Finck  */
347565d3bf74SEric Kohl CONFIGRET
347665d3bf74SEric Kohl WINAPI
347765d3bf74SEric Kohl CM_Get_DevNode_Registry_PropertyW(
347865d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
347965d3bf74SEric Kohl     _In_ ULONG ulProperty,
348065d3bf74SEric Kohl     _Out_opt_ PULONG pulRegDataType,
348165d3bf74SEric Kohl     _Out_writes_bytes_opt_(*pulLength) PVOID Buffer,
348265d3bf74SEric Kohl     _Inout_ PULONG pulLength,
348365d3bf74SEric Kohl     _In_ ULONG ulFlags)
3484c2c66affSColin Finck {
348565d3bf74SEric Kohl     TRACE("CM_Get_DevNode_Registry_PropertyW(%lx %lu %p %p %p %lx)\n",
3486c2c66affSColin Finck           dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength, ulFlags);
3487c2c66affSColin Finck 
3488c2c66affSColin Finck     return CM_Get_DevNode_Registry_Property_ExW(dnDevInst, ulProperty,
3489c2c66affSColin Finck                                                 pulRegDataType, Buffer,
3490c2c66affSColin Finck                                                 pulLength, ulFlags, NULL);
3491c2c66affSColin Finck }
3492c2c66affSColin Finck 
3493c2c66affSColin Finck 
3494c2c66affSColin Finck /***********************************************************************
3495c2c66affSColin Finck  * CM_Get_DevNode_Registry_Property_ExA [SETUPAPI.@]
3496c2c66affSColin Finck  */
349765d3bf74SEric Kohl CONFIGRET
349865d3bf74SEric Kohl WINAPI
349965d3bf74SEric Kohl CM_Get_DevNode_Registry_Property_ExA(
350065d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
350165d3bf74SEric Kohl     _In_ ULONG ulProperty,
350265d3bf74SEric Kohl     _Out_opt_ PULONG pulRegDataType,
350365d3bf74SEric Kohl     _Out_writes_bytes_opt_(*pulLength) PVOID Buffer,
350465d3bf74SEric Kohl     _Inout_ PULONG pulLength,
350565d3bf74SEric Kohl     _In_ ULONG ulFlags,
350665d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
3507c2c66affSColin Finck {
3508c2c66affSColin Finck     PVOID BufferW;
3509c2c66affSColin Finck     ULONG LengthW;
3510c2c66affSColin Finck     ULONG ulDataType = REG_NONE;
3511c2c66affSColin Finck     CONFIGRET ret;
3512c2c66affSColin Finck 
351360a21894SEric Kohl     TRACE("CM_Get_DevNode_Registry_Property_ExA(%lx %lu %p %p %p %lx %p)\n",
3514c2c66affSColin Finck           dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength,
3515c2c66affSColin Finck           ulFlags, hMachine);
3516c2c66affSColin Finck 
3517c2c66affSColin Finck     if (!pulLength)
3518c2c66affSColin Finck         return CR_INVALID_POINTER;
3519c2c66affSColin Finck 
3520c2c66affSColin Finck     LengthW = *pulLength * sizeof(WCHAR);
3521c2c66affSColin Finck     BufferW = HeapAlloc(GetProcessHeap(), 0, LengthW);
3522c2c66affSColin Finck     if (!BufferW)
3523c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
3524c2c66affSColin Finck 
3525c2c66affSColin Finck     ret = CM_Get_DevNode_Registry_Property_ExW(dnDevInst,
3526c2c66affSColin Finck                                                ulProperty,
3527c2c66affSColin Finck                                                &ulDataType,
3528c2c66affSColin Finck                                                BufferW,
3529c2c66affSColin Finck                                                &LengthW,
3530c2c66affSColin Finck                                                ulFlags,
3531c2c66affSColin Finck                                                hMachine);
3532c2c66affSColin Finck 
3533c2c66affSColin Finck     if (ret == CR_SUCCESS)
3534c2c66affSColin Finck     {
3535c2c66affSColin Finck         if (ulDataType == REG_SZ ||
3536c2c66affSColin Finck             ulDataType == REG_EXPAND_SZ ||
3537c2c66affSColin Finck             ulDataType == REG_MULTI_SZ)
3538c2c66affSColin Finck         {
3539c2c66affSColin Finck             /* Do W->A conversion */
3540c2c66affSColin Finck             *pulLength = WideCharToMultiByte(CP_ACP,
3541c2c66affSColin Finck                                              0,
3542c2c66affSColin Finck                                              BufferW,
3543c2c66affSColin Finck                                              lstrlenW(BufferW) + 1,
3544c2c66affSColin Finck                                              Buffer,
3545c2c66affSColin Finck                                              *pulLength,
3546c2c66affSColin Finck                                              NULL,
3547c2c66affSColin Finck                                              NULL);
3548c2c66affSColin Finck             if (*pulLength == 0)
3549c2c66affSColin Finck                 ret = CR_FAILURE;
3550c2c66affSColin Finck         }
3551c2c66affSColin Finck         else
3552c2c66affSColin Finck         {
3553c2c66affSColin Finck             /* Directly copy the value */
3554c2c66affSColin Finck             if (LengthW <= *pulLength)
3555c2c66affSColin Finck                 memcpy(Buffer, BufferW, LengthW);
3556c2c66affSColin Finck             else
3557c2c66affSColin Finck             {
3558c2c66affSColin Finck                 *pulLength = LengthW;
3559c2c66affSColin Finck                 ret = CR_BUFFER_SMALL;
3560c2c66affSColin Finck             }
3561c2c66affSColin Finck         }
3562c2c66affSColin Finck     }
3563c2c66affSColin Finck 
3564c2c66affSColin Finck     if (pulRegDataType)
3565c2c66affSColin Finck         *pulRegDataType = ulDataType;
3566c2c66affSColin Finck 
3567c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, BufferW);
3568c2c66affSColin Finck 
3569c2c66affSColin Finck     return ret;
3570c2c66affSColin Finck }
3571c2c66affSColin Finck 
3572c2c66affSColin Finck 
3573c2c66affSColin Finck /***********************************************************************
3574c2c66affSColin Finck  * CM_Get_DevNode_Registry_Property_ExW [SETUPAPI.@]
3575c2c66affSColin Finck  */
357665d3bf74SEric Kohl CONFIGRET
357765d3bf74SEric Kohl WINAPI
357865d3bf74SEric Kohl CM_Get_DevNode_Registry_Property_ExW(
357965d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
358065d3bf74SEric Kohl     _In_ ULONG ulProperty,
358165d3bf74SEric Kohl     _Out_opt_ PULONG pulRegDataType,
358265d3bf74SEric Kohl     _Out_writes_bytes_opt_(*pulLength) PVOID Buffer,
358365d3bf74SEric Kohl     _Inout_ PULONG pulLength,
358465d3bf74SEric Kohl     _In_ ULONG ulFlags,
358565d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
3586c2c66affSColin Finck {
3587c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3588c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
3589c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
3590c2c66affSColin Finck     LPWSTR lpDevInst;
3591c2c66affSColin Finck     ULONG ulDataType = REG_NONE;
3592c2c66affSColin Finck     ULONG ulTransferLength = 0;
3593c2c66affSColin Finck 
359460a21894SEric Kohl     TRACE("CM_Get_DevNode_Registry_Property_ExW(%lx %lu %p %p %p %lx %p)\n",
3595c2c66affSColin Finck           dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength,
3596c2c66affSColin Finck           ulFlags, hMachine);
3597c2c66affSColin Finck 
3598c2c66affSColin Finck     if (dnDevInst == 0)
3599c2c66affSColin Finck         return CR_INVALID_DEVNODE;
3600c2c66affSColin Finck 
3601c2c66affSColin Finck     if (ulProperty < CM_DRP_MIN || ulProperty > CM_DRP_MAX)
3602c2c66affSColin Finck         return CR_INVALID_PROPERTY;
3603c2c66affSColin Finck 
3604c2c66affSColin Finck     /* pulRegDataType is optional */
3605c2c66affSColin Finck 
3606c2c66affSColin Finck     /* Buffer is optional */
3607c2c66affSColin Finck 
3608c2c66affSColin Finck     if (pulLength == NULL)
3609c2c66affSColin Finck         return CR_INVALID_POINTER;
3610c2c66affSColin Finck 
3611c2c66affSColin Finck     if (*pulLength == 0)
3612c2c66affSColin Finck         return CR_INVALID_POINTER;
3613c2c66affSColin Finck 
3614c2c66affSColin Finck     if (ulFlags != 0)
3615c2c66affSColin Finck         return CR_INVALID_FLAG;
3616c2c66affSColin Finck 
3617c2c66affSColin Finck     if (hMachine != NULL)
3618c2c66affSColin Finck     {
3619c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3620c2c66affSColin Finck         if (BindingHandle == NULL)
3621c2c66affSColin Finck             return CR_FAILURE;
3622c2c66affSColin Finck 
3623c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3624c2c66affSColin Finck         if (StringTable == 0)
3625c2c66affSColin Finck             return CR_FAILURE;
3626c2c66affSColin Finck     }
3627c2c66affSColin Finck     else
3628c2c66affSColin Finck     {
3629c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
3630c2c66affSColin Finck             return CR_FAILURE;
3631c2c66affSColin Finck     }
3632c2c66affSColin Finck 
3633c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
3634c2c66affSColin Finck     if (lpDevInst == NULL)
3635c2c66affSColin Finck         return CR_INVALID_DEVNODE;
3636c2c66affSColin Finck 
3637c2c66affSColin Finck     ulTransferLength = *pulLength;
3638c2c66affSColin Finck 
3639c2c66affSColin Finck     RpcTryExcept
3640c2c66affSColin Finck     {
3641c2c66affSColin Finck         ret = PNP_GetDeviceRegProp(BindingHandle,
3642c2c66affSColin Finck                                    lpDevInst,
3643c2c66affSColin Finck                                    ulProperty,
3644c2c66affSColin Finck                                    &ulDataType,
3645c2c66affSColin Finck                                    Buffer,
3646c2c66affSColin Finck                                    &ulTransferLength,
3647c2c66affSColin Finck                                    pulLength,
3648c2c66affSColin Finck                                    ulFlags);
3649c2c66affSColin Finck     }
3650c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3651c2c66affSColin Finck     {
3652c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3653c2c66affSColin Finck     }
3654c2c66affSColin Finck     RpcEndExcept;
3655c2c66affSColin Finck 
3656c2c66affSColin Finck     if (ret == CR_SUCCESS)
3657c2c66affSColin Finck     {
3658c2c66affSColin Finck         if (pulRegDataType != NULL)
3659c2c66affSColin Finck             *pulRegDataType = ulDataType;
3660c2c66affSColin Finck     }
3661c2c66affSColin Finck 
3662c2c66affSColin Finck     return ret;
3663c2c66affSColin Finck }
3664c2c66affSColin Finck 
3665c2c66affSColin Finck 
3666c2c66affSColin Finck /***********************************************************************
3667c2c66affSColin Finck  * CM_Get_DevNode_Status [SETUPAPI.@]
3668c2c66affSColin Finck  */
366965d3bf74SEric Kohl CONFIGRET
367065d3bf74SEric Kohl WINAPI
367165d3bf74SEric Kohl CM_Get_DevNode_Status(
367265d3bf74SEric Kohl     _Out_ PULONG pulStatus,
367365d3bf74SEric Kohl     _Out_ PULONG pulProblemNumber,
367465d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
367565d3bf74SEric Kohl     _In_ ULONG ulFlags)
3676c2c66affSColin Finck {
367765d3bf74SEric Kohl     TRACE("CM_Get_DevNode_Status(%p %p %lx %lx)\n",
3678c2c66affSColin Finck           pulStatus, pulProblemNumber, dnDevInst, ulFlags);
367965d3bf74SEric Kohl 
3680c2c66affSColin Finck     return CM_Get_DevNode_Status_Ex(pulStatus, pulProblemNumber, dnDevInst,
3681c2c66affSColin Finck                                     ulFlags, NULL);
3682c2c66affSColin Finck }
3683c2c66affSColin Finck 
3684c2c66affSColin Finck 
3685c2c66affSColin Finck /***********************************************************************
3686c2c66affSColin Finck  * CM_Get_DevNode_Status_Ex [SETUPAPI.@]
3687c2c66affSColin Finck  */
368865d3bf74SEric Kohl CONFIGRET
368965d3bf74SEric Kohl WINAPI
3690c2c66affSColin Finck CM_Get_DevNode_Status_Ex(
369165d3bf74SEric Kohl     _Out_ PULONG pulStatus,
369265d3bf74SEric Kohl     _Out_ PULONG pulProblemNumber,
369365d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
369465d3bf74SEric Kohl     _In_ ULONG ulFlags,
369565d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
3696c2c66affSColin Finck {
3697c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3698c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
3699c2c66affSColin Finck     LPWSTR lpDevInst;
3700c2c66affSColin Finck     CONFIGRET ret;
3701c2c66affSColin Finck 
370260a21894SEric Kohl     TRACE("CM_Get_DevNode_Status_Ex(%p %p %lx %lx %p)\n",
3703c2c66affSColin Finck           pulStatus, pulProblemNumber, dnDevInst, ulFlags, hMachine);
3704c2c66affSColin Finck 
3705c2c66affSColin Finck     if (pulStatus == NULL || pulProblemNumber == NULL)
3706c2c66affSColin Finck         return CR_INVALID_POINTER;
3707c2c66affSColin Finck 
3708c2c66affSColin Finck     if (dnDevInst == 0)
3709c2c66affSColin Finck         return CR_INVALID_DEVINST;
3710c2c66affSColin Finck 
3711c2c66affSColin Finck     if (ulFlags != 0)
3712c2c66affSColin Finck         return CR_INVALID_FLAG;
3713c2c66affSColin Finck 
3714c2c66affSColin Finck     if (hMachine != NULL)
3715c2c66affSColin Finck     {
3716c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3717c2c66affSColin Finck         if (BindingHandle == NULL)
3718c2c66affSColin Finck             return CR_FAILURE;
3719c2c66affSColin Finck 
3720c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3721c2c66affSColin Finck         if (StringTable == 0)
3722c2c66affSColin Finck             return CR_FAILURE;
3723c2c66affSColin Finck     }
3724c2c66affSColin Finck     else
3725c2c66affSColin Finck     {
3726c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
3727c2c66affSColin Finck             return CR_FAILURE;
3728c2c66affSColin Finck     }
3729c2c66affSColin Finck 
3730c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
3731c2c66affSColin Finck     if (lpDevInst == NULL)
3732c2c66affSColin Finck         return CR_INVALID_DEVNODE;
3733c2c66affSColin Finck 
3734c2c66affSColin Finck     RpcTryExcept
3735c2c66affSColin Finck     {
3736c2c66affSColin Finck         ret = PNP_GetDeviceStatus(BindingHandle,
3737c2c66affSColin Finck                                   lpDevInst,
3738c2c66affSColin Finck                                   pulStatus,
3739c2c66affSColin Finck                                   pulProblemNumber,
3740c2c66affSColin Finck                                   ulFlags);
3741c2c66affSColin Finck     }
3742c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3743c2c66affSColin Finck     {
3744c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
3745c2c66affSColin Finck     }
3746c2c66affSColin Finck     RpcEndExcept;
3747c2c66affSColin Finck 
3748c2c66affSColin Finck     return ret;
3749c2c66affSColin Finck }
3750c2c66affSColin Finck 
3751c2c66affSColin Finck 
3752c2c66affSColin Finck /***********************************************************************
3753c2c66affSColin Finck  * CM_Get_Device_IDA [SETUPAPI.@]
3754c2c66affSColin Finck  */
375565d3bf74SEric Kohl CONFIGRET
375665d3bf74SEric Kohl WINAPI
375765d3bf74SEric Kohl CM_Get_Device_IDA(
375865d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
375965d3bf74SEric Kohl     _Out_writes_(BufferLen) PCHAR Buffer,
376065d3bf74SEric Kohl     _In_ ULONG BufferLen,
376165d3bf74SEric Kohl     _In_ ULONG ulFlags)
3762c2c66affSColin Finck {
376360a21894SEric Kohl     TRACE("CM_Get_Device_IDA(%lx %p %lu %lx)\n",
3764c2c66affSColin Finck           dnDevInst, Buffer, BufferLen, ulFlags);
376565d3bf74SEric Kohl 
3766c2c66affSColin Finck     return CM_Get_Device_ID_ExA(dnDevInst, Buffer, BufferLen, ulFlags, NULL);
3767c2c66affSColin Finck }
3768c2c66affSColin Finck 
3769c2c66affSColin Finck 
3770c2c66affSColin Finck /***********************************************************************
3771c2c66affSColin Finck  * CM_Get_Device_IDW [SETUPAPI.@]
3772c2c66affSColin Finck  */
377365d3bf74SEric Kohl CONFIGRET
377465d3bf74SEric Kohl WINAPI
377565d3bf74SEric Kohl CM_Get_Device_IDW(
377665d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
377765d3bf74SEric Kohl     _Out_writes_(BufferLen) PWCHAR Buffer,
377865d3bf74SEric Kohl     _In_ ULONG BufferLen,
377965d3bf74SEric Kohl     _In_ ULONG ulFlags)
3780c2c66affSColin Finck {
378160a21894SEric Kohl     TRACE("CM_Get_Device_IDW(%lx %p %lu %lx)\n",
3782c2c66affSColin Finck           dnDevInst, Buffer, BufferLen, ulFlags);
378365d3bf74SEric Kohl 
3784c2c66affSColin Finck     return CM_Get_Device_ID_ExW(dnDevInst, Buffer, BufferLen, ulFlags, NULL);
3785c2c66affSColin Finck }
3786c2c66affSColin Finck 
3787c2c66affSColin Finck 
3788c2c66affSColin Finck /***********************************************************************
3789c2c66affSColin Finck  * CM_Get_Device_ID_ExA [SETUPAPI.@]
3790c2c66affSColin Finck  */
379165d3bf74SEric Kohl CONFIGRET
379265d3bf74SEric Kohl WINAPI
379365d3bf74SEric Kohl CM_Get_Device_ID_ExA(
379465d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
379565d3bf74SEric Kohl     _Out_writes_(BufferLen) PCHAR Buffer,
379665d3bf74SEric Kohl     _In_ ULONG BufferLen,
379765d3bf74SEric Kohl     _In_ ULONG ulFlags,
379865d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
3799c2c66affSColin Finck {
3800c2c66affSColin Finck     WCHAR szBufferW[MAX_DEVICE_ID_LEN];
3801c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
3802c2c66affSColin Finck 
380360a21894SEric Kohl     TRACE("CM_Get_Device_ID_ExA(%lx %p %lu %lx %p)\n",
3804c2c66affSColin Finck           dnDevInst, Buffer, BufferLen, ulFlags, hMachine);
3805c2c66affSColin Finck 
3806c2c66affSColin Finck     if (Buffer == NULL)
3807c2c66affSColin Finck         return CR_INVALID_POINTER;
3808c2c66affSColin Finck 
3809c2c66affSColin Finck     ret = CM_Get_Device_ID_ExW(dnDevInst,
3810c2c66affSColin Finck                                szBufferW,
3811c2c66affSColin Finck                                MAX_DEVICE_ID_LEN,
3812c2c66affSColin Finck                                ulFlags,
3813c2c66affSColin Finck                                hMachine);
3814c2c66affSColin Finck     if (ret == CR_SUCCESS)
3815c2c66affSColin Finck     {
3816c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
3817c2c66affSColin Finck                                 0,
3818c2c66affSColin Finck                                 szBufferW,
3819c2c66affSColin Finck                                 lstrlenW(szBufferW) + 1,
3820c2c66affSColin Finck                                 Buffer,
3821c2c66affSColin Finck                                 BufferLen,
3822c2c66affSColin Finck                                 NULL,
3823c2c66affSColin Finck                                 NULL) == 0)
3824c2c66affSColin Finck             ret = CR_FAILURE;
3825c2c66affSColin Finck     }
3826c2c66affSColin Finck 
3827c2c66affSColin Finck     return ret;
3828c2c66affSColin Finck }
3829c2c66affSColin Finck 
3830c2c66affSColin Finck 
3831c2c66affSColin Finck /***********************************************************************
3832c2c66affSColin Finck  * CM_Get_Device_ID_ExW [SETUPAPI.@]
3833c2c66affSColin Finck  */
383465d3bf74SEric Kohl CONFIGRET
383565d3bf74SEric Kohl WINAPI
383665d3bf74SEric Kohl CM_Get_Device_ID_ExW(
383765d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
383865d3bf74SEric Kohl     _Out_writes_(BufferLen) PWCHAR Buffer,
383965d3bf74SEric Kohl     _In_ ULONG BufferLen,
384065d3bf74SEric Kohl     _In_ ULONG ulFlags,
384165d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
3842c2c66affSColin Finck {
3843c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
3844c2c66affSColin Finck 
384560a21894SEric Kohl     TRACE("CM_Get_Device_ID_ExW(%lx %p %lu %lx %p)\n",
3846c2c66affSColin Finck           dnDevInst, Buffer, BufferLen, ulFlags, hMachine);
3847c2c66affSColin Finck 
3848c2c66affSColin Finck     if (dnDevInst == 0)
3849c2c66affSColin Finck         return CR_INVALID_DEVINST;
3850c2c66affSColin Finck 
3851c2c66affSColin Finck     if (Buffer == NULL)
3852c2c66affSColin Finck         return CR_INVALID_POINTER;
3853c2c66affSColin Finck 
3854c2c66affSColin Finck     if (ulFlags != 0)
3855c2c66affSColin Finck         return CR_INVALID_FLAG;
3856c2c66affSColin Finck 
3857c2c66affSColin Finck     if (hMachine != NULL)
3858c2c66affSColin Finck     {
3859c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3860c2c66affSColin Finck         if (StringTable == NULL)
3861c2c66affSColin Finck             return CR_FAILURE;
3862c2c66affSColin Finck     }
3863c2c66affSColin Finck     else
3864c2c66affSColin Finck     {
3865c2c66affSColin Finck         if (!PnpGetLocalHandles(NULL, &StringTable))
3866c2c66affSColin Finck             return CR_FAILURE;
3867c2c66affSColin Finck     }
3868c2c66affSColin Finck 
3869c2c66affSColin Finck     if (!pSetupStringTableStringFromIdEx(StringTable,
3870c2c66affSColin Finck                                          dnDevInst,
3871c2c66affSColin Finck                                          Buffer,
3872c2c66affSColin Finck                                          &BufferLen))
3873c2c66affSColin Finck         return CR_FAILURE;
3874c2c66affSColin Finck 
3875c2c66affSColin Finck     return CR_SUCCESS;
3876c2c66affSColin Finck }
3877c2c66affSColin Finck 
3878c2c66affSColin Finck 
3879c2c66affSColin Finck /***********************************************************************
3880c2c66affSColin Finck  * CM_Get_Device_ID_ListA [SETUPAPI.@]
3881c2c66affSColin Finck  */
388265d3bf74SEric Kohl CONFIGRET
388365d3bf74SEric Kohl WINAPI
388465d3bf74SEric Kohl CM_Get_Device_ID_ListA(
388565d3bf74SEric Kohl     _In_ PCSTR pszFilter,
388665d3bf74SEric Kohl     _Out_writes_(BufferLen) PCHAR Buffer,
388765d3bf74SEric Kohl     _In_ ULONG BufferLen,
388865d3bf74SEric Kohl     _In_ ULONG ulFlags)
3889c2c66affSColin Finck {
389060a21894SEric Kohl     TRACE("CM_Get_Device_ID_ListA(%p %p %lu %lx)\n",
389165d3bf74SEric Kohl           pszFilter, Buffer, BufferLen, ulFlags);
389265d3bf74SEric Kohl 
3893c2c66affSColin Finck     return CM_Get_Device_ID_List_ExA(pszFilter, Buffer, BufferLen,
3894c2c66affSColin Finck                                      ulFlags, NULL);
3895c2c66affSColin Finck }
3896c2c66affSColin Finck 
3897c2c66affSColin Finck 
3898c2c66affSColin Finck /***********************************************************************
3899c2c66affSColin Finck  * CM_Get_Device_ID_ListW [SETUPAPI.@]
3900c2c66affSColin Finck  */
390165d3bf74SEric Kohl CONFIGRET
390265d3bf74SEric Kohl WINAPI
390365d3bf74SEric Kohl CM_Get_Device_ID_ListW(
390465d3bf74SEric Kohl     _In_ PCWSTR pszFilter,
390565d3bf74SEric Kohl     _Out_writes_(BufferLen) PWCHAR Buffer,
390665d3bf74SEric Kohl     _In_ ULONG BufferLen,
390765d3bf74SEric Kohl     _In_ ULONG ulFlags)
3908c2c66affSColin Finck {
390960a21894SEric Kohl     TRACE("CM_Get_Device_ID_ListW(%p %p %lu %lx)\n",
391065d3bf74SEric Kohl           pszFilter, Buffer, BufferLen, ulFlags);
391165d3bf74SEric Kohl 
3912c2c66affSColin Finck     return CM_Get_Device_ID_List_ExW(pszFilter, Buffer, BufferLen,
3913c2c66affSColin Finck                                      ulFlags, NULL);
3914c2c66affSColin Finck }
3915c2c66affSColin Finck 
3916c2c66affSColin Finck 
3917c2c66affSColin Finck /***********************************************************************
3918c2c66affSColin Finck  * CM_Get_Device_ID_List_ExA [SETUPAPI.@]
3919c2c66affSColin Finck  */
392065d3bf74SEric Kohl CONFIGRET
392165d3bf74SEric Kohl WINAPI
392265d3bf74SEric Kohl CM_Get_Device_ID_List_ExA(
392365d3bf74SEric Kohl     _In_ PCSTR pszFilter,
392465d3bf74SEric Kohl     _Out_writes_(BufferLen) PCHAR Buffer,
392565d3bf74SEric Kohl     _In_ ULONG BufferLen,
392665d3bf74SEric Kohl     _In_ ULONG ulFlags,
392765d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
3928c2c66affSColin Finck {
3929c2c66affSColin Finck     LPWSTR BufferW = NULL;
3930c2c66affSColin Finck     LPWSTR pszFilterW = NULL;
3931c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
3932c2c66affSColin Finck 
393360a21894SEric Kohl     TRACE("CM_Get_Device_ID_List_ExA(%p %p %lu %lx %p)\n",
3934c2c66affSColin Finck           pszFilter, Buffer, BufferLen, ulFlags, hMachine);
3935c2c66affSColin Finck 
3936c2c66affSColin Finck     BufferW = MyMalloc(BufferLen * sizeof(WCHAR));
3937c2c66affSColin Finck     if (BufferW == NULL)
3938c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
3939c2c66affSColin Finck 
3940c2c66affSColin Finck     if (pszFilter == NULL)
3941c2c66affSColin Finck     {
3942c2c66affSColin Finck         ret = CM_Get_Device_ID_List_ExW(NULL,
3943c2c66affSColin Finck                                         BufferW,
3944c2c66affSColin Finck                                         BufferLen,
3945c2c66affSColin Finck                                         ulFlags,
3946c2c66affSColin Finck                                         hMachine);
3947c2c66affSColin Finck     }
3948c2c66affSColin Finck     else
3949c2c66affSColin Finck     {
3950c2c66affSColin Finck         if (pSetupCaptureAndConvertAnsiArg(pszFilter, &pszFilterW))
3951c2c66affSColin Finck         {
3952c2c66affSColin Finck             ret = CR_INVALID_DEVICE_ID;
3953c2c66affSColin Finck             goto Done;
3954c2c66affSColin Finck         }
3955c2c66affSColin Finck 
3956c2c66affSColin Finck         ret = CM_Get_Device_ID_List_ExW(pszFilterW,
3957c2c66affSColin Finck                                         BufferW,
3958c2c66affSColin Finck                                         BufferLen,
3959c2c66affSColin Finck                                         ulFlags,
3960c2c66affSColin Finck                                         hMachine);
3961c2c66affSColin Finck 
3962c2c66affSColin Finck         MyFree(pszFilterW);
3963c2c66affSColin Finck     }
3964c2c66affSColin Finck 
3965c2c66affSColin Finck     if (WideCharToMultiByte(CP_ACP,
3966c2c66affSColin Finck                             0,
3967c2c66affSColin Finck                             BufferW,
3968aa056499SVictor Perevertkin                             BufferLen,
3969c2c66affSColin Finck                             Buffer,
3970c2c66affSColin Finck                             BufferLen,
3971c2c66affSColin Finck                             NULL,
3972c2c66affSColin Finck                             NULL) == 0)
3973c2c66affSColin Finck         ret = CR_FAILURE;
3974c2c66affSColin Finck 
3975c2c66affSColin Finck Done:
3976c2c66affSColin Finck     MyFree(BufferW);
3977c2c66affSColin Finck 
3978c2c66affSColin Finck     return ret;
3979c2c66affSColin Finck }
3980c2c66affSColin Finck 
3981c2c66affSColin Finck 
3982c2c66affSColin Finck /***********************************************************************
3983c2c66affSColin Finck  * CM_Get_Device_ID_List_ExW [SETUPAPI.@]
3984c2c66affSColin Finck  */
398565d3bf74SEric Kohl CONFIGRET
398665d3bf74SEric Kohl WINAPI
398765d3bf74SEric Kohl CM_Get_Device_ID_List_ExW(
398865d3bf74SEric Kohl     _In_ PCWSTR pszFilter,
398965d3bf74SEric Kohl     _Out_writes_(BufferLen) PWCHAR Buffer,
399065d3bf74SEric Kohl     _In_ ULONG BufferLen,
399165d3bf74SEric Kohl     _In_ ULONG ulFlags,
399265d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
3993c2c66affSColin Finck {
3994c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
3995c2c66affSColin Finck     CONFIGRET ret;
3996c2c66affSColin Finck 
399760a21894SEric Kohl     TRACE("CM_Get_Device_ID_List_ExW(%p %p %lu %lx %p)\n",
3998c2c66affSColin Finck           pszFilter, Buffer, BufferLen, ulFlags, hMachine);
3999c2c66affSColin Finck 
4000c2c66affSColin Finck     if (Buffer == NULL || BufferLen == 0)
4001c2c66affSColin Finck         return CR_INVALID_POINTER;
4002c2c66affSColin Finck 
4003c2c66affSColin Finck     if (ulFlags & ~CM_GETIDLIST_FILTER_BITS)
4004c2c66affSColin Finck         return CR_INVALID_FLAG;
4005c2c66affSColin Finck 
4006c2c66affSColin Finck     if (hMachine != NULL)
4007c2c66affSColin Finck     {
4008c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4009c2c66affSColin Finck         if (BindingHandle == NULL)
4010c2c66affSColin Finck             return CR_FAILURE;
4011c2c66affSColin Finck     }
4012c2c66affSColin Finck     else
4013c2c66affSColin Finck     {
4014c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
4015c2c66affSColin Finck             return CR_FAILURE;
4016c2c66affSColin Finck     }
4017c2c66affSColin Finck 
4018c2c66affSColin Finck     *Buffer = 0;
4019c2c66affSColin Finck 
4020c2c66affSColin Finck     RpcTryExcept
4021c2c66affSColin Finck     {
4022c2c66affSColin Finck         ret = PNP_GetDeviceList(BindingHandle,
4023c2c66affSColin Finck                                 (LPWSTR)pszFilter,
4024c2c66affSColin Finck                                 Buffer,
4025c2c66affSColin Finck                                 &BufferLen,
4026c2c66affSColin Finck                                 ulFlags);
4027c2c66affSColin Finck     }
4028c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4029c2c66affSColin Finck     {
4030c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4031c2c66affSColin Finck     }
4032c2c66affSColin Finck     RpcEndExcept;
4033c2c66affSColin Finck 
4034c2c66affSColin Finck     return ret;
4035c2c66affSColin Finck }
4036c2c66affSColin Finck 
4037c2c66affSColin Finck 
4038c2c66affSColin Finck /***********************************************************************
4039c2c66affSColin Finck  * CM_Get_Device_ID_List_SizeA [SETUPAPI.@]
4040c2c66affSColin Finck  */
404165d3bf74SEric Kohl CONFIGRET
404265d3bf74SEric Kohl WINAPI
404365d3bf74SEric Kohl CM_Get_Device_ID_List_SizeA(
404465d3bf74SEric Kohl     _Out_ PULONG pulLen,
404565d3bf74SEric Kohl     _In_opt_ PCSTR pszFilter,
404665d3bf74SEric Kohl     _In_ ULONG ulFlags)
4047c2c66affSColin Finck {
404865d3bf74SEric Kohl     TRACE("CM_Get_Device_ID_List_SizeA(%p %s %lx)\n",
404965d3bf74SEric Kohl           pulLen, debugstr_a(pszFilter), ulFlags);
405065d3bf74SEric Kohl 
4051c2c66affSColin Finck     return CM_Get_Device_ID_List_Size_ExA(pulLen, pszFilter, ulFlags, NULL);
4052c2c66affSColin Finck }
4053c2c66affSColin Finck 
4054c2c66affSColin Finck 
4055c2c66affSColin Finck /***********************************************************************
4056c2c66affSColin Finck  * CM_Get_Device_ID_List_SizeW [SETUPAPI.@]
4057c2c66affSColin Finck  */
405865d3bf74SEric Kohl CONFIGRET
405965d3bf74SEric Kohl WINAPI
406065d3bf74SEric Kohl CM_Get_Device_ID_List_SizeW(
406165d3bf74SEric Kohl     _Out_ PULONG pulLen,
406265d3bf74SEric Kohl     _In_opt_ PCWSTR pszFilter,
406365d3bf74SEric Kohl     _In_ ULONG ulFlags)
4064c2c66affSColin Finck {
406565d3bf74SEric Kohl     TRACE("CM_Get_Device_ID_List_SizeW(%p %s %lx)\n",
406665d3bf74SEric Kohl           pulLen, debugstr_w(pszFilter), ulFlags);
406765d3bf74SEric Kohl 
4068c2c66affSColin Finck     return CM_Get_Device_ID_List_Size_ExW(pulLen, pszFilter, ulFlags, NULL);
4069c2c66affSColin Finck }
4070c2c66affSColin Finck 
4071c2c66affSColin Finck 
4072c2c66affSColin Finck /***********************************************************************
4073c2c66affSColin Finck  * CM_Get_Device_ID_List_Size_ExA [SETUPAPI.@]
4074c2c66affSColin Finck  */
407565d3bf74SEric Kohl CONFIGRET
407665d3bf74SEric Kohl WINAPI
407765d3bf74SEric Kohl CM_Get_Device_ID_List_Size_ExA(
407865d3bf74SEric Kohl     _Out_ PULONG pulLen,
407965d3bf74SEric Kohl     _In_opt_ PCSTR pszFilter,
408065d3bf74SEric Kohl     _In_ ULONG ulFlags,
408165d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4082c2c66affSColin Finck {
4083c2c66affSColin Finck     LPWSTR pszFilterW = NULL;
4084c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
4085c2c66affSColin Finck 
408660a21894SEric Kohl     FIXME("CM_Get_Device_ID_List_Size_ExA(%p %s %lx %p)\n",
408765d3bf74SEric Kohl           pulLen, debugstr_a(pszFilter), ulFlags, hMachine);
4088c2c66affSColin Finck 
4089c2c66affSColin Finck     if (pszFilter == NULL)
4090c2c66affSColin Finck     {
4091c2c66affSColin Finck         ret = CM_Get_Device_ID_List_Size_ExW(pulLen,
4092c2c66affSColin Finck                                              NULL,
4093c2c66affSColin Finck                                              ulFlags,
4094c2c66affSColin Finck                                              hMachine);
4095c2c66affSColin Finck     }
4096c2c66affSColin Finck     else
4097c2c66affSColin Finck     {
4098c2c66affSColin Finck         if (pSetupCaptureAndConvertAnsiArg(pszFilter, &pszFilterW))
4099c2c66affSColin Finck             return CR_INVALID_DEVICE_ID;
4100c2c66affSColin Finck 
4101c2c66affSColin Finck         ret = CM_Get_Device_ID_List_Size_ExW(pulLen,
4102c2c66affSColin Finck                                              pszFilterW,
4103c2c66affSColin Finck                                              ulFlags,
4104c2c66affSColin Finck                                              hMachine);
4105c2c66affSColin Finck 
4106c2c66affSColin Finck         MyFree(pszFilterW);
4107c2c66affSColin Finck     }
4108c2c66affSColin Finck 
4109c2c66affSColin Finck     return ret;
4110c2c66affSColin Finck }
4111c2c66affSColin Finck 
4112c2c66affSColin Finck 
4113c2c66affSColin Finck /***********************************************************************
4114c2c66affSColin Finck  * CM_Get_Device_ID_List_Size_ExW [SETUPAPI.@]
4115c2c66affSColin Finck  */
411665d3bf74SEric Kohl CONFIGRET
411765d3bf74SEric Kohl WINAPI
411865d3bf74SEric Kohl CM_Get_Device_ID_List_Size_ExW(
411965d3bf74SEric Kohl     _Out_ PULONG pulLen,
412065d3bf74SEric Kohl     _In_opt_ PCWSTR pszFilter,
412165d3bf74SEric Kohl     _In_ ULONG ulFlags,
412265d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4123c2c66affSColin Finck {
4124c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4125c2c66affSColin Finck     CONFIGRET ret;
4126c2c66affSColin Finck 
412760a21894SEric Kohl     FIXME("CM_Get_Device_ID_List_Size_ExW(%p %s %lx %p)\n",
412865d3bf74SEric Kohl           pulLen, debugstr_w(pszFilter), ulFlags, hMachine);
4129c2c66affSColin Finck 
4130c2c66affSColin Finck     if (pulLen == NULL)
4131c2c66affSColin Finck         return CR_INVALID_POINTER;
4132c2c66affSColin Finck 
4133c2c66affSColin Finck     if (ulFlags & ~CM_GETIDLIST_FILTER_BITS)
4134c2c66affSColin Finck         return CR_INVALID_FLAG;
4135c2c66affSColin Finck 
4136c2c66affSColin Finck     if (hMachine != NULL)
4137c2c66affSColin Finck     {
4138c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4139c2c66affSColin Finck         if (BindingHandle == NULL)
4140c2c66affSColin Finck             return CR_FAILURE;
4141c2c66affSColin Finck     }
4142c2c66affSColin Finck     else
4143c2c66affSColin Finck     {
4144c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
4145c2c66affSColin Finck             return CR_FAILURE;
4146c2c66affSColin Finck     }
4147c2c66affSColin Finck 
4148c2c66affSColin Finck     *pulLen = 0;
4149c2c66affSColin Finck 
4150c2c66affSColin Finck     RpcTryExcept
4151c2c66affSColin Finck     {
4152c2c66affSColin Finck         ret = PNP_GetDeviceListSize(BindingHandle,
4153c2c66affSColin Finck                                     (LPWSTR)pszFilter,
4154c2c66affSColin Finck                                     pulLen,
4155c2c66affSColin Finck                                     ulFlags);
4156c2c66affSColin Finck     }
4157c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4158c2c66affSColin Finck     {
4159c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4160c2c66affSColin Finck     }
4161c2c66affSColin Finck     RpcEndExcept;
4162c2c66affSColin Finck 
4163c2c66affSColin Finck     return ret;
4164c2c66affSColin Finck }
4165c2c66affSColin Finck 
4166c2c66affSColin Finck 
4167c2c66affSColin Finck /***********************************************************************
4168c2c66affSColin Finck  * CM_Get_Device_ID_Size [SETUPAPI.@]
4169c2c66affSColin Finck  */
417065d3bf74SEric Kohl CONFIGRET
417165d3bf74SEric Kohl WINAPI
417265d3bf74SEric Kohl CM_Get_Device_ID_Size(
417365d3bf74SEric Kohl     _Out_ PULONG pulLen,
417465d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
417565d3bf74SEric Kohl     _In_ ULONG ulFlags)
4176c2c66affSColin Finck {
417765d3bf74SEric Kohl     TRACE("CM_Get_Device_ID_Size(%p %lx %lx)\n",
417865d3bf74SEric Kohl           pulLen, dnDevInst, ulFlags);
417965d3bf74SEric Kohl 
4180c2c66affSColin Finck     return CM_Get_Device_ID_Size_Ex(pulLen, dnDevInst, ulFlags, NULL);
4181c2c66affSColin Finck }
4182c2c66affSColin Finck 
4183c2c66affSColin Finck 
4184c2c66affSColin Finck /***********************************************************************
4185c2c66affSColin Finck  * CM_Get_Device_ID_Size_Ex [SETUPAPI.@]
4186c2c66affSColin Finck  */
418765d3bf74SEric Kohl CONFIGRET
418865d3bf74SEric Kohl WINAPI
418965d3bf74SEric Kohl CM_Get_Device_ID_Size_Ex(
419065d3bf74SEric Kohl     _Out_ PULONG pulLen,
419165d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
419265d3bf74SEric Kohl     _In_ ULONG ulFlags,
419365d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4194c2c66affSColin Finck {
4195c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
4196c2c66affSColin Finck     LPWSTR DeviceId;
4197c2c66affSColin Finck 
419860a21894SEric Kohl     TRACE("CM_Get_Device_ID_Size_Ex(%p %lx %lx %p)\n",
419965d3bf74SEric Kohl           pulLen, dnDevInst, ulFlags, hMachine);
4200c2c66affSColin Finck 
4201c2c66affSColin Finck     if (pulLen == NULL)
4202c2c66affSColin Finck         return CR_INVALID_POINTER;
4203c2c66affSColin Finck 
4204c2c66affSColin Finck     if (dnDevInst == 0)
4205c2c66affSColin Finck         return CR_INVALID_DEVINST;
4206c2c66affSColin Finck 
4207c2c66affSColin Finck     if (ulFlags != 0)
4208c2c66affSColin Finck         return CR_INVALID_FLAG;
4209c2c66affSColin Finck 
4210c2c66affSColin Finck     if (hMachine != NULL)
4211c2c66affSColin Finck     {
4212c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
4213c2c66affSColin Finck         if (StringTable == NULL)
4214c2c66affSColin Finck             return CR_FAILURE;
4215c2c66affSColin Finck     }
4216c2c66affSColin Finck     else
4217c2c66affSColin Finck     {
4218c2c66affSColin Finck         if (!PnpGetLocalHandles(NULL, &StringTable))
4219c2c66affSColin Finck             return CR_FAILURE;
4220c2c66affSColin Finck     }
4221c2c66affSColin Finck 
4222c2c66affSColin Finck     DeviceId = pSetupStringTableStringFromId(StringTable, dnDevInst);
4223c2c66affSColin Finck     if (DeviceId == NULL)
4224c2c66affSColin Finck     {
4225c2c66affSColin Finck         *pulLen = 0;
4226c2c66affSColin Finck         return CR_SUCCESS;
4227c2c66affSColin Finck     }
4228c2c66affSColin Finck 
4229c2c66affSColin Finck     *pulLen = lstrlenW(DeviceId);
4230c2c66affSColin Finck 
4231c2c66affSColin Finck     return CR_SUCCESS;
4232c2c66affSColin Finck }
4233c2c66affSColin Finck 
4234c2c66affSColin Finck 
4235c2c66affSColin Finck /***********************************************************************
4236c2c66affSColin Finck  * CM_Get_Device_Interface_AliasA [SETUPAPI.@]
4237c2c66affSColin Finck  */
423865d3bf74SEric Kohl CONFIGRET
423965d3bf74SEric Kohl WINAPI
424065d3bf74SEric Kohl CM_Get_Device_Interface_AliasA(
424165d3bf74SEric Kohl     _In_ LPCSTR pszDeviceInterface,
424265d3bf74SEric Kohl     _In_ LPGUID AliasInterfaceGuid,
424365d3bf74SEric Kohl     _Out_writes_(*pulLength) LPSTR pszAliasDeviceInterface,
424465d3bf74SEric Kohl     _Inout_ PULONG pulLength,
424565d3bf74SEric Kohl     _In_ ULONG ulFlags)
4246c2c66affSColin Finck {
424765d3bf74SEric Kohl     TRACE("CM_Get_Device_Interface_AliasA(%p %p %p %p %lx)\n",
424865d3bf74SEric Kohl           pszDeviceInterface, AliasInterfaceGuid,
4249c2c66affSColin Finck           pszAliasDeviceInterface, pulLength, ulFlags);
4250c2c66affSColin Finck 
4251c2c66affSColin Finck     return CM_Get_Device_Interface_Alias_ExA(pszDeviceInterface,
4252c2c66affSColin Finck         AliasInterfaceGuid, pszAliasDeviceInterface, pulLength,
4253c2c66affSColin Finck         ulFlags, NULL);
4254c2c66affSColin Finck }
4255c2c66affSColin Finck 
4256c2c66affSColin Finck 
4257c2c66affSColin Finck /***********************************************************************
4258c2c66affSColin Finck  * CM_Get_Device_Interface_AliasW [SETUPAPI.@]
4259c2c66affSColin Finck  */
426065d3bf74SEric Kohl CONFIGRET
426165d3bf74SEric Kohl WINAPI
426265d3bf74SEric Kohl CM_Get_Device_Interface_AliasW(
426365d3bf74SEric Kohl     _In_ LPCWSTR pszDeviceInterface,
426465d3bf74SEric Kohl     _In_ LPGUID AliasInterfaceGuid,
426565d3bf74SEric Kohl     _Out_writes_(*pulLength) LPWSTR pszAliasDeviceInterface,
426665d3bf74SEric Kohl     _Inout_ PULONG pulLength,
426765d3bf74SEric Kohl     _In_ ULONG ulFlags)
4268c2c66affSColin Finck {
426965d3bf74SEric Kohl     TRACE("CM_Get_Device_Interface_AliasW(%p %p %p %p %lx)\n",
427065d3bf74SEric Kohl           pszDeviceInterface, AliasInterfaceGuid,
4271c2c66affSColin Finck           pszAliasDeviceInterface, pulLength, ulFlags);
4272c2c66affSColin Finck 
4273c2c66affSColin Finck     return CM_Get_Device_Interface_Alias_ExW(pszDeviceInterface,
4274c2c66affSColin Finck         AliasInterfaceGuid, pszAliasDeviceInterface, pulLength,
4275c2c66affSColin Finck         ulFlags, NULL);
4276c2c66affSColin Finck }
4277c2c66affSColin Finck 
4278c2c66affSColin Finck 
4279c2c66affSColin Finck /***********************************************************************
4280c2c66affSColin Finck  * CM_Get_Device_Interface_Alias_ExA [SETUPAPI.@]
4281c2c66affSColin Finck  */
428265d3bf74SEric Kohl CONFIGRET
428365d3bf74SEric Kohl WINAPI
428465d3bf74SEric Kohl CM_Get_Device_Interface_Alias_ExA(
428565d3bf74SEric Kohl     _In_ LPCSTR pszDeviceInterface,
428665d3bf74SEric Kohl     _In_ LPGUID AliasInterfaceGuid,
428765d3bf74SEric Kohl     _Out_writes_(*pulLength) LPSTR pszAliasDeviceInterface,
428865d3bf74SEric Kohl     _Inout_ PULONG pulLength,
428965d3bf74SEric Kohl     _In_ ULONG ulFlags,
429065d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4291c2c66affSColin Finck {
429260a21894SEric Kohl     FIXME("CM_Get_Device_Interface_Alias_ExA(%p %p %p %p %lx %p)\n",
429365d3bf74SEric Kohl           pszDeviceInterface, AliasInterfaceGuid,
4294c2c66affSColin Finck           pszAliasDeviceInterface, pulLength, ulFlags, hMachine);
4295c2c66affSColin Finck 
4296c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
4297c2c66affSColin Finck }
4298c2c66affSColin Finck 
4299c2c66affSColin Finck 
4300c2c66affSColin Finck /***********************************************************************
4301c2c66affSColin Finck  * CM_Get_Device_Interface_Alias_ExW [SETUPAPI.@]
4302c2c66affSColin Finck  */
430365d3bf74SEric Kohl CONFIGRET
430465d3bf74SEric Kohl WINAPI
430565d3bf74SEric Kohl CM_Get_Device_Interface_Alias_ExW(
430665d3bf74SEric Kohl     _In_ LPCWSTR pszDeviceInterface,
430765d3bf74SEric Kohl     _In_ LPGUID AliasInterfaceGuid,
430865d3bf74SEric Kohl     _Out_writes_(*pulLength) LPWSTR pszAliasDeviceInterface,
430965d3bf74SEric Kohl     _Inout_ PULONG pulLength,
431065d3bf74SEric Kohl     _In_ ULONG ulFlags,
431165d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4312c2c66affSColin Finck {
4313c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4314c2c66affSColin Finck     ULONG ulTransferLength;
4315c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
4316c2c66affSColin Finck 
431760a21894SEric Kohl     TRACE("CM_Get_Device_Interface_Alias_ExW(%p %p %p %p %lx %p)\n",
431865d3bf74SEric Kohl           pszDeviceInterface, AliasInterfaceGuid,
4319c2c66affSColin Finck           pszAliasDeviceInterface, pulLength, ulFlags, hMachine);
4320c2c66affSColin Finck 
4321c2c66affSColin Finck     if (pszDeviceInterface == NULL ||
4322c2c66affSColin Finck         AliasInterfaceGuid == NULL ||
4323c2c66affSColin Finck         pszAliasDeviceInterface == NULL ||
4324c2c66affSColin Finck         pulLength == NULL)
4325c2c66affSColin Finck         return CR_INVALID_POINTER;
4326c2c66affSColin Finck 
4327c2c66affSColin Finck     if (ulFlags != 0)
4328c2c66affSColin Finck         return CR_INVALID_FLAG;
4329c2c66affSColin Finck 
4330c2c66affSColin Finck     if (hMachine != NULL)
4331c2c66affSColin Finck     {
4332c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4333c2c66affSColin Finck         if (BindingHandle == NULL)
4334c2c66affSColin Finck             return CR_FAILURE;
4335c2c66affSColin Finck     }
4336c2c66affSColin Finck     else
4337c2c66affSColin Finck     {
4338c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
4339c2c66affSColin Finck             return CR_FAILURE;
4340c2c66affSColin Finck     }
4341c2c66affSColin Finck 
4342c2c66affSColin Finck     ulTransferLength = *pulLength;
4343c2c66affSColin Finck 
4344c2c66affSColin Finck     RpcTryExcept
4345c2c66affSColin Finck     {
4346c2c66affSColin Finck         ret = PNP_GetInterfaceDeviceAlias(BindingHandle,
4347c2c66affSColin Finck                                           (LPWSTR)pszDeviceInterface,
4348c2c66affSColin Finck                                           AliasInterfaceGuid,
4349c2c66affSColin Finck                                           pszAliasDeviceInterface,
4350c2c66affSColin Finck                                           pulLength,
4351c2c66affSColin Finck                                           &ulTransferLength,
4352c2c66affSColin Finck                                           0);
4353c2c66affSColin Finck     }
4354c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4355c2c66affSColin Finck     {
4356c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4357c2c66affSColin Finck     }
4358c2c66affSColin Finck     RpcEndExcept;
4359c2c66affSColin Finck 
4360c2c66affSColin Finck     return ret;
4361c2c66affSColin Finck }
4362c2c66affSColin Finck 
4363c2c66affSColin Finck 
4364c2c66affSColin Finck /***********************************************************************
4365c2c66affSColin Finck  *      CM_Get_Device_Interface_ListA (SETUPAPI.@)
4366c2c66affSColin Finck  */
436765d3bf74SEric Kohl CONFIGRET
436865d3bf74SEric Kohl WINAPI
436965d3bf74SEric Kohl CM_Get_Device_Interface_ListA(
437065d3bf74SEric Kohl     _In_ LPGUID InterfaceClassGuid,
437165d3bf74SEric Kohl     _In_opt_ DEVINSTID_A pDeviceID,
437265d3bf74SEric Kohl     _Out_writes_(BufferLen) PCHAR Buffer,
437365d3bf74SEric Kohl     _In_ ULONG BufferLen,
437465d3bf74SEric Kohl     _In_ ULONG ulFlags)
4375c2c66affSColin Finck {
437665d3bf74SEric Kohl     TRACE("CM_Get_Device_Interface_ListA(%s %s %p %lu 0x%08lx)\n",
437765d3bf74SEric Kohl           debugstr_guid(InterfaceClassGuid), debugstr_a(pDeviceID),
437865d3bf74SEric Kohl           Buffer, BufferLen, ulFlags);
4379c2c66affSColin Finck 
4380c2c66affSColin Finck     return CM_Get_Device_Interface_List_ExA(InterfaceClassGuid, pDeviceID,
4381c2c66affSColin Finck                                             Buffer, BufferLen, ulFlags, NULL);
4382c2c66affSColin Finck }
4383c2c66affSColin Finck 
4384c2c66affSColin Finck 
4385c2c66affSColin Finck /***********************************************************************
4386c2c66affSColin Finck  *      CM_Get_Device_Interface_ListW (SETUPAPI.@)
4387c2c66affSColin Finck  */
438865d3bf74SEric Kohl CONFIGRET
438965d3bf74SEric Kohl WINAPI
439065d3bf74SEric Kohl CM_Get_Device_Interface_ListW(
439165d3bf74SEric Kohl     _In_ LPGUID InterfaceClassGuid,
439265d3bf74SEric Kohl     _In_opt_ DEVINSTID_W pDeviceID,
439365d3bf74SEric Kohl     _Out_writes_(BufferLen) PWCHAR Buffer,
439465d3bf74SEric Kohl     _In_ ULONG BufferLen,
439565d3bf74SEric Kohl     _In_ ULONG ulFlags)
4396c2c66affSColin Finck {
439765d3bf74SEric Kohl     TRACE("CM_Get_Device_Interface_ListW(%s %s %p %lu 0x%08lx)\n",
439865d3bf74SEric Kohl           debugstr_guid(InterfaceClassGuid), debugstr_w(pDeviceID),
439965d3bf74SEric Kohl           Buffer, BufferLen, ulFlags);
4400c2c66affSColin Finck 
4401c2c66affSColin Finck     return CM_Get_Device_Interface_List_ExW(InterfaceClassGuid, pDeviceID,
4402c2c66affSColin Finck                                             Buffer, BufferLen, ulFlags, NULL);
4403c2c66affSColin Finck }
4404c2c66affSColin Finck 
4405c2c66affSColin Finck 
4406c2c66affSColin Finck /***********************************************************************
4407c2c66affSColin Finck  *      CM_Get_Device_Interface_List_ExA (SETUPAPI.@)
4408c2c66affSColin Finck  */
440965d3bf74SEric Kohl CONFIGRET
441065d3bf74SEric Kohl WINAPI
441165d3bf74SEric Kohl CM_Get_Device_Interface_List_ExA(
441265d3bf74SEric Kohl     _In_ LPGUID InterfaceClassGuid,
441365d3bf74SEric Kohl     _In_opt_ DEVINSTID_A pDeviceID,
441465d3bf74SEric Kohl     _Out_writes_(BufferLen) PCHAR Buffer,
441565d3bf74SEric Kohl     _In_ ULONG BufferLen,
441665d3bf74SEric Kohl     _In_ ULONG ulFlags,
441765d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4418c2c66affSColin Finck {
4419c2c66affSColin Finck     DEVINSTID_W pDeviceIdW = NULL;
4420c2c66affSColin Finck     PWCHAR BufferW = NULL;
4421c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
4422c2c66affSColin Finck 
442365d3bf74SEric Kohl     TRACE("CM_Get_Device_Interface_List_ExA(%s %s %p %lu 0x%08lx %p)\n",
442465d3bf74SEric Kohl           debugstr_guid(InterfaceClassGuid), debugstr_a(pDeviceID),
442565d3bf74SEric Kohl           Buffer, BufferLen, ulFlags, hMachine);
4426c2c66affSColin Finck 
4427c2c66affSColin Finck     if (Buffer == NULL ||
4428c2c66affSColin Finck         BufferLen == 0)
4429c2c66affSColin Finck         return CR_INVALID_POINTER;
4430c2c66affSColin Finck 
4431c2c66affSColin Finck     if (pDeviceID != NULL)
4432c2c66affSColin Finck     {
4433c2c66affSColin Finck         if (!pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDeviceIdW))
4434c2c66affSColin Finck             return CR_INVALID_DEVICE_ID;
4435c2c66affSColin Finck     }
4436c2c66affSColin Finck 
4437c2c66affSColin Finck     BufferW = MyMalloc(BufferLen * sizeof(WCHAR));
4438c2c66affSColin Finck     if (BufferW == NULL)
4439c2c66affSColin Finck     {
4440c2c66affSColin Finck         ret = CR_OUT_OF_MEMORY;
4441c2c66affSColin Finck         goto Done;
4442c2c66affSColin Finck     }
4443c2c66affSColin Finck 
4444c2c66affSColin Finck     ret = CM_Get_Device_Interface_List_ExW(InterfaceClassGuid, pDeviceIdW,
4445c2c66affSColin Finck                                            BufferW, BufferLen, ulFlags,
4446c2c66affSColin Finck                                            hMachine);
4447c2c66affSColin Finck     if (ret != CR_SUCCESS)
4448c2c66affSColin Finck         goto Done;
4449c2c66affSColin Finck 
4450c2c66affSColin Finck     if (WideCharToMultiByte(CP_ACP,
4451c2c66affSColin Finck                             0,
4452c2c66affSColin Finck                             BufferW,
4453aa056499SVictor Perevertkin                             BufferLen,
4454c2c66affSColin Finck                             Buffer,
4455c2c66affSColin Finck                             BufferLen,
4456c2c66affSColin Finck                             NULL,
4457c2c66affSColin Finck                             NULL) == 0)
4458c2c66affSColin Finck         ret = CR_FAILURE;
4459c2c66affSColin Finck 
4460c2c66affSColin Finck Done:
4461c2c66affSColin Finck     if (BufferW != NULL)
4462c2c66affSColin Finck         MyFree(BufferW);
4463c2c66affSColin Finck 
4464c2c66affSColin Finck     if (pDeviceIdW != NULL)
4465c2c66affSColin Finck         MyFree(pDeviceIdW);
4466c2c66affSColin Finck 
4467c2c66affSColin Finck     return ret;
4468c2c66affSColin Finck }
4469c2c66affSColin Finck 
4470c2c66affSColin Finck 
4471c2c66affSColin Finck /***********************************************************************
4472c2c66affSColin Finck  *      CM_Get_Device_Interface_List_ExW (SETUPAPI.@)
4473c2c66affSColin Finck  */
447465d3bf74SEric Kohl CONFIGRET
447565d3bf74SEric Kohl WINAPI
447665d3bf74SEric Kohl CM_Get_Device_Interface_List_ExW(
447765d3bf74SEric Kohl     _In_ LPGUID InterfaceClassGuid,
447865d3bf74SEric Kohl     _In_opt_ DEVINSTID_W pDeviceID,
447965d3bf74SEric Kohl     _Out_writes_(BufferLen) PWCHAR Buffer,
448065d3bf74SEric Kohl     _In_ ULONG BufferLen,
448165d3bf74SEric Kohl     _In_ ULONG ulFlags,
448265d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4483c2c66affSColin Finck {
4484c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4485c2c66affSColin Finck     PNP_RPC_BUFFER_SIZE BufferSize = 0;
4486c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
4487c2c66affSColin Finck 
448865d3bf74SEric Kohl     TRACE("CM_Get_Device_Interface_List_ExW(%s %s %p %lu 0x%08lx %p)\n",
448965d3bf74SEric Kohl           debugstr_guid(InterfaceClassGuid), debugstr_w(pDeviceID),
449065d3bf74SEric Kohl           Buffer, BufferLen, ulFlags, hMachine);
4491c2c66affSColin Finck 
4492c2c66affSColin Finck     if (Buffer == NULL ||
4493c2c66affSColin Finck         BufferLen == 0)
4494c2c66affSColin Finck         return CR_INVALID_POINTER;
4495c2c66affSColin Finck 
4496c2c66affSColin Finck     if (ulFlags & ~CM_GET_DEVICE_INTERFACE_LIST_BITS)
4497c2c66affSColin Finck         return CR_INVALID_FLAG;
4498c2c66affSColin Finck 
4499c2c66affSColin Finck     if (hMachine != NULL)
4500c2c66affSColin Finck     {
4501c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4502c2c66affSColin Finck         if (BindingHandle == NULL)
4503c2c66affSColin Finck             return CR_FAILURE;
4504c2c66affSColin Finck     }
4505c2c66affSColin Finck     else
4506c2c66affSColin Finck     {
4507c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
4508c2c66affSColin Finck             return CR_FAILURE;
4509c2c66affSColin Finck     }
4510c2c66affSColin Finck 
4511c2c66affSColin Finck     *Buffer = 0;
4512c2c66affSColin Finck     BufferSize = BufferLen;
4513c2c66affSColin Finck 
4514c2c66affSColin Finck     RpcTryExcept
4515c2c66affSColin Finck     {
4516c2c66affSColin Finck         ret = PNP_GetInterfaceDeviceList(BindingHandle,
4517c2c66affSColin Finck                                          InterfaceClassGuid,
4518c2c66affSColin Finck                                          pDeviceID,
4519c2c66affSColin Finck                                          (LPBYTE)Buffer,
4520c2c66affSColin Finck                                          &BufferSize,
4521c2c66affSColin Finck                                          ulFlags);
4522c2c66affSColin Finck     }
4523c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4524c2c66affSColin Finck     {
4525c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4526c2c66affSColin Finck     }
4527c2c66affSColin Finck     RpcEndExcept;
4528c2c66affSColin Finck 
4529c2c66affSColin Finck     return ret;
4530c2c66affSColin Finck }
4531c2c66affSColin Finck 
4532c2c66affSColin Finck 
4533c2c66affSColin Finck /***********************************************************************
4534c2c66affSColin Finck  *      CM_Get_Device_Interface_List_SizeA (SETUPAPI.@)
4535c2c66affSColin Finck  */
453665d3bf74SEric Kohl CONFIGRET
453765d3bf74SEric Kohl WINAPI
453865d3bf74SEric Kohl CM_Get_Device_Interface_List_SizeA(
453965d3bf74SEric Kohl     _Out_ PULONG pulLen,
454065d3bf74SEric Kohl     _In_ LPGUID InterfaceClassGuid,
454165d3bf74SEric Kohl     _In_opt_ DEVINSTID_A pDeviceID,
454265d3bf74SEric Kohl     _In_ ULONG ulFlags)
4543c2c66affSColin Finck {
454465d3bf74SEric Kohl     TRACE("CM_Get_Device_Interface_List_SizeA(%p %p %s 0x%08lx)\n",
454565d3bf74SEric Kohl           pulLen, InterfaceClassGuid, debugstr_a(pDeviceID), ulFlags);
4546c2c66affSColin Finck 
4547c2c66affSColin Finck     return CM_Get_Device_Interface_List_Size_ExA(pulLen, InterfaceClassGuid,
454865d3bf74SEric Kohl                                                  pDeviceID, ulFlags, NULL);
4549c2c66affSColin Finck }
4550c2c66affSColin Finck 
4551c2c66affSColin Finck 
4552c2c66affSColin Finck /***********************************************************************
4553c2c66affSColin Finck  *      CM_Get_Device_Interface_List_SizeW (SETUPAPI.@)
4554c2c66affSColin Finck  */
455565d3bf74SEric Kohl CONFIGRET
455665d3bf74SEric Kohl WINAPI
455765d3bf74SEric Kohl CM_Get_Device_Interface_List_SizeW(
455865d3bf74SEric Kohl     _Out_ PULONG pulLen,
455965d3bf74SEric Kohl     _In_ LPGUID InterfaceClassGuid,
456065d3bf74SEric Kohl     _In_opt_ DEVINSTID_W pDeviceID,
456165d3bf74SEric Kohl     _In_ ULONG ulFlags)
4562c2c66affSColin Finck {
456365d3bf74SEric Kohl     TRACE("CM_Get_Device_Interface_List_SizeW(%p %p %s 0x%08lx)\n",
456465d3bf74SEric Kohl           pulLen, InterfaceClassGuid, debugstr_w(pDeviceID), ulFlags);
4565c2c66affSColin Finck 
4566c2c66affSColin Finck     return CM_Get_Device_Interface_List_Size_ExW(pulLen, InterfaceClassGuid,
456765d3bf74SEric Kohl                                                  pDeviceID, ulFlags, NULL);
4568c2c66affSColin Finck }
4569c2c66affSColin Finck 
4570c2c66affSColin Finck 
4571c2c66affSColin Finck /***********************************************************************
4572c2c66affSColin Finck  *      CM_Get_Device_Interface_List_Size_ExA (SETUPAPI.@)
4573c2c66affSColin Finck  */
457465d3bf74SEric Kohl CONFIGRET
457565d3bf74SEric Kohl WINAPI
457665d3bf74SEric Kohl CM_Get_Device_Interface_List_Size_ExA(
457765d3bf74SEric Kohl     _Out_ PULONG pulLen,
457865d3bf74SEric Kohl     _In_ LPGUID InterfaceClassGuid,
457965d3bf74SEric Kohl     _In_opt_ DEVINSTID_A pDeviceID,
458065d3bf74SEric Kohl     _In_ ULONG ulFlags,
458165d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4582c2c66affSColin Finck {
4583c2c66affSColin Finck     DEVINSTID_W pDeviceIdW = NULL;
4584c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
4585c2c66affSColin Finck 
458665d3bf74SEric Kohl     TRACE("CM_Get_Device_Interface_List_Size_ExA(%p %p %s 0x%08lx %p)\n",
458765d3bf74SEric Kohl           pulLen, InterfaceClassGuid, debugstr_a(pDeviceID), ulFlags, hMachine);
4588c2c66affSColin Finck 
4589c2c66affSColin Finck     if (pulLen == NULL)
4590c2c66affSColin Finck         return CR_INVALID_POINTER;
4591c2c66affSColin Finck 
459265d3bf74SEric Kohl     if (pDeviceID != NULL)
4593c2c66affSColin Finck     {
459465d3bf74SEric Kohl         if (!pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDeviceIdW))
4595c2c66affSColin Finck             return CR_INVALID_DEVICE_ID;
4596c2c66affSColin Finck     }
4597c2c66affSColin Finck 
4598c2c66affSColin Finck     *pulLen = 0;
4599c2c66affSColin Finck 
4600c2c66affSColin Finck     ret = CM_Get_Device_Interface_List_Size_ExW(pulLen, InterfaceClassGuid,
4601c2c66affSColin Finck                                                 pDeviceIdW, ulFlags, hMachine);
4602c2c66affSColin Finck 
4603c2c66affSColin Finck     if (pDeviceIdW != NULL)
4604c2c66affSColin Finck         MyFree(pDeviceIdW);
4605c2c66affSColin Finck 
4606c2c66affSColin Finck     return ret;
4607c2c66affSColin Finck }
4608c2c66affSColin Finck 
4609c2c66affSColin Finck 
4610c2c66affSColin Finck /***********************************************************************
4611c2c66affSColin Finck  *      CM_Get_Device_Interface_List_Size_ExW (SETUPAPI.@)
4612c2c66affSColin Finck  */
461365d3bf74SEric Kohl CONFIGRET
461465d3bf74SEric Kohl WINAPI
461565d3bf74SEric Kohl CM_Get_Device_Interface_List_Size_ExW(
461665d3bf74SEric Kohl     _Out_ PULONG pulLen,
461765d3bf74SEric Kohl     _In_ LPGUID InterfaceClassGuid,
461865d3bf74SEric Kohl     _In_opt_ DEVINSTID_W pDeviceID,
461965d3bf74SEric Kohl     _In_ ULONG ulFlags,
462065d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4621c2c66affSColin Finck {
4622c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4623c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
4624c2c66affSColin Finck 
462565d3bf74SEric Kohl     TRACE("CM_Get_Device_Interface_List_Size_ExW(%p %p %s 0x%08lx %p)\n",
462665d3bf74SEric Kohl           pulLen, InterfaceClassGuid, debugstr_w(pDeviceID), ulFlags, hMachine);
4627c2c66affSColin Finck 
4628c2c66affSColin Finck     if (pulLen == NULL)
4629c2c66affSColin Finck         return CR_INVALID_POINTER;
4630c2c66affSColin Finck 
4631c2c66affSColin Finck     if (ulFlags & ~CM_GET_DEVICE_INTERFACE_LIST_BITS)
4632c2c66affSColin Finck         return CR_INVALID_FLAG;
4633c2c66affSColin Finck 
4634c2c66affSColin Finck     if (hMachine != NULL)
4635c2c66affSColin Finck     {
4636c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4637c2c66affSColin Finck         if (BindingHandle == NULL)
4638c2c66affSColin Finck             return CR_FAILURE;
4639c2c66affSColin Finck     }
4640c2c66affSColin Finck     else
4641c2c66affSColin Finck     {
4642c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
4643c2c66affSColin Finck             return CR_FAILURE;
4644c2c66affSColin Finck     }
4645c2c66affSColin Finck 
4646c2c66affSColin Finck     *pulLen = 0;
4647c2c66affSColin Finck 
4648c2c66affSColin Finck     RpcTryExcept
4649c2c66affSColin Finck     {
4650c2c66affSColin Finck         ret = PNP_GetInterfaceDeviceListSize(BindingHandle,
4651c2c66affSColin Finck                                              pulLen,
4652c2c66affSColin Finck                                              InterfaceClassGuid,
465365d3bf74SEric Kohl                                              pDeviceID,
4654c2c66affSColin Finck                                              ulFlags);
4655c2c66affSColin Finck     }
4656c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4657c2c66affSColin Finck     {
4658c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4659c2c66affSColin Finck     }
4660c2c66affSColin Finck     RpcEndExcept;
4661c2c66affSColin Finck 
4662c2c66affSColin Finck     return ret;
4663c2c66affSColin Finck }
4664c2c66affSColin Finck 
4665c2c66affSColin Finck 
4666c2c66affSColin Finck /***********************************************************************
4667c2c66affSColin Finck  * CM_Get_First_Log_Conf [SETUPAPI.@]
4668c2c66affSColin Finck  */
466965d3bf74SEric Kohl CONFIGRET
467065d3bf74SEric Kohl WINAPI
467165d3bf74SEric Kohl CM_Get_First_Log_Conf(
467265d3bf74SEric Kohl     _Out_opt_ PLOG_CONF plcLogConf,
467365d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
467465d3bf74SEric Kohl     _In_ ULONG ulFlags)
4675c2c66affSColin Finck {
467665d3bf74SEric Kohl     TRACE("CM_Get_First_Log_Conf(%p %lx %lx)\n",
467765d3bf74SEric Kohl           plcLogConf, dnDevInst, ulFlags);
467865d3bf74SEric Kohl 
4679c2c66affSColin Finck     return CM_Get_First_Log_Conf_Ex(plcLogConf, dnDevInst, ulFlags, NULL);
4680c2c66affSColin Finck }
4681c2c66affSColin Finck 
4682c2c66affSColin Finck 
4683c2c66affSColin Finck /***********************************************************************
4684c2c66affSColin Finck  * CM_Get_First_Log_Conf_Ex [SETUPAPI.@]
4685c2c66affSColin Finck  */
468665d3bf74SEric Kohl CONFIGRET
468765d3bf74SEric Kohl WINAPI
468865d3bf74SEric Kohl CM_Get_First_Log_Conf_Ex(
468965d3bf74SEric Kohl     _Out_opt_ PLOG_CONF plcLogConf,
469065d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
469165d3bf74SEric Kohl     _In_ ULONG ulFlags,
469265d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4693c2c66affSColin Finck {
4694c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4695c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
4696c2c66affSColin Finck     LPWSTR lpDevInst = NULL;
4697c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
4698c2c66affSColin Finck     ULONG ulTag;
4699c2c66affSColin Finck     PLOG_CONF_INFO pLogConfInfo;
4700c2c66affSColin Finck 
470160a21894SEric Kohl     FIXME("CM_Get_First_Log_Conf_Ex(%p %lx %lx %p)\n",
470265d3bf74SEric Kohl           plcLogConf, dnDevInst, ulFlags, hMachine);
4703c2c66affSColin Finck 
4704c2c66affSColin Finck     if (dnDevInst == 0)
4705c2c66affSColin Finck         return CR_INVALID_DEVINST;
4706c2c66affSColin Finck 
4707c2c66affSColin Finck     if (ulFlags & ~LOG_CONF_BITS)
4708c2c66affSColin Finck         return CR_INVALID_FLAG;
4709c2c66affSColin Finck 
4710c2c66affSColin Finck     if (plcLogConf)
4711c2c66affSColin Finck         *plcLogConf = 0;
4712c2c66affSColin Finck 
4713c2c66affSColin Finck     if (hMachine != NULL)
4714c2c66affSColin Finck     {
4715c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4716c2c66affSColin Finck         if (BindingHandle == NULL)
4717c2c66affSColin Finck             return CR_FAILURE;
4718c2c66affSColin Finck 
4719c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
4720c2c66affSColin Finck         if (StringTable == 0)
4721c2c66affSColin Finck             return CR_FAILURE;
4722c2c66affSColin Finck     }
4723c2c66affSColin Finck     else
4724c2c66affSColin Finck     {
4725c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
4726c2c66affSColin Finck             return CR_FAILURE;
4727c2c66affSColin Finck     }
4728c2c66affSColin Finck 
4729c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
4730c2c66affSColin Finck     if (lpDevInst == NULL)
4731c2c66affSColin Finck         return CR_INVALID_DEVNODE;
4732c2c66affSColin Finck 
4733c2c66affSColin Finck     RpcTryExcept
4734c2c66affSColin Finck     {
4735c2c66affSColin Finck         ret = PNP_GetFirstLogConf(BindingHandle,
4736c2c66affSColin Finck                                   lpDevInst,
4737c2c66affSColin Finck                                   ulFlags,
4738c2c66affSColin Finck                                   &ulTag,
4739c2c66affSColin Finck                                   ulFlags);
4740c2c66affSColin Finck     }
4741c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4742c2c66affSColin Finck     {
4743c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4744c2c66affSColin Finck     }
4745c2c66affSColin Finck     RpcEndExcept;
4746c2c66affSColin Finck 
4747c2c66affSColin Finck     if (ret != CR_SUCCESS)
4748c2c66affSColin Finck         return ret;
4749c2c66affSColin Finck 
4750c2c66affSColin Finck     if (plcLogConf)
4751c2c66affSColin Finck     {
4752c2c66affSColin Finck         pLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
4753c2c66affSColin Finck         if (pLogConfInfo == NULL)
4754c2c66affSColin Finck             return CR_OUT_OF_MEMORY;
4755c2c66affSColin Finck 
4756c2c66affSColin Finck         pLogConfInfo->ulMagic = LOG_CONF_MAGIC;
4757c2c66affSColin Finck         pLogConfInfo->dnDevInst = dnDevInst;
47586efb3cbeSEric Kohl         pLogConfInfo->ulType = ulFlags;
4759c2c66affSColin Finck         pLogConfInfo->ulTag = ulTag;
4760c2c66affSColin Finck 
4761c2c66affSColin Finck         *plcLogConf = (LOG_CONF)pLogConfInfo;
4762c2c66affSColin Finck     }
4763c2c66affSColin Finck 
4764c2c66affSColin Finck     return CR_SUCCESS;
4765c2c66affSColin Finck }
4766c2c66affSColin Finck 
4767c2c66affSColin Finck 
4768c2c66affSColin Finck /***********************************************************************
4769c2c66affSColin Finck  * CM_Get_Global_State [SETUPAPI.@]
4770c2c66affSColin Finck  */
477165d3bf74SEric Kohl CONFIGRET
477265d3bf74SEric Kohl WINAPI
477365d3bf74SEric Kohl CM_Get_Global_State(
477465d3bf74SEric Kohl     _Out_ PULONG pulState,
477565d3bf74SEric Kohl     _In_ ULONG ulFlags)
4776c2c66affSColin Finck {
477765d3bf74SEric Kohl     TRACE("CM_Get_Global_State(%p %lx)\n",
477865d3bf74SEric Kohl           pulState, ulFlags);
477965d3bf74SEric Kohl 
4780c2c66affSColin Finck     return CM_Get_Global_State_Ex(pulState, ulFlags, NULL);
4781c2c66affSColin Finck }
4782c2c66affSColin Finck 
4783c2c66affSColin Finck 
4784c2c66affSColin Finck /***********************************************************************
4785c2c66affSColin Finck  * CM_Get_Global_State_Ex [SETUPAPI.@]
4786c2c66affSColin Finck  */
478765d3bf74SEric Kohl CONFIGRET
478865d3bf74SEric Kohl WINAPI
478965d3bf74SEric Kohl CM_Get_Global_State_Ex(
479065d3bf74SEric Kohl     _Out_ PULONG pulState,
479165d3bf74SEric Kohl     _In_ ULONG ulFlags,
479265d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4793c2c66affSColin Finck {
4794c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4795c2c66affSColin Finck     CONFIGRET ret;
4796c2c66affSColin Finck 
479760a21894SEric Kohl     TRACE("CM_Get_Global_State_Ex(%p %lx %p)\n",
479865d3bf74SEric Kohl           pulState, ulFlags, hMachine);
4799c2c66affSColin Finck 
4800c2c66affSColin Finck     if (pulState == NULL)
4801c2c66affSColin Finck         return CR_INVALID_POINTER;
4802c2c66affSColin Finck 
4803c2c66affSColin Finck     if (ulFlags != 0)
4804c2c66affSColin Finck         return CR_INVALID_FLAG;
4805c2c66affSColin Finck 
4806c2c66affSColin Finck     if (hMachine != NULL)
4807c2c66affSColin Finck     {
4808c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4809c2c66affSColin Finck         if (BindingHandle == NULL)
4810c2c66affSColin Finck             return CR_FAILURE;
4811c2c66affSColin Finck     }
4812c2c66affSColin Finck     else
4813c2c66affSColin Finck     {
4814c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
4815c2c66affSColin Finck             return CR_FAILURE;
4816c2c66affSColin Finck     }
4817c2c66affSColin Finck 
4818c2c66affSColin Finck     RpcTryExcept
4819c2c66affSColin Finck     {
4820c2c66affSColin Finck         ret = PNP_GetGlobalState(BindingHandle, pulState, ulFlags);
4821c2c66affSColin Finck     }
4822c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4823c2c66affSColin Finck     {
4824c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4825c2c66affSColin Finck     }
4826c2c66affSColin Finck     RpcEndExcept;
4827c2c66affSColin Finck 
4828c2c66affSColin Finck     return ret;
4829c2c66affSColin Finck }
4830c2c66affSColin Finck 
4831c2c66affSColin Finck 
4832c2c66affSColin Finck /***********************************************************************
4833c2c66affSColin Finck  * CM_Get_HW_Prof_FlagsA [SETUPAPI.@]
4834c2c66affSColin Finck  */
483565d3bf74SEric Kohl CONFIGRET
483665d3bf74SEric Kohl WINAPI
483765d3bf74SEric Kohl CM_Get_HW_Prof_FlagsA(
483865d3bf74SEric Kohl     _In_ DEVINSTID_A szDevInstName,
483965d3bf74SEric Kohl     _In_ ULONG ulHardwareProfile,
484065d3bf74SEric Kohl     _Out_ PULONG pulValue,
484165d3bf74SEric Kohl     _In_ ULONG ulFlags)
4842c2c66affSColin Finck {
484365d3bf74SEric Kohl     TRACE("CM_Get_HW_Prof_FlagsA(%s %lu %p %lx)\n",
484465d3bf74SEric Kohl           debugstr_a(szDevInstName), ulHardwareProfile, pulValue, ulFlags);
4845c2c66affSColin Finck 
4846c2c66affSColin Finck     return CM_Get_HW_Prof_Flags_ExA(szDevInstName, ulHardwareProfile,
4847c2c66affSColin Finck                                     pulValue, ulFlags, NULL);
4848c2c66affSColin Finck }
4849c2c66affSColin Finck 
4850c2c66affSColin Finck 
4851c2c66affSColin Finck /***********************************************************************
4852c2c66affSColin Finck  * CM_Get_HW_Prof_FlagsW [SETUPAPI.@]
4853c2c66affSColin Finck  */
485465d3bf74SEric Kohl CONFIGRET
485565d3bf74SEric Kohl WINAPI
485665d3bf74SEric Kohl CM_Get_HW_Prof_FlagsW(
485765d3bf74SEric Kohl     _In_ DEVINSTID_W szDevInstName,
485865d3bf74SEric Kohl     _In_ ULONG ulHardwareProfile,
485965d3bf74SEric Kohl     _Out_ PULONG pulValue,
486065d3bf74SEric Kohl     _In_ ULONG ulFlags)
4861c2c66affSColin Finck {
486265d3bf74SEric Kohl     TRACE("CM_Get_HW_Prof_FlagsW(%s %lu %p %lx)\n",
486365d3bf74SEric Kohl           debugstr_w(szDevInstName), ulHardwareProfile, pulValue, ulFlags);
4864c2c66affSColin Finck 
4865c2c66affSColin Finck     return CM_Get_HW_Prof_Flags_ExW(szDevInstName, ulHardwareProfile,
4866c2c66affSColin Finck                                     pulValue, ulFlags, NULL);
4867c2c66affSColin Finck }
4868c2c66affSColin Finck 
4869c2c66affSColin Finck 
4870c2c66affSColin Finck /***********************************************************************
4871c2c66affSColin Finck  * CM_Get_HW_Prof_Flags_ExA [SETUPAPI.@]
4872c2c66affSColin Finck  */
487365d3bf74SEric Kohl CONFIGRET
487465d3bf74SEric Kohl WINAPI
487565d3bf74SEric Kohl CM_Get_HW_Prof_Flags_ExA(
487665d3bf74SEric Kohl     _In_ DEVINSTID_A szDevInstName,
487765d3bf74SEric Kohl     _In_ ULONG ulHardwareProfile,
487865d3bf74SEric Kohl     _Out_ PULONG pulValue,
487965d3bf74SEric Kohl     _In_ ULONG ulFlags,
488065d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4881c2c66affSColin Finck {
4882c2c66affSColin Finck     DEVINSTID_W pszDevIdW = NULL;
4883c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
4884c2c66affSColin Finck 
488560a21894SEric Kohl     TRACE("CM_Get_HW_Prof_Flags_ExA(%s %lu %p %lx %p)\n",
488665d3bf74SEric Kohl           debugstr_a(szDevInstName), ulHardwareProfile, pulValue, ulFlags, hMachine);
4887c2c66affSColin Finck 
4888c2c66affSColin Finck     if (szDevInstName != NULL)
4889c2c66affSColin Finck     {
4890c2c66affSColin Finck        if (pSetupCaptureAndConvertAnsiArg(szDevInstName, &pszDevIdW))
4891c2c66affSColin Finck          return CR_INVALID_DEVICE_ID;
4892c2c66affSColin Finck     }
4893c2c66affSColin Finck 
4894c2c66affSColin Finck     ret = CM_Get_HW_Prof_Flags_ExW(pszDevIdW, ulHardwareProfile,
4895c2c66affSColin Finck                                    pulValue, ulFlags, hMachine);
4896c2c66affSColin Finck 
4897c2c66affSColin Finck     if (pszDevIdW != NULL)
4898c2c66affSColin Finck         MyFree(pszDevIdW);
4899c2c66affSColin Finck 
4900c2c66affSColin Finck     return ret;
4901c2c66affSColin Finck }
4902c2c66affSColin Finck 
4903c2c66affSColin Finck 
4904c2c66affSColin Finck /***********************************************************************
4905c2c66affSColin Finck  * CM_Get_HW_Prof_Flags_ExW [SETUPAPI.@]
4906c2c66affSColin Finck  */
490765d3bf74SEric Kohl CONFIGRET
490865d3bf74SEric Kohl WINAPI
490965d3bf74SEric Kohl CM_Get_HW_Prof_Flags_ExW(
491065d3bf74SEric Kohl     _In_ DEVINSTID_W szDevInstName,
491165d3bf74SEric Kohl     _In_ ULONG ulHardwareProfile,
491265d3bf74SEric Kohl     _Out_ PULONG pulValue,
491365d3bf74SEric Kohl     _In_ ULONG ulFlags,
491465d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
4915c2c66affSColin Finck {
4916c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
4917c2c66affSColin Finck     CONFIGRET ret;
4918c2c66affSColin Finck 
491960a21894SEric Kohl     FIXME("CM_Get_HW_Prof_Flags_ExW(%s %lu %p %lx %p)\n",
492065d3bf74SEric Kohl           debugstr_w(szDevInstName), ulHardwareProfile, pulValue, ulFlags, hMachine);
4921c2c66affSColin Finck 
4922c2c66affSColin Finck     if ((szDevInstName == NULL) || (pulValue == NULL))
4923c2c66affSColin Finck         return CR_INVALID_POINTER;
4924c2c66affSColin Finck 
4925c2c66affSColin Finck     if (ulFlags != 0)
4926c2c66affSColin Finck         return CR_INVALID_FLAG;
4927c2c66affSColin Finck 
4928c2c66affSColin Finck     /* FIXME: Check whether szDevInstName is valid */
4929c2c66affSColin Finck 
4930c2c66affSColin Finck     if (hMachine != NULL)
4931c2c66affSColin Finck     {
4932c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4933c2c66affSColin Finck         if (BindingHandle == NULL)
4934c2c66affSColin Finck             return CR_FAILURE;
4935c2c66affSColin Finck     }
4936c2c66affSColin Finck     else
4937c2c66affSColin Finck     {
4938c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
4939c2c66affSColin Finck             return CR_FAILURE;
4940c2c66affSColin Finck     }
4941c2c66affSColin Finck 
4942c2c66affSColin Finck     RpcTryExcept
4943c2c66affSColin Finck     {
4944c2c66affSColin Finck         ret = PNP_HwProfFlags(BindingHandle, PNP_GET_HWPROFFLAGS, szDevInstName,
4945c2c66affSColin Finck                               ulHardwareProfile, pulValue, NULL, NULL, 0, 0);
4946c2c66affSColin Finck     }
4947c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4948c2c66affSColin Finck     {
4949c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
4950c2c66affSColin Finck     }
4951c2c66affSColin Finck     RpcEndExcept;
4952c2c66affSColin Finck 
4953c2c66affSColin Finck     return ret;
4954c2c66affSColin Finck }
4955c2c66affSColin Finck 
4956c2c66affSColin Finck 
4957c2c66affSColin Finck /***********************************************************************
4958c2c66affSColin Finck  * CM_Get_Hardware_Profile_InfoA [SETUPAPI.@]
4959c2c66affSColin Finck  */
496060a21894SEric Kohl CONFIGRET
496160a21894SEric Kohl WINAPI
496260a21894SEric Kohl CM_Get_Hardware_Profile_InfoA(
496360a21894SEric Kohl     _In_ ULONG ulIndex,
496460a21894SEric Kohl     _Out_ PHWPROFILEINFO_A pHWProfileInfo,
496560a21894SEric Kohl     _In_ ULONG ulFlags)
4966c2c66affSColin Finck {
496760a21894SEric Kohl     TRACE("CM_Get_Hardware_Profile_InfoA(%lu %p %lx)\n",
496860a21894SEric Kohl           ulIndex, pHWProfileInfo, ulFlags);
4969c2c66affSColin Finck 
4970c2c66affSColin Finck     return CM_Get_Hardware_Profile_Info_ExA(ulIndex, pHWProfileInfo,
4971c2c66affSColin Finck                                             ulFlags, NULL);
4972c2c66affSColin Finck }
4973c2c66affSColin Finck 
4974c2c66affSColin Finck 
4975c2c66affSColin Finck /***********************************************************************
4976c2c66affSColin Finck  * CM_Get_Hardware_Profile_InfoW [SETUPAPI.@]
4977c2c66affSColin Finck  */
497860a21894SEric Kohl CONFIGRET
497960a21894SEric Kohl WINAPI
498060a21894SEric Kohl CM_Get_Hardware_Profile_InfoW(
498160a21894SEric Kohl     _In_ ULONG ulIndex,
498260a21894SEric Kohl     _Out_ PHWPROFILEINFO_W pHWProfileInfo,
498360a21894SEric Kohl     _In_ ULONG ulFlags)
4984c2c66affSColin Finck {
498560a21894SEric Kohl     TRACE("CM_Get_Hardware_Profile_InfoW(%lu %p %lx)\n",
498660a21894SEric Kohl           ulIndex, pHWProfileInfo, ulFlags);
4987c2c66affSColin Finck 
4988c2c66affSColin Finck     return CM_Get_Hardware_Profile_Info_ExW(ulIndex, pHWProfileInfo,
4989c2c66affSColin Finck                                             ulFlags, NULL);
4990c2c66affSColin Finck }
4991c2c66affSColin Finck 
4992c2c66affSColin Finck 
4993c2c66affSColin Finck /***********************************************************************
4994c2c66affSColin Finck  * CM_Get_Hardware_Profile_Info_ExA [SETUPAPI.@]
4995c2c66affSColin Finck  */
499660a21894SEric Kohl CONFIGRET
499760a21894SEric Kohl WINAPI
499860a21894SEric Kohl CM_Get_Hardware_Profile_Info_ExA(
499960a21894SEric Kohl     _In_ ULONG ulIndex,
500060a21894SEric Kohl     _Out_ PHWPROFILEINFO_A pHWProfileInfo,
500160a21894SEric Kohl     _In_ ULONG ulFlags,
500260a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
5003c2c66affSColin Finck {
5004c2c66affSColin Finck     HWPROFILEINFO_W LocalProfileInfo;
5005c2c66affSColin Finck     CONFIGRET ret;
5006c2c66affSColin Finck 
500760a21894SEric Kohl     TRACE("CM_Get_Hardware_Profile_Info_ExA(%lu %p %lx %p)\n",
500860a21894SEric Kohl           ulIndex, pHWProfileInfo, ulFlags, hMachine);
5009c2c66affSColin Finck 
5010c2c66affSColin Finck     if (pHWProfileInfo == NULL)
5011c2c66affSColin Finck         return CR_INVALID_POINTER;
5012c2c66affSColin Finck 
5013c2c66affSColin Finck     ret = CM_Get_Hardware_Profile_Info_ExW(ulIndex, &LocalProfileInfo,
5014c2c66affSColin Finck                                            ulFlags, hMachine);
5015c2c66affSColin Finck     if (ret == CR_SUCCESS)
5016c2c66affSColin Finck     {
5017c2c66affSColin Finck         pHWProfileInfo->HWPI_ulHWProfile = LocalProfileInfo.HWPI_ulHWProfile;
5018c2c66affSColin Finck         pHWProfileInfo->HWPI_dwFlags = LocalProfileInfo.HWPI_dwFlags;
5019c2c66affSColin Finck 
5020c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
5021c2c66affSColin Finck                                 0,
5022c2c66affSColin Finck                                 LocalProfileInfo.HWPI_szFriendlyName,
5023c2c66affSColin Finck                                 lstrlenW(LocalProfileInfo.HWPI_szFriendlyName) + 1,
5024c2c66affSColin Finck                                 pHWProfileInfo->HWPI_szFriendlyName,
5025c2c66affSColin Finck                                 MAX_PROFILE_LEN,
5026c2c66affSColin Finck                                 NULL,
5027c2c66affSColin Finck                                 NULL) == 0)
5028c2c66affSColin Finck             ret = CR_FAILURE;
5029c2c66affSColin Finck     }
5030c2c66affSColin Finck 
5031c2c66affSColin Finck     return ret;
5032c2c66affSColin Finck }
5033c2c66affSColin Finck 
5034c2c66affSColin Finck 
5035c2c66affSColin Finck /***********************************************************************
5036c2c66affSColin Finck  * CM_Get_Hardware_Profile_Info_ExW [SETUPAPI.@]
5037c2c66affSColin Finck  */
503860a21894SEric Kohl CONFIGRET
503960a21894SEric Kohl WINAPI
504060a21894SEric Kohl CM_Get_Hardware_Profile_Info_ExW(
504160a21894SEric Kohl     _In_ ULONG ulIndex,
504260a21894SEric Kohl     _Out_ PHWPROFILEINFO_W pHWProfileInfo,
504360a21894SEric Kohl     _In_ ULONG ulFlags,
504460a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
5045c2c66affSColin Finck {
5046c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5047c2c66affSColin Finck     CONFIGRET ret;
5048c2c66affSColin Finck 
504960a21894SEric Kohl     TRACE("CM_Get_Hardware_Profile_Info_ExW(%lu %p %lx %p)\n",
505060a21894SEric Kohl           ulIndex, pHWProfileInfo, ulFlags, hMachine);
5051c2c66affSColin Finck 
5052c2c66affSColin Finck     if (pHWProfileInfo == NULL)
5053c2c66affSColin Finck         return CR_INVALID_POINTER;
5054c2c66affSColin Finck 
5055c2c66affSColin Finck     if (ulFlags != 0)
5056c2c66affSColin Finck         return CR_INVALID_FLAG;
5057c2c66affSColin Finck 
5058c2c66affSColin Finck     if (hMachine != NULL)
5059c2c66affSColin Finck     {
5060c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5061c2c66affSColin Finck         if (BindingHandle == NULL)
5062c2c66affSColin Finck             return CR_FAILURE;
5063c2c66affSColin Finck     }
5064c2c66affSColin Finck     else
5065c2c66affSColin Finck     {
5066c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
5067c2c66affSColin Finck             return CR_FAILURE;
5068c2c66affSColin Finck     }
5069c2c66affSColin Finck 
5070c2c66affSColin Finck     RpcTryExcept
5071c2c66affSColin Finck     {
5072c2c66affSColin Finck         ret = PNP_GetHwProfInfo(BindingHandle, ulIndex, pHWProfileInfo,
5073c2c66affSColin Finck                                 sizeof(HWPROFILEINFO_W), 0);
5074c2c66affSColin Finck     }
5075c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5076c2c66affSColin Finck     {
5077c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5078c2c66affSColin Finck     }
5079c2c66affSColin Finck     RpcEndExcept;
5080c2c66affSColin Finck 
5081c2c66affSColin Finck     return ret;
5082c2c66affSColin Finck }
5083c2c66affSColin Finck 
5084c2c66affSColin Finck 
5085c2c66affSColin Finck /***********************************************************************
5086c2c66affSColin Finck  * CM_Get_Log_Conf_Priority [SETUPAPI.@]
5087c2c66affSColin Finck  */
508860a21894SEric Kohl CONFIGRET
508960a21894SEric Kohl WINAPI
509060a21894SEric Kohl CM_Get_Log_Conf_Priority(
509160a21894SEric Kohl     _In_ LOG_CONF lcLogConf,
509260a21894SEric Kohl     _Out_ PPRIORITY pPriority,
509360a21894SEric Kohl     _In_ ULONG ulFlags)
5094c2c66affSColin Finck {
509560a21894SEric Kohl     TRACE("CM_Get_Log_Conf_Priority(%p %p %lx)\n",
509660a21894SEric Kohl           lcLogConf, pPriority, ulFlags);
509760a21894SEric Kohl 
5098c2c66affSColin Finck     return CM_Get_Log_Conf_Priority_Ex(lcLogConf, pPriority, ulFlags, NULL);
5099c2c66affSColin Finck }
5100c2c66affSColin Finck 
5101c2c66affSColin Finck 
5102c2c66affSColin Finck /***********************************************************************
5103c2c66affSColin Finck  * CM_Get_Log_Conf_Priority_Ex [SETUPAPI.@]
5104c2c66affSColin Finck  */
510560a21894SEric Kohl CONFIGRET
510660a21894SEric Kohl WINAPI
510760a21894SEric Kohl CM_Get_Log_Conf_Priority_Ex(
510860a21894SEric Kohl     _In_ LOG_CONF lcLogConf,
510960a21894SEric Kohl     _Out_ PPRIORITY pPriority,
511060a21894SEric Kohl     _In_ ULONG ulFlags,
511160a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
5112c2c66affSColin Finck {
5113c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5114c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
5115c2c66affSColin Finck     PLOG_CONF_INFO pLogConfInfo;
5116c2c66affSColin Finck     LPWSTR lpDevInst;
5117c2c66affSColin Finck     CONFIGRET ret;
5118c2c66affSColin Finck 
511960a21894SEric Kohl     FIXME("CM_Get_Log_Conf_Priority_Ex(%p %p %lx %p)\n",
512060a21894SEric Kohl           lcLogConf, pPriority, ulFlags, hMachine);
5121c2c66affSColin Finck 
5122c2c66affSColin Finck     pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
512319fc20f2SEric Kohl     if (!IsValidLogConf(pLogConfInfo))
5124c2c66affSColin Finck         return CR_INVALID_LOG_CONF;
5125c2c66affSColin Finck 
5126c2c66affSColin Finck     if (pPriority == NULL)
5127c2c66affSColin Finck         return CR_INVALID_POINTER;
5128c2c66affSColin Finck 
5129c2c66affSColin Finck     if (ulFlags != 0)
5130c2c66affSColin Finck         return CR_INVALID_FLAG;
5131c2c66affSColin Finck 
5132c2c66affSColin Finck     if (hMachine != NULL)
5133c2c66affSColin Finck     {
5134c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5135c2c66affSColin Finck         if (BindingHandle == NULL)
5136c2c66affSColin Finck             return CR_FAILURE;
5137c2c66affSColin Finck 
5138c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
5139c2c66affSColin Finck         if (StringTable == 0)
5140c2c66affSColin Finck             return CR_FAILURE;
5141c2c66affSColin Finck     }
5142c2c66affSColin Finck     else
5143c2c66affSColin Finck     {
5144c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
5145c2c66affSColin Finck             return CR_FAILURE;
5146c2c66affSColin Finck     }
5147c2c66affSColin Finck 
5148c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
5149c2c66affSColin Finck     if (lpDevInst == NULL)
5150c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5151c2c66affSColin Finck 
5152c2c66affSColin Finck     RpcTryExcept
5153c2c66affSColin Finck     {
5154c2c66affSColin Finck         ret = PNP_GetLogConfPriority(BindingHandle,
5155c2c66affSColin Finck                                      lpDevInst,
51566efb3cbeSEric Kohl                                      pLogConfInfo->ulType,
5157c2c66affSColin Finck                                      pLogConfInfo->ulTag,
5158c2c66affSColin Finck                                      pPriority,
5159c2c66affSColin Finck                                      0);
5160c2c66affSColin Finck     }
5161c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5162c2c66affSColin Finck     {
5163c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5164c2c66affSColin Finck     }
5165c2c66affSColin Finck     RpcEndExcept;
5166c2c66affSColin Finck 
5167c2c66affSColin Finck     return ret;
5168c2c66affSColin Finck }
5169c2c66affSColin Finck 
5170c2c66affSColin Finck 
5171c2c66affSColin Finck /***********************************************************************
5172c2c66affSColin Finck  * CM_Get_Next_Log_Conf [SETUPAPI.@]
5173c2c66affSColin Finck  */
517460a21894SEric Kohl CONFIGRET
517560a21894SEric Kohl WINAPI
517660a21894SEric Kohl CM_Get_Next_Log_Conf(
517760a21894SEric Kohl     _Out_opt_ PLOG_CONF plcLogConf,
517860a21894SEric Kohl     _In_ LOG_CONF lcLogConf,
517960a21894SEric Kohl     _In_ ULONG ulFlags)
5180c2c66affSColin Finck {
518160a21894SEric Kohl     TRACE("CM_Get_Next_Log_Conf(%p %p %lx)\n",
518260a21894SEric Kohl           plcLogConf, lcLogConf, ulFlags);
518360a21894SEric Kohl 
5184c2c66affSColin Finck     return CM_Get_Next_Log_Conf_Ex(plcLogConf, lcLogConf, ulFlags, NULL);
5185c2c66affSColin Finck }
5186c2c66affSColin Finck 
5187c2c66affSColin Finck 
5188c2c66affSColin Finck /***********************************************************************
5189c2c66affSColin Finck  * CM_Get_Next_Log_Conf_Ex [SETUPAPI.@]
5190c2c66affSColin Finck  */
519160a21894SEric Kohl CONFIGRET
519260a21894SEric Kohl WINAPI
519360a21894SEric Kohl CM_Get_Next_Log_Conf_Ex(
519460a21894SEric Kohl     _Out_opt_ PLOG_CONF plcLogConf,
519560a21894SEric Kohl     _In_ LOG_CONF lcLogConf,
519660a21894SEric Kohl     _In_ ULONG ulFlags,
519760a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
5198c2c66affSColin Finck {
5199c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5200c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
5201c2c66affSColin Finck     PLOG_CONF_INFO pLogConfInfo;
5202c2c66affSColin Finck     PLOG_CONF_INFO pNewLogConfInfo;
5203c2c66affSColin Finck     ULONG ulNewTag;
5204c2c66affSColin Finck     LPWSTR lpDevInst;
5205c2c66affSColin Finck     CONFIGRET ret;
5206c2c66affSColin Finck 
520760a21894SEric Kohl     FIXME("CM_Get_Next_Log_Conf_Ex(%p %p %lx %p)\n",
520860a21894SEric Kohl           plcLogConf, lcLogConf, ulFlags, hMachine);
5209c2c66affSColin Finck 
5210c2c66affSColin Finck     if (plcLogConf)
5211c2c66affSColin Finck         *plcLogConf = 0;
5212c2c66affSColin Finck 
5213c2c66affSColin Finck     pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
521419fc20f2SEric Kohl     if (!IsValidLogConf(pLogConfInfo))
5215c2c66affSColin Finck         return CR_INVALID_LOG_CONF;
5216c2c66affSColin Finck 
5217c2c66affSColin Finck     if (ulFlags != 0)
5218c2c66affSColin Finck         return CR_INVALID_FLAG;
5219c2c66affSColin Finck 
5220c2c66affSColin Finck     if (hMachine != NULL)
5221c2c66affSColin Finck     {
5222c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5223c2c66affSColin Finck         if (BindingHandle == NULL)
5224c2c66affSColin Finck             return CR_FAILURE;
5225c2c66affSColin Finck 
5226c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
5227c2c66affSColin Finck         if (StringTable == 0)
5228c2c66affSColin Finck             return CR_FAILURE;
5229c2c66affSColin Finck     }
5230c2c66affSColin Finck     else
5231c2c66affSColin Finck     {
5232c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
5233c2c66affSColin Finck             return CR_FAILURE;
5234c2c66affSColin Finck     }
5235c2c66affSColin Finck 
5236c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
5237c2c66affSColin Finck     if (lpDevInst == NULL)
5238c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5239c2c66affSColin Finck 
5240c2c66affSColin Finck     RpcTryExcept
5241c2c66affSColin Finck     {
5242c2c66affSColin Finck         ret = PNP_GetNextLogConf(BindingHandle,
5243c2c66affSColin Finck                                  lpDevInst,
52446efb3cbeSEric Kohl                                  pLogConfInfo->ulType,
5245c2c66affSColin Finck                                  pLogConfInfo->ulTag,
5246c2c66affSColin Finck                                  &ulNewTag,
5247c2c66affSColin Finck                                  0);
5248c2c66affSColin Finck     }
5249c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5250c2c66affSColin Finck     {
5251c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5252c2c66affSColin Finck     }
5253c2c66affSColin Finck     RpcEndExcept;
5254c2c66affSColin Finck 
5255c2c66affSColin Finck     if (ret != CR_SUCCESS)
5256c2c66affSColin Finck         return ret;
5257c2c66affSColin Finck 
5258c2c66affSColin Finck     if (plcLogConf)
5259c2c66affSColin Finck     {
5260c2c66affSColin Finck         pNewLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
5261c2c66affSColin Finck         if (pNewLogConfInfo == NULL)
5262c2c66affSColin Finck             return CR_OUT_OF_MEMORY;
5263c2c66affSColin Finck 
5264c2c66affSColin Finck         pNewLogConfInfo->ulMagic = LOG_CONF_MAGIC;
5265c2c66affSColin Finck         pNewLogConfInfo->dnDevInst = pLogConfInfo->dnDevInst;
52666efb3cbeSEric Kohl         pNewLogConfInfo->ulType = pLogConfInfo->ulType;
5267c2c66affSColin Finck         pNewLogConfInfo->ulTag = ulNewTag;
5268c2c66affSColin Finck 
5269c2c66affSColin Finck         *plcLogConf = (LOG_CONF)pNewLogConfInfo;
5270c2c66affSColin Finck     }
5271c2c66affSColin Finck 
5272c2c66affSColin Finck     return CR_SUCCESS;
5273c2c66affSColin Finck }
5274c2c66affSColin Finck 
5275c2c66affSColin Finck 
5276c2c66affSColin Finck /***********************************************************************
5277894ad4f1SEric Kohl  * CM_Get_Next_Res_Des [SETUPAPI.@]
5278c2c66affSColin Finck  */
527960a21894SEric Kohl CONFIGRET
528060a21894SEric Kohl WINAPI
528160a21894SEric Kohl CM_Get_Next_Res_Des(
528260a21894SEric Kohl     _Out_ PRES_DES prdResDes,
528360a21894SEric Kohl     _In_ RES_DES rdResDes,
528460a21894SEric Kohl     _In_ RESOURCEID ForResource,
528560a21894SEric Kohl     _Out_opt_ PRESOURCEID pResourceID,
528660a21894SEric Kohl     _In_ ULONG ulFlags)
5287c2c66affSColin Finck {
528860a21894SEric Kohl     TRACE("CM_Get_Next_Res_Des(%p %p %lu %p %lx)\n",
528960a21894SEric Kohl           prdResDes, rdResDes, ForResource, pResourceID, ulFlags);
529060a21894SEric Kohl 
5291c2c66affSColin Finck     return CM_Get_Next_Res_Des_Ex(prdResDes, rdResDes, ForResource,
5292c2c66affSColin Finck                                   pResourceID, ulFlags, NULL);
5293c2c66affSColin Finck }
5294c2c66affSColin Finck 
5295c2c66affSColin Finck 
5296c2c66affSColin Finck /***********************************************************************
5297c2c66affSColin Finck  * CM_Get_Next_Re_Des_Ex [SETUPAPI.@]
5298c2c66affSColin Finck  */
529960a21894SEric Kohl CONFIGRET
530060a21894SEric Kohl WINAPI
530160a21894SEric Kohl CM_Get_Next_Res_Des_Ex(
530260a21894SEric Kohl     _Out_ PRES_DES prdResDes,
530360a21894SEric Kohl     _In_ RES_DES rdResDes,
530460a21894SEric Kohl     _In_ RESOURCEID ForResource,
530560a21894SEric Kohl     _Out_opt_ PRESOURCEID pResourceID,
530660a21894SEric Kohl     _In_ ULONG ulFlags,
530760a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
5308c2c66affSColin Finck {
53096efb3cbeSEric Kohl     RPC_BINDING_HANDLE BindingHandle = NULL;
53106efb3cbeSEric Kohl     HSTRING_TABLE StringTable = NULL;
5311894ad4f1SEric Kohl     PRES_DES_INFO pNewResDesInfo = NULL;
5312894ad4f1SEric Kohl     ULONG ulLogConfTag, ulLogConfType, ulResDesTag;
5313894ad4f1SEric Kohl     ULONG ulNextResDesType = 0, ulNextResDesTag = 0;
53146efb3cbeSEric Kohl     LPWSTR lpDevInst;
53156efb3cbeSEric Kohl     DEVINST dnDevInst;
53166efb3cbeSEric Kohl     CONFIGRET ret;
53176efb3cbeSEric Kohl 
531860a21894SEric Kohl     FIXME("CM_Get_Next_Res_Des_Ex(%p %p %lu %p %lx %p)\n",
531960a21894SEric Kohl           prdResDes, rdResDes, ForResource, pResourceID, ulFlags, hMachine);
5320c2c66affSColin Finck 
53216efb3cbeSEric Kohl     if (prdResDes == NULL)
53226efb3cbeSEric Kohl         return CR_INVALID_POINTER;
53236efb3cbeSEric Kohl 
53246efb3cbeSEric Kohl     if (IsValidLogConf((PLOG_CONF_INFO)rdResDes))
53256efb3cbeSEric Kohl     {
53266efb3cbeSEric Kohl         FIXME("LogConf found!\n");
53276efb3cbeSEric Kohl         dnDevInst = ((PLOG_CONF_INFO)rdResDes)->dnDevInst;
5328894ad4f1SEric Kohl         ulLogConfTag = ((PLOG_CONF_INFO)rdResDes)->ulTag;
5329894ad4f1SEric Kohl         ulLogConfType = ((PLOG_CONF_INFO)rdResDes)->ulType;
5330894ad4f1SEric Kohl         ulResDesTag = (ULONG)-1;
53316efb3cbeSEric Kohl     }
53326efb3cbeSEric Kohl     else if (IsValidResDes((PRES_DES_INFO)rdResDes))
53336efb3cbeSEric Kohl     {
53346efb3cbeSEric Kohl         FIXME("ResDes found!\n");
53356efb3cbeSEric Kohl         dnDevInst = ((PRES_DES_INFO)rdResDes)->dnDevInst;
5336894ad4f1SEric Kohl         ulLogConfTag = ((PRES_DES_INFO)rdResDes)->ulLogConfTag;
5337894ad4f1SEric Kohl         ulLogConfType = ((PRES_DES_INFO)rdResDes)->ulLogConfType;
5338894ad4f1SEric Kohl         ulResDesTag = ((PRES_DES_INFO)rdResDes)->ulResDesTag;
53396efb3cbeSEric Kohl     }
53406efb3cbeSEric Kohl     else
53416efb3cbeSEric Kohl     {
53426efb3cbeSEric Kohl         return CR_INVALID_RES_DES;
53436efb3cbeSEric Kohl     }
53446efb3cbeSEric Kohl 
5345894ad4f1SEric Kohl     if ((ForResource == ResType_All) && (pResourceID == NULL))
5346894ad4f1SEric Kohl         return CR_INVALID_POINTER;
5347894ad4f1SEric Kohl 
5348894ad4f1SEric Kohl     if (ulFlags != 0)
5349894ad4f1SEric Kohl         return CR_INVALID_FLAG;
5350894ad4f1SEric Kohl 
53516efb3cbeSEric Kohl     if (hMachine != NULL)
53526efb3cbeSEric Kohl     {
53536efb3cbeSEric Kohl         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
53546efb3cbeSEric Kohl         if (BindingHandle == NULL)
53556efb3cbeSEric Kohl             return CR_FAILURE;
53566efb3cbeSEric Kohl 
53576efb3cbeSEric Kohl         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
53586efb3cbeSEric Kohl         if (StringTable == 0)
53596efb3cbeSEric Kohl             return CR_FAILURE;
53606efb3cbeSEric Kohl     }
53616efb3cbeSEric Kohl     else
53626efb3cbeSEric Kohl     {
53636efb3cbeSEric Kohl         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
53646efb3cbeSEric Kohl             return CR_FAILURE;
53656efb3cbeSEric Kohl     }
53666efb3cbeSEric Kohl 
53676efb3cbeSEric Kohl     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
53686efb3cbeSEric Kohl     if (lpDevInst == NULL)
53696efb3cbeSEric Kohl         return CR_INVALID_DEVNODE;
53706efb3cbeSEric Kohl 
53716efb3cbeSEric Kohl     RpcTryExcept
53726efb3cbeSEric Kohl     {
53736efb3cbeSEric Kohl         ret = PNP_GetNextResDes(BindingHandle,
53746efb3cbeSEric Kohl                                 lpDevInst,
5375894ad4f1SEric Kohl                                 ulLogConfTag,
5376894ad4f1SEric Kohl                                 ulLogConfType,
53776efb3cbeSEric Kohl                                 ForResource,
5378894ad4f1SEric Kohl                                 ulResDesTag,
5379894ad4f1SEric Kohl                                 &ulNextResDesTag,
5380894ad4f1SEric Kohl                                 &ulNextResDesType,
53816efb3cbeSEric Kohl                                 0);
53826efb3cbeSEric Kohl     }
53836efb3cbeSEric Kohl     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
53846efb3cbeSEric Kohl     {
53856efb3cbeSEric Kohl         ret = RpcStatusToCmStatus(RpcExceptionCode());
53866efb3cbeSEric Kohl     }
53876efb3cbeSEric Kohl     RpcEndExcept;
53886efb3cbeSEric Kohl 
53896efb3cbeSEric Kohl     if (ret != CR_SUCCESS)
53906efb3cbeSEric Kohl         return ret;
53916efb3cbeSEric Kohl 
5392894ad4f1SEric Kohl     if (ForResource == ResType_All)
5393894ad4f1SEric Kohl         *pResourceID = ulNextResDesType;
5394894ad4f1SEric Kohl 
5395894ad4f1SEric Kohl     if (prdResDes)
5396894ad4f1SEric Kohl     {
5397894ad4f1SEric Kohl         pNewResDesInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(RES_DES_INFO));
5398894ad4f1SEric Kohl         if (pNewResDesInfo == NULL)
5399894ad4f1SEric Kohl             return CR_OUT_OF_MEMORY;
5400894ad4f1SEric Kohl 
5401894ad4f1SEric Kohl         pNewResDesInfo->ulMagic = LOG_CONF_MAGIC;
5402894ad4f1SEric Kohl         pNewResDesInfo->dnDevInst = dnDevInst;
5403894ad4f1SEric Kohl         pNewResDesInfo->ulLogConfType = ulLogConfType;
5404894ad4f1SEric Kohl         pNewResDesInfo->ulLogConfTag = ulLogConfTag;
5405894ad4f1SEric Kohl         pNewResDesInfo->ulResDesType = ulNextResDesType;
5406894ad4f1SEric Kohl         pNewResDesInfo->ulResDesTag = ulNextResDesTag;
5407894ad4f1SEric Kohl 
5408894ad4f1SEric Kohl         *prdResDes = (RES_DES)pNewResDesInfo;
5409894ad4f1SEric Kohl     }
54106efb3cbeSEric Kohl 
54116efb3cbeSEric Kohl     return CR_SUCCESS;
5412c2c66affSColin Finck }
5413c2c66affSColin Finck 
5414c2c66affSColin Finck 
5415c2c66affSColin Finck /***********************************************************************
5416c2c66affSColin Finck  * CM_Get_Parent [SETUPAPI.@]
5417c2c66affSColin Finck  */
541860a21894SEric Kohl CONFIGRET
541960a21894SEric Kohl WINAPI
542060a21894SEric Kohl CM_Get_Parent(
542160a21894SEric Kohl     _Out_ PDEVINST pdnDevInst,
542260a21894SEric Kohl     _In_ DEVINST dnDevInst,
542360a21894SEric Kohl     _In_ ULONG ulFlags)
5424c2c66affSColin Finck {
542560a21894SEric Kohl     TRACE("CM_Get_Parent(%p %p %lx)\n",
542660a21894SEric Kohl           pdnDevInst, dnDevInst, ulFlags);
542760a21894SEric Kohl 
5428c2c66affSColin Finck     return CM_Get_Parent_Ex(pdnDevInst, dnDevInst, ulFlags, NULL);
5429c2c66affSColin Finck }
5430c2c66affSColin Finck 
5431c2c66affSColin Finck 
5432c2c66affSColin Finck /***********************************************************************
5433c2c66affSColin Finck  * CM_Get_Parent_Ex [SETUPAPI.@]
5434c2c66affSColin Finck  */
543560a21894SEric Kohl CONFIGRET
543660a21894SEric Kohl WINAPI
543760a21894SEric Kohl CM_Get_Parent_Ex(
543860a21894SEric Kohl     _Out_ PDEVINST pdnDevInst,
543960a21894SEric Kohl     _In_ DEVINST dnDevInst,
544060a21894SEric Kohl     _In_ ULONG ulFlags,
544160a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
5442c2c66affSColin Finck {
5443c2c66affSColin Finck     WCHAR szRelatedDevInst[MAX_DEVICE_ID_LEN];
5444c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5445c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
5446c2c66affSColin Finck     LPWSTR lpDevInst;
5447c2c66affSColin Finck     DWORD dwIndex, dwLength = MAX_DEVICE_ID_LEN;
5448c2c66affSColin Finck     CONFIGRET ret;
5449c2c66affSColin Finck 
545060a21894SEric Kohl     TRACE("CM_Get_Parent_Ex(%p %lx %lx %p)\n",
545160a21894SEric Kohl           pdnDevInst, dnDevInst, ulFlags, hMachine);
5452c2c66affSColin Finck 
5453c2c66affSColin Finck     if (pdnDevInst == NULL)
5454c2c66affSColin Finck         return CR_INVALID_POINTER;
5455c2c66affSColin Finck 
5456c2c66affSColin Finck     if (dnDevInst == 0)
5457c2c66affSColin Finck         return CR_INVALID_DEVINST;
5458c2c66affSColin Finck 
5459c2c66affSColin Finck     if (ulFlags != 0)
5460c2c66affSColin Finck         return CR_INVALID_FLAG;
5461c2c66affSColin Finck 
5462c2c66affSColin Finck     *pdnDevInst = -1;
5463c2c66affSColin Finck 
5464c2c66affSColin Finck     if (hMachine != NULL)
5465c2c66affSColin Finck     {
5466c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5467c2c66affSColin Finck         if (BindingHandle == NULL)
5468c2c66affSColin Finck             return CR_FAILURE;
5469c2c66affSColin Finck 
5470c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
5471c2c66affSColin Finck         if (StringTable == 0)
5472c2c66affSColin Finck             return CR_FAILURE;
5473c2c66affSColin Finck     }
5474c2c66affSColin Finck     else
5475c2c66affSColin Finck     {
5476c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
5477c2c66affSColin Finck             return CR_FAILURE;
5478c2c66affSColin Finck     }
5479c2c66affSColin Finck 
5480c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
5481c2c66affSColin Finck     if (lpDevInst == NULL)
5482c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5483c2c66affSColin Finck 
5484c2c66affSColin Finck     RpcTryExcept
5485c2c66affSColin Finck     {
5486c2c66affSColin Finck         ret = PNP_GetRelatedDeviceInstance(BindingHandle,
5487c2c66affSColin Finck                                            PNP_GET_PARENT_DEVICE_INSTANCE,
5488c2c66affSColin Finck                                            lpDevInst,
5489c2c66affSColin Finck                                            szRelatedDevInst,
5490c2c66affSColin Finck                                            &dwLength,
5491c2c66affSColin Finck                                            0);
5492c2c66affSColin Finck     }
5493c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5494c2c66affSColin Finck     {
5495c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5496c2c66affSColin Finck     }
5497c2c66affSColin Finck     RpcEndExcept;
5498c2c66affSColin Finck 
5499c2c66affSColin Finck     if (ret != CR_SUCCESS)
5500c2c66affSColin Finck         return ret;
5501c2c66affSColin Finck 
5502c2c66affSColin Finck     TRACE("szRelatedDevInst: %s\n", debugstr_w(szRelatedDevInst));
5503c2c66affSColin Finck 
5504c2c66affSColin Finck     dwIndex = pSetupStringTableAddString(StringTable, szRelatedDevInst, 1);
5505c2c66affSColin Finck     if (dwIndex == -1)
5506c2c66affSColin Finck         return CR_FAILURE;
5507c2c66affSColin Finck 
5508c2c66affSColin Finck     *pdnDevInst = dwIndex;
5509c2c66affSColin Finck 
5510c2c66affSColin Finck     return CR_SUCCESS;
5511c2c66affSColin Finck }
5512c2c66affSColin Finck 
5513c2c66affSColin Finck 
5514c2c66affSColin Finck /***********************************************************************
5515c2c66affSColin Finck  * CM_Get_Res_Des_Data [SETUPAPI.@]
5516c2c66affSColin Finck  */
551760a21894SEric Kohl CONFIGRET
551860a21894SEric Kohl WINAPI
551960a21894SEric Kohl CM_Get_Res_Des_Data(
552060a21894SEric Kohl     _In_ RES_DES rdResDes,
552160a21894SEric Kohl     _Out_writes_bytes_(BufferLen) PVOID Buffer,
552260a21894SEric Kohl     _In_ ULONG BufferLen,
552360a21894SEric Kohl     _In_ ULONG ulFlags)
5524c2c66affSColin Finck {
552560a21894SEric Kohl     TRACE("CM_Get_Res_Des_Data(%p %p %lu %lx)\n",
552660a21894SEric Kohl           rdResDes, Buffer, BufferLen, ulFlags);
552760a21894SEric Kohl 
5528c2c66affSColin Finck     return CM_Get_Res_Des_Data_Ex(rdResDes, Buffer, BufferLen, ulFlags, NULL);
5529c2c66affSColin Finck }
5530c2c66affSColin Finck 
5531c2c66affSColin Finck 
5532c2c66affSColin Finck /***********************************************************************
5533c2c66affSColin Finck  * CM_Get_Res_Des_Data_Ex [SETUPAPI.@]
5534c2c66affSColin Finck  */
553560a21894SEric Kohl CONFIGRET
553660a21894SEric Kohl WINAPI
553760a21894SEric Kohl CM_Get_Res_Des_Data_Ex(
553860a21894SEric Kohl     _In_ RES_DES rdResDes,
553960a21894SEric Kohl     _Out_writes_bytes_(BufferLen) PVOID Buffer,
554060a21894SEric Kohl     _In_ ULONG BufferLen,
554160a21894SEric Kohl     _In_ ULONG ulFlags,
554260a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
5543c2c66affSColin Finck {
554460a21894SEric Kohl     FIXME("CM_Get_Res_Des_Data_Ex(%p %p %lu %lx %p)\n",
554560a21894SEric Kohl           rdResDes, Buffer, BufferLen, ulFlags, hMachine);
554660a21894SEric Kohl 
5547c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
5548c2c66affSColin Finck }
5549c2c66affSColin Finck 
5550c2c66affSColin Finck 
5551c2c66affSColin Finck /***********************************************************************
5552c2c66affSColin Finck  * CM_Get_Res_Des_Size [SETUPAPI.@]
5553c2c66affSColin Finck  */
555460a21894SEric Kohl CONFIGRET
555560a21894SEric Kohl WINAPI
555660a21894SEric Kohl CM_Get_Res_Des_Data_Size(
555760a21894SEric Kohl     _Out_ PULONG pulSize,
555860a21894SEric Kohl     _In_ RES_DES rdResDes,
555960a21894SEric Kohl     _In_ ULONG ulFlags)
5560c2c66affSColin Finck {
556160a21894SEric Kohl     TRACE("CM_Get_Res_Des_Data_Size(%p %p %lx)\n",
556260a21894SEric Kohl           pulSize, rdResDes, ulFlags);
556360a21894SEric Kohl 
5564c2c66affSColin Finck     return CM_Get_Res_Des_Data_Size_Ex(pulSize, rdResDes, ulFlags, NULL);
5565c2c66affSColin Finck }
5566c2c66affSColin Finck 
5567c2c66affSColin Finck 
5568c2c66affSColin Finck /***********************************************************************
5569c2c66affSColin Finck  * CM_Get_Res_Des_Size_Ex [SETUPAPI.@]
5570c2c66affSColin Finck  */
557160a21894SEric Kohl CONFIGRET
557260a21894SEric Kohl WINAPI
557360a21894SEric Kohl CM_Get_Res_Des_Data_Size_Ex(
557460a21894SEric Kohl     _Out_ PULONG pulSize,
557560a21894SEric Kohl     _In_ RES_DES rdResDes,
557660a21894SEric Kohl     _In_ ULONG ulFlags,
557760a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
5578c2c66affSColin Finck {
557960a21894SEric Kohl     TRACE("CM_Get_Res_Des_Data_Size_Ex(%p %p %lx %p)\n",
558060a21894SEric Kohl           pulSize, rdResDes, ulFlags, hMachine);
558160a21894SEric Kohl 
5582c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
5583c2c66affSColin Finck }
5584c2c66affSColin Finck 
5585c2c66affSColin Finck 
5586c2c66affSColin Finck /***********************************************************************
5587d1c376f3SEric Kohl  * CM_Get_Resource_Conflict_Count [SETUPAPI.@]
5588d1c376f3SEric Kohl  */
5589d1c376f3SEric Kohl CONFIGRET
5590d1c376f3SEric Kohl WINAPI
5591d1c376f3SEric Kohl CM_Get_Resource_Conflict_Count(
5592d1c376f3SEric Kohl     _In_ CONFLICT_LIST clConflictList,
5593d1c376f3SEric Kohl     _Out_ PULONG pulCount)
5594d1c376f3SEric Kohl {
5595d1c376f3SEric Kohl     PCONFLICT_DATA pConflictData;
5596d1c376f3SEric Kohl 
5597d1c376f3SEric Kohl     FIXME("CM_Get_Resource_Conflict_Count(%p %p)\n",
5598d1c376f3SEric Kohl           clConflictList, pulCount);
5599d1c376f3SEric Kohl 
5600d1c376f3SEric Kohl     pConflictData = (PCONFLICT_DATA)clConflictList;
5601d1c376f3SEric Kohl     if (!IsValidConflictData(pConflictData))
5602d1c376f3SEric Kohl         return CR_INVALID_CONFLICT_LIST;
5603d1c376f3SEric Kohl 
5604d1c376f3SEric Kohl     if (pulCount == NULL)
5605d1c376f3SEric Kohl         return CR_INVALID_POINTER;
5606d1c376f3SEric Kohl 
5607d1c376f3SEric Kohl     *pulCount = pConflictData->pConflictList->ConflictsListed;
5608d1c376f3SEric Kohl 
5609d1c376f3SEric Kohl     return CR_SUCCESS;
5610d1c376f3SEric Kohl }
5611d1c376f3SEric Kohl 
5612d1c376f3SEric Kohl 
5613d1c376f3SEric Kohl /***********************************************************************
5614d1c376f3SEric Kohl  * CM_Get_Resource_Conflict_DetailsA [SETUPAPI.@]
5615d1c376f3SEric Kohl  */
5616d1c376f3SEric Kohl CONFIGRET
5617d1c376f3SEric Kohl WINAPI
5618d1c376f3SEric Kohl CM_Get_Resource_Conflict_DetailsA(
5619d1c376f3SEric Kohl     _In_ CONFLICT_LIST clConflictList,
5620d1c376f3SEric Kohl     _In_ ULONG ulIndex,
5621d1c376f3SEric Kohl     _Inout_ PCONFLICT_DETAILS_A pConflictDetails)
5622d1c376f3SEric Kohl {
5623d1c376f3SEric Kohl     FIXME("CM_Get_Resource_Conflict_CountA(%p %lu %p)\n",
5624d1c376f3SEric Kohl           clConflictList, ulIndex, pConflictDetails);
5625d1c376f3SEric Kohl 
5626d1c376f3SEric Kohl     return CR_CALL_NOT_IMPLEMENTED;
5627d1c376f3SEric Kohl }
5628d1c376f3SEric Kohl 
5629d1c376f3SEric Kohl 
5630d1c376f3SEric Kohl /***********************************************************************
5631d1c376f3SEric Kohl  * CM_Get_Resource_Conflict_DetailsW [SETUPAPI.@]
5632d1c376f3SEric Kohl  */
5633d1c376f3SEric Kohl CONFIGRET
5634d1c376f3SEric Kohl WINAPI
5635d1c376f3SEric Kohl CM_Get_Resource_Conflict_DetailsW(
5636d1c376f3SEric Kohl     _In_ CONFLICT_LIST clConflictList,
5637d1c376f3SEric Kohl     _In_ ULONG ulIndex,
5638d1c376f3SEric Kohl     _Inout_ PCONFLICT_DETAILS_W pConflictDetails)
5639d1c376f3SEric Kohl {
5640d1c376f3SEric Kohl     FIXME("CM_Get_Resource_Conflict_CountW(%p %lu %p)\n",
5641d1c376f3SEric Kohl           clConflictList, ulIndex, pConflictDetails);
5642d1c376f3SEric Kohl 
5643d1c376f3SEric Kohl     return CR_CALL_NOT_IMPLEMENTED;
5644d1c376f3SEric Kohl }
5645d1c376f3SEric Kohl 
5646d1c376f3SEric Kohl 
5647d1c376f3SEric Kohl /***********************************************************************
5648c2c66affSColin Finck  * CM_Get_Sibling [SETUPAPI.@]
5649c2c66affSColin Finck  */
565060a21894SEric Kohl CONFIGRET
565160a21894SEric Kohl WINAPI
565260a21894SEric Kohl CM_Get_Sibling(
565360a21894SEric Kohl     _Out_ PDEVINST pdnDevInst,
565460a21894SEric Kohl     _In_ DEVINST dnDevInst,
565560a21894SEric Kohl     _In_ ULONG ulFlags)
5656c2c66affSColin Finck {
565760a21894SEric Kohl     TRACE("CM_Get_Sibling(%p %p %lx)\n",
565860a21894SEric Kohl           pdnDevInst, dnDevInst, ulFlags);
565960a21894SEric Kohl 
5660c2c66affSColin Finck     return CM_Get_Sibling_Ex(pdnDevInst, dnDevInst, ulFlags, NULL);
5661c2c66affSColin Finck }
5662c2c66affSColin Finck 
5663c2c66affSColin Finck 
5664c2c66affSColin Finck /***********************************************************************
5665c2c66affSColin Finck  * CM_Get_Sibling_Ex [SETUPAPI.@]
5666c2c66affSColin Finck  */
566760a21894SEric Kohl CONFIGRET
566860a21894SEric Kohl WINAPI
566960a21894SEric Kohl CM_Get_Sibling_Ex(
567060a21894SEric Kohl     _Out_ PDEVINST pdnDevInst,
567160a21894SEric Kohl     _In_ DEVINST dnDevInst,
567260a21894SEric Kohl     _In_ ULONG ulFlags,
567360a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
5674c2c66affSColin Finck {
5675c2c66affSColin Finck     WCHAR szRelatedDevInst[MAX_DEVICE_ID_LEN];
5676c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5677c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
5678c2c66affSColin Finck     LPWSTR lpDevInst;
5679c2c66affSColin Finck     DWORD dwIndex, dwLength = MAX_DEVICE_ID_LEN;
5680c2c66affSColin Finck     CONFIGRET ret;
5681c2c66affSColin Finck 
568260a21894SEric Kohl     TRACE("CM_Get_Sibling_Ex(%p %lx %lx %p)\n",
568360a21894SEric Kohl           pdnDevInst, dnDevInst, ulFlags, hMachine);
5684c2c66affSColin Finck 
5685c2c66affSColin Finck     if (pdnDevInst == NULL)
5686c2c66affSColin Finck         return CR_INVALID_POINTER;
5687c2c66affSColin Finck 
5688c2c66affSColin Finck     if (dnDevInst == 0)
5689c2c66affSColin Finck         return CR_INVALID_DEVINST;
5690c2c66affSColin Finck 
5691c2c66affSColin Finck     if (ulFlags != 0)
5692c2c66affSColin Finck         return CR_INVALID_FLAG;
5693c2c66affSColin Finck 
5694c2c66affSColin Finck     *pdnDevInst = -1;
5695c2c66affSColin Finck 
5696c2c66affSColin Finck     if (hMachine != NULL)
5697c2c66affSColin Finck     {
5698c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5699c2c66affSColin Finck         if (BindingHandle == NULL)
5700c2c66affSColin Finck             return CR_FAILURE;
5701c2c66affSColin Finck 
5702c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
5703c2c66affSColin Finck         if (StringTable == 0)
5704c2c66affSColin Finck             return CR_FAILURE;
5705c2c66affSColin Finck     }
5706c2c66affSColin Finck     else
5707c2c66affSColin Finck     {
5708c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
5709c2c66affSColin Finck             return CR_FAILURE;
5710c2c66affSColin Finck     }
5711c2c66affSColin Finck 
5712c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
5713c2c66affSColin Finck     if (lpDevInst == NULL)
5714c2c66affSColin Finck         return CR_INVALID_DEVNODE;
5715c2c66affSColin Finck 
5716c2c66affSColin Finck     RpcTryExcept
5717c2c66affSColin Finck     {
5718c2c66affSColin Finck         ret = PNP_GetRelatedDeviceInstance(BindingHandle,
5719c2c66affSColin Finck                                            PNP_GET_SIBLING_DEVICE_INSTANCE,
5720c2c66affSColin Finck                                            lpDevInst,
5721c2c66affSColin Finck                                            szRelatedDevInst,
5722c2c66affSColin Finck                                            &dwLength,
5723c2c66affSColin Finck                                            0);
5724c2c66affSColin Finck     }
5725c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5726c2c66affSColin Finck     {
5727c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5728c2c66affSColin Finck     }
5729c2c66affSColin Finck     RpcEndExcept;
5730c2c66affSColin Finck 
5731c2c66affSColin Finck     if (ret != CR_SUCCESS)
5732c2c66affSColin Finck         return ret;
5733c2c66affSColin Finck 
5734c2c66affSColin Finck     TRACE("szRelatedDevInst: %s\n", debugstr_w(szRelatedDevInst));
5735c2c66affSColin Finck 
5736c2c66affSColin Finck     dwIndex = pSetupStringTableAddString(StringTable, szRelatedDevInst, 1);
5737c2c66affSColin Finck     if (dwIndex == -1)
5738c2c66affSColin Finck         return CR_FAILURE;
5739c2c66affSColin Finck 
5740c2c66affSColin Finck     *pdnDevInst = dwIndex;
5741c2c66affSColin Finck 
5742c2c66affSColin Finck     return CR_SUCCESS;
5743c2c66affSColin Finck }
5744c2c66affSColin Finck 
5745c2c66affSColin Finck 
5746c2c66affSColin Finck /***********************************************************************
5747c2c66affSColin Finck  * CM_Get_Version [SETUPAPI.@]
5748c2c66affSColin Finck  */
574960a21894SEric Kohl WORD
575060a21894SEric Kohl WINAPI
575160a21894SEric Kohl CM_Get_Version(VOID)
5752c2c66affSColin Finck {
575360a21894SEric Kohl     TRACE("CM_Get_Version()\n");
575460a21894SEric Kohl 
5755c2c66affSColin Finck     return CM_Get_Version_Ex(NULL);
5756c2c66affSColin Finck }
5757c2c66affSColin Finck 
5758c2c66affSColin Finck 
5759c2c66affSColin Finck /***********************************************************************
5760c2c66affSColin Finck  * CM_Get_Version_Ex [SETUPAPI.@]
5761c2c66affSColin Finck  */
576260a21894SEric Kohl WORD
576360a21894SEric Kohl WINAPI
576460a21894SEric Kohl CM_Get_Version_Ex(
576560a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
5766c2c66affSColin Finck {
5767c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5768c2c66affSColin Finck     WORD Version = 0;
5769c2c66affSColin Finck     CONFIGRET ret;
5770c2c66affSColin Finck 
577160a21894SEric Kohl     TRACE("CM_Get_Version_Ex(%p)\n", hMachine);
5772c2c66affSColin Finck 
5773c2c66affSColin Finck     if (hMachine != NULL)
5774c2c66affSColin Finck     {
5775c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5776c2c66affSColin Finck         if (BindingHandle == NULL)
5777c2c66affSColin Finck             return 0;
5778c2c66affSColin Finck     }
5779c2c66affSColin Finck     else
5780c2c66affSColin Finck     {
5781c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
5782c2c66affSColin Finck             return CR_FAILURE;
5783c2c66affSColin Finck     }
5784c2c66affSColin Finck 
5785c2c66affSColin Finck     RpcTryExcept
5786c2c66affSColin Finck     {
5787c2c66affSColin Finck         ret = PNP_GetVersion(BindingHandle, &Version);
5788c2c66affSColin Finck     }
5789c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5790c2c66affSColin Finck     {
5791c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5792c2c66affSColin Finck     }
5793c2c66affSColin Finck     RpcEndExcept;
5794c2c66affSColin Finck 
5795c2c66affSColin Finck     if (ret != CR_SUCCESS)
5796c2c66affSColin Finck         return 0;
5797c2c66affSColin Finck 
5798c2c66affSColin Finck     return Version;
5799c2c66affSColin Finck }
5800c2c66affSColin Finck 
5801c2c66affSColin Finck 
5802c2c66affSColin Finck /***********************************************************************
5803c2c66affSColin Finck  * CM_Intersect_Range_List [SETUPAPI.@]
5804c2c66affSColin Finck  */
5805c2c66affSColin Finck CONFIGRET
5806c2c66affSColin Finck WINAPI
5807c2c66affSColin Finck CM_Intersect_Range_List(
5808c2c66affSColin Finck     _In_ RANGE_LIST rlhOld1,
5809c2c66affSColin Finck     _In_ RANGE_LIST rlhOld2,
5810c2c66affSColin Finck     _In_ RANGE_LIST rlhNew,
5811c2c66affSColin Finck     _In_ ULONG ulFlags)
5812c2c66affSColin Finck {
5813c2c66affSColin Finck     FIXME("CM_Intersect_Range_List(%p %p %p %lx)\n",
5814c2c66affSColin Finck           rlhOld1, rlhOld2, rlhNew, ulFlags);
581565d3bf74SEric Kohl 
5816c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
5817c2c66affSColin Finck }
5818c2c66affSColin Finck 
5819c2c66affSColin Finck 
5820c2c66affSColin Finck /***********************************************************************
5821c2c66affSColin Finck  * CM_Invert_Range_List [SETUPAPI.@]
5822c2c66affSColin Finck  */
5823c2c66affSColin Finck CONFIGRET
5824c2c66affSColin Finck WINAPI
5825c2c66affSColin Finck CM_Invert_Range_List(
5826c2c66affSColin Finck     _In_ RANGE_LIST rlhOld,
5827c2c66affSColin Finck     _In_ RANGE_LIST rlhNew,
5828c2c66affSColin Finck     _In_ DWORDLONG ullMaxValue,
5829c2c66affSColin Finck     _In_ ULONG ulFlags)
5830c2c66affSColin Finck {
5831c2c66affSColin Finck     FIXME("CM_Invert_Range_List(%p %p %I64u %lx)\n",
5832c2c66affSColin Finck           rlhOld, rlhNew, ullMaxValue, ulFlags);
583365d3bf74SEric Kohl 
5834c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
5835c2c66affSColin Finck }
5836c2c66affSColin Finck 
5837c2c66affSColin Finck 
5838c2c66affSColin Finck /***********************************************************************
5839c2c66affSColin Finck  * CM_Is_Dock_Station_Present [SETUPAPI.@]
5840c2c66affSColin Finck  */
5841f86e78d0SEric Kohl CONFIGRET
5842f86e78d0SEric Kohl WINAPI
5843f86e78d0SEric Kohl CM_Is_Dock_Station_Present(
5844f86e78d0SEric Kohl     _Out_ PBOOL pbPresent)
5845c2c66affSColin Finck {
5846f86e78d0SEric Kohl     TRACE("CM_Is_Dock_Station_Present(%p)\n",
5847f86e78d0SEric Kohl           pbPresent);
584865d3bf74SEric Kohl 
5849c2c66affSColin Finck     return CM_Is_Dock_Station_Present_Ex(pbPresent, NULL);
5850c2c66affSColin Finck }
5851c2c66affSColin Finck 
5852c2c66affSColin Finck 
5853c2c66affSColin Finck /***********************************************************************
5854c2c66affSColin Finck  * CM_Is_Dock_Station_Present_Ex [SETUPAPI.@]
5855c2c66affSColin Finck  */
5856f86e78d0SEric Kohl CONFIGRET
5857f86e78d0SEric Kohl WINAPI
5858f86e78d0SEric Kohl CM_Is_Dock_Station_Present_Ex(
5859f86e78d0SEric Kohl     _Out_ PBOOL pbPresent,
5860f86e78d0SEric Kohl     _In_opt_ HMACHINE hMachine)
5861c2c66affSColin Finck {
5862c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5863c2c66affSColin Finck     CONFIGRET ret;
5864c2c66affSColin Finck 
586560a21894SEric Kohl     TRACE("CM_Is_Dock_Station_Present_Ex(%p %p)\n",
5866f86e78d0SEric Kohl           pbPresent, hMachine);
5867c2c66affSColin Finck 
5868c2c66affSColin Finck     if (pbPresent == NULL)
5869c2c66affSColin Finck         return CR_INVALID_POINTER;
5870c2c66affSColin Finck 
5871c2c66affSColin Finck     *pbPresent = FALSE;
5872c2c66affSColin Finck 
5873c2c66affSColin Finck     if (hMachine != NULL)
5874c2c66affSColin Finck     {
5875c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5876c2c66affSColin Finck         if (BindingHandle == NULL)
5877c2c66affSColin Finck             return CR_FAILURE;
5878c2c66affSColin Finck     }
5879c2c66affSColin Finck     else
5880c2c66affSColin Finck     {
5881c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
5882c2c66affSColin Finck             return CR_FAILURE;
5883c2c66affSColin Finck     }
5884c2c66affSColin Finck 
5885c2c66affSColin Finck     RpcTryExcept
5886c2c66affSColin Finck     {
5887c2c66affSColin Finck         ret = PNP_IsDockStationPresent(BindingHandle,
5888c2c66affSColin Finck                                        pbPresent);
5889c2c66affSColin Finck     }
5890c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5891c2c66affSColin Finck     {
5892c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5893c2c66affSColin Finck     }
5894c2c66affSColin Finck     RpcEndExcept;
5895c2c66affSColin Finck 
5896c2c66affSColin Finck     return ret;
5897c2c66affSColin Finck }
5898c2c66affSColin Finck 
5899c2c66affSColin Finck 
5900c2c66affSColin Finck /***********************************************************************
5901c2c66affSColin Finck  * CM_Is_Version_Available_Ex [SETUPAPI.@]
5902c2c66affSColin Finck  */
5903f86e78d0SEric Kohl BOOL
5904f86e78d0SEric Kohl WINAPI
5905f86e78d0SEric Kohl CM_Is_Version_Available(
5906f86e78d0SEric Kohl      _In_ WORD wVersion)
5907c2c66affSColin Finck {
5908f86e78d0SEric Kohl     TRACE("CM_Is_Version_Available(%hu)\n",
5909f86e78d0SEric Kohl           wVersion);
591065d3bf74SEric Kohl 
5911c2c66affSColin Finck     return CM_Is_Version_Available_Ex(wVersion, NULL);
5912c2c66affSColin Finck }
5913c2c66affSColin Finck 
5914c2c66affSColin Finck 
5915c2c66affSColin Finck /***********************************************************************
5916c2c66affSColin Finck  * CM_Is_Version_Available_Ex [SETUPAPI.@]
5917c2c66affSColin Finck  */
5918f86e78d0SEric Kohl BOOL
5919f86e78d0SEric Kohl WINAPI
5920f86e78d0SEric Kohl CM_Is_Version_Available_Ex(
5921f86e78d0SEric Kohl     _In_ WORD wVersion,
5922f86e78d0SEric Kohl     _In_opt_ HMACHINE hMachine)
5923c2c66affSColin Finck {
5924c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
5925c2c66affSColin Finck     WORD wServerVersion;
5926c2c66affSColin Finck     CONFIGRET ret;
5927c2c66affSColin Finck 
592860a21894SEric Kohl     TRACE("CM_Is_Version_Available_Ex(%hu %p)\n",
5929f86e78d0SEric Kohl           wVersion, hMachine);
5930c2c66affSColin Finck 
5931c2c66affSColin Finck     if (wVersion <= 0x400)
5932c2c66affSColin Finck         return TRUE;
5933c2c66affSColin Finck 
5934c2c66affSColin Finck     if (hMachine != NULL)
5935c2c66affSColin Finck     {
5936c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
5937c2c66affSColin Finck         if (BindingHandle == NULL)
5938c2c66affSColin Finck             return FALSE;
5939c2c66affSColin Finck     }
5940c2c66affSColin Finck     else
5941c2c66affSColin Finck     {
5942c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
5943c2c66affSColin Finck             return FALSE;
5944c2c66affSColin Finck     }
5945c2c66affSColin Finck 
5946c2c66affSColin Finck     RpcTryExcept
5947c2c66affSColin Finck     {
5948c2c66affSColin Finck         ret = PNP_GetVersion(BindingHandle, &wServerVersion);
5949c2c66affSColin Finck     }
5950c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
5951c2c66affSColin Finck     {
5952c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
5953c2c66affSColin Finck     }
5954c2c66affSColin Finck     RpcEndExcept;
5955c2c66affSColin Finck 
5956c2c66affSColin Finck     if (ret != CR_SUCCESS)
5957c2c66affSColin Finck         return FALSE;
5958c2c66affSColin Finck 
5959c2c66affSColin Finck     return (wServerVersion >= wVersion);
5960c2c66affSColin Finck }
5961c2c66affSColin Finck 
5962c2c66affSColin Finck 
5963c2c66affSColin Finck /***********************************************************************
5964c2c66affSColin Finck  * CM_Locate_DevNodeA [SETUPAPI.@]
5965c2c66affSColin Finck  */
5966f86e78d0SEric Kohl CONFIGRET
5967f86e78d0SEric Kohl WINAPI
5968f86e78d0SEric Kohl CM_Locate_DevNodeA(
5969f86e78d0SEric Kohl     _Out_ PDEVINST pdnDevInst,
5970f86e78d0SEric Kohl     _In_opt_ DEVINSTID_A pDeviceID,
5971f86e78d0SEric Kohl     _In_ ULONG ulFlags)
5972c2c66affSColin Finck {
597360a21894SEric Kohl     TRACE("CM_Locate_DevNodeA(%p %s %lx)\n",
597460a21894SEric Kohl           pdnDevInst, debugstr_a(pDeviceID), ulFlags);
597565d3bf74SEric Kohl 
5976c2c66affSColin Finck     return CM_Locate_DevNode_ExA(pdnDevInst, pDeviceID, ulFlags, NULL);
5977c2c66affSColin Finck }
5978c2c66affSColin Finck 
5979c2c66affSColin Finck 
5980c2c66affSColin Finck /***********************************************************************
5981c2c66affSColin Finck  * CM_Locate_DevNodeW [SETUPAPI.@]
5982c2c66affSColin Finck  */
5983f86e78d0SEric Kohl CONFIGRET
5984f86e78d0SEric Kohl WINAPI
5985f86e78d0SEric Kohl CM_Locate_DevNodeW(
5986f86e78d0SEric Kohl     _Out_ PDEVINST pdnDevInst,
5987f86e78d0SEric Kohl     _In_opt_ DEVINSTID_W pDeviceID,
5988f86e78d0SEric Kohl     _In_ ULONG ulFlags)
5989c2c66affSColin Finck {
599060a21894SEric Kohl     TRACE("CM_Locate_DevNodeW(%p %s %lx)\n",
5991f86e78d0SEric Kohl           pdnDevInst, debugstr_w(pDeviceID), ulFlags);
599265d3bf74SEric Kohl 
5993c2c66affSColin Finck     return CM_Locate_DevNode_ExW(pdnDevInst, pDeviceID, ulFlags, NULL);
5994c2c66affSColin Finck }
5995c2c66affSColin Finck 
5996c2c66affSColin Finck 
5997c2c66affSColin Finck /***********************************************************************
5998c2c66affSColin Finck  * CM_Locate_DevNode_ExA [SETUPAPI.@]
5999c2c66affSColin Finck  */
6000f86e78d0SEric Kohl CONFIGRET
6001f86e78d0SEric Kohl WINAPI
6002f86e78d0SEric Kohl CM_Locate_DevNode_ExA(
6003f86e78d0SEric Kohl     _Out_ PDEVINST pdnDevInst,
6004f86e78d0SEric Kohl     _In_opt_ DEVINSTID_A pDeviceID,
6005f86e78d0SEric Kohl     _In_ ULONG ulFlags,
6006f86e78d0SEric Kohl     _In_opt_ HMACHINE hMachine)
6007c2c66affSColin Finck {
6008c2c66affSColin Finck     DEVINSTID_W pDevIdW = NULL;
6009c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
6010c2c66affSColin Finck 
601160a21894SEric Kohl     TRACE("CM_Locate_DevNode_ExA(%p %s %lx %p)\n",
601260a21894SEric Kohl           pdnDevInst, debugstr_a(pDeviceID), ulFlags, hMachine);
6013c2c66affSColin Finck 
6014c2c66affSColin Finck     if (pDeviceID != NULL)
6015c2c66affSColin Finck     {
6016c2c66affSColin Finck        if (pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDevIdW))
6017c2c66affSColin Finck          return CR_INVALID_DEVICE_ID;
6018c2c66affSColin Finck     }
6019c2c66affSColin Finck 
6020c2c66affSColin Finck     ret = CM_Locate_DevNode_ExW(pdnDevInst, pDevIdW, ulFlags, hMachine);
6021c2c66affSColin Finck 
6022c2c66affSColin Finck     if (pDevIdW != NULL)
6023c2c66affSColin Finck         MyFree(pDevIdW);
6024c2c66affSColin Finck 
6025c2c66affSColin Finck     return ret;
6026c2c66affSColin Finck }
6027c2c66affSColin Finck 
6028c2c66affSColin Finck 
6029c2c66affSColin Finck /***********************************************************************
6030c2c66affSColin Finck  * CM_Locate_DevNode_ExW [SETUPAPI.@]
6031c2c66affSColin Finck  */
6032f86e78d0SEric Kohl CONFIGRET
6033f86e78d0SEric Kohl WINAPI
6034f86e78d0SEric Kohl CM_Locate_DevNode_ExW(
6035f86e78d0SEric Kohl     _Out_ PDEVINST pdnDevInst,
6036f86e78d0SEric Kohl     _In_opt_ DEVINSTID_W pDeviceID,
6037f86e78d0SEric Kohl     _In_ ULONG ulFlags,
6038f86e78d0SEric Kohl     _In_opt_ HMACHINE hMachine)
6039c2c66affSColin Finck {
6040c2c66affSColin Finck     WCHAR DeviceIdBuffer[MAX_DEVICE_ID_LEN];
6041c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
6042c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
6043c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
6044c2c66affSColin Finck 
604560a21894SEric Kohl     TRACE("CM_Locate_DevNode_ExW(%p %s %lx %p)\n",
6046f86e78d0SEric Kohl           pdnDevInst, debugstr_w(pDeviceID), ulFlags, hMachine);
6047c2c66affSColin Finck 
6048c2c66affSColin Finck     if (pdnDevInst == NULL)
6049c2c66affSColin Finck         return CR_INVALID_POINTER;
6050c2c66affSColin Finck 
6051c2c66affSColin Finck     if (ulFlags & ~CM_LOCATE_DEVNODE_BITS)
6052c2c66affSColin Finck         return CR_INVALID_FLAG;
6053c2c66affSColin Finck 
6054c2c66affSColin Finck     if (hMachine != NULL)
6055c2c66affSColin Finck     {
6056c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
6057c2c66affSColin Finck         if (BindingHandle == NULL)
6058c2c66affSColin Finck             return CR_FAILURE;
6059c2c66affSColin Finck 
6060c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
6061c2c66affSColin Finck         if (StringTable == 0)
6062c2c66affSColin Finck             return CR_FAILURE;
6063c2c66affSColin Finck     }
6064c2c66affSColin Finck     else
6065c2c66affSColin Finck     {
6066c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
6067c2c66affSColin Finck             return CR_FAILURE;
6068c2c66affSColin Finck     }
6069c2c66affSColin Finck 
6070c2c66affSColin Finck     if (pDeviceID != NULL && lstrlenW(pDeviceID) != 0)
6071c2c66affSColin Finck     {
6072c2c66affSColin Finck         lstrcpyW(DeviceIdBuffer, pDeviceID);
6073dde7e6e2SEric Kohl 
6074dde7e6e2SEric Kohl         RpcTryExcept
6075dde7e6e2SEric Kohl         {
6076dde7e6e2SEric Kohl             /* Validate the device ID */
6077dde7e6e2SEric Kohl             ret = PNP_ValidateDeviceInstance(BindingHandle,
6078dde7e6e2SEric Kohl                                              DeviceIdBuffer,
6079dde7e6e2SEric Kohl                                              ulFlags);
6080dde7e6e2SEric Kohl         }
6081dde7e6e2SEric Kohl         RpcExcept(EXCEPTION_EXECUTE_HANDLER)
6082dde7e6e2SEric Kohl         {
6083dde7e6e2SEric Kohl             ret = RpcStatusToCmStatus(RpcExceptionCode());
6084dde7e6e2SEric Kohl         }
6085dde7e6e2SEric Kohl         RpcEndExcept;
6086c2c66affSColin Finck     }
6087c2c66affSColin Finck     else
6088c2c66affSColin Finck     {
6089c2c66affSColin Finck         RpcTryExcept
6090c2c66affSColin Finck         {
6091c2c66affSColin Finck             /* Get the root device ID */
6092c2c66affSColin Finck             ret = PNP_GetRootDeviceInstance(BindingHandle,
6093c2c66affSColin Finck                                             DeviceIdBuffer,
6094c2c66affSColin Finck                                             MAX_DEVICE_ID_LEN);
6095c2c66affSColin Finck         }
6096c2c66affSColin Finck         RpcExcept(EXCEPTION_EXECUTE_HANDLER)
6097c2c66affSColin Finck         {
6098c2c66affSColin Finck             ret = RpcStatusToCmStatus(RpcExceptionCode());
6099c2c66affSColin Finck         }
6100c2c66affSColin Finck         RpcEndExcept;
6101c2c66affSColin Finck     }
6102dde7e6e2SEric Kohl 
6103c2c66affSColin Finck     TRACE("DeviceIdBuffer: %s\n", debugstr_w(DeviceIdBuffer));
6104c2c66affSColin Finck 
6105c2c66affSColin Finck     if (ret == CR_SUCCESS)
6106c2c66affSColin Finck     {
6107c2c66affSColin Finck         *pdnDevInst = pSetupStringTableAddString(StringTable, DeviceIdBuffer, 1);
6108c2c66affSColin Finck         if (*pdnDevInst == -1)
6109c2c66affSColin Finck             ret = CR_FAILURE;
6110c2c66affSColin Finck     }
6111c2c66affSColin Finck 
6112c2c66affSColin Finck     return ret;
6113c2c66affSColin Finck }
6114c2c66affSColin Finck 
6115c2c66affSColin Finck 
6116c2c66affSColin Finck /***********************************************************************
6117c2c66affSColin Finck  * CM_Merge_Range_List [SETUPAPI.@]
6118c2c66affSColin Finck  */
6119c2c66affSColin Finck CONFIGRET
6120c2c66affSColin Finck WINAPI
6121c2c66affSColin Finck CM_Merge_Range_List(
6122c2c66affSColin Finck     _In_ RANGE_LIST rlhOld1,
6123c2c66affSColin Finck     _In_ RANGE_LIST rlhOld2,
6124c2c66affSColin Finck     _In_ RANGE_LIST rlhNew,
6125c2c66affSColin Finck     _In_ ULONG ulFlags)
6126c2c66affSColin Finck {
6127c2c66affSColin Finck     FIXME("CM_Merge_Range_List(%p %p %p %lx)\n",
6128c2c66affSColin Finck           rlhOld1, rlhOld2, rlhNew, ulFlags);
612965d3bf74SEric Kohl 
6130c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
6131c2c66affSColin Finck }
6132c2c66affSColin Finck 
6133c2c66affSColin Finck 
6134c2c66affSColin Finck /***********************************************************************
6135c2c66affSColin Finck  * CM_Modify_Res_Des [SETUPAPI.@]
6136c2c66affSColin Finck  */
6137f86e78d0SEric Kohl CONFIGRET
6138f86e78d0SEric Kohl WINAPI
6139f86e78d0SEric Kohl CM_Modify_Res_Des(
6140f86e78d0SEric Kohl     _Out_ PRES_DES prdResDes,
6141f86e78d0SEric Kohl     _In_ RES_DES rdResDes,
6142f86e78d0SEric Kohl     _In_ RESOURCEID ResourceID,
614360a21894SEric Kohl     _In_reads_bytes_(ResourceLen) PCVOID ResourceData,
6144f86e78d0SEric Kohl     _In_ ULONG ResourceLen,
6145f86e78d0SEric Kohl     _In_ ULONG ulFlags)
6146c2c66affSColin Finck {
6147f86e78d0SEric Kohl     TRACE("CM_Modify_Res_Des(%p %p %lx %p %lu %lx)\n",
6148f86e78d0SEric Kohl           prdResDes, rdResDes, ResourceID, ResourceData,
6149c2c66affSColin Finck           ResourceLen, ulFlags);
615065d3bf74SEric Kohl 
6151c2c66affSColin Finck     return CM_Modify_Res_Des_Ex(prdResDes, rdResDes, ResourceID, ResourceData,
6152c2c66affSColin Finck                                 ResourceLen, ulFlags, NULL);
6153c2c66affSColin Finck }
6154c2c66affSColin Finck 
6155c2c66affSColin Finck 
6156c2c66affSColin Finck /***********************************************************************
6157c2c66affSColin Finck  * CM_Modify_Res_Des_Ex [SETUPAPI.@]
6158c2c66affSColin Finck  */
6159f86e78d0SEric Kohl CONFIGRET
6160f86e78d0SEric Kohl WINAPI
6161f86e78d0SEric Kohl CM_Modify_Res_Des_Ex(
6162f86e78d0SEric Kohl     _Out_ PRES_DES prdResDes,
6163f86e78d0SEric Kohl     _In_ RES_DES rdResDes,
6164f86e78d0SEric Kohl     _In_ RESOURCEID ResourceID,
616560a21894SEric Kohl     _In_reads_bytes_(ResourceLen) PCVOID ResourceData,
6166f86e78d0SEric Kohl     _In_ ULONG ResourceLen,
6167f86e78d0SEric Kohl     _In_ ULONG ulFlags,
6168f86e78d0SEric Kohl     _In_opt_ HMACHINE hMachine)
6169c2c66affSColin Finck {
617060a21894SEric Kohl     FIXME("CM_Modify_Res_Des_Ex(%p %p %lx %p %lu %lx %p)\n",
6171f86e78d0SEric Kohl           prdResDes, rdResDes, ResourceID, ResourceData,
6172c2c66affSColin Finck           ResourceLen, ulFlags, hMachine);
617365d3bf74SEric Kohl 
6174c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
6175c2c66affSColin Finck }
6176c2c66affSColin Finck 
6177c2c66affSColin Finck 
6178c2c66affSColin Finck /***********************************************************************
6179c2c66affSColin Finck  * CM_Move_DevNode [SETUPAPI.@]
6180c2c66affSColin Finck  */
6181f86e78d0SEric Kohl CONFIGRET
6182f86e78d0SEric Kohl WINAPI
6183f86e78d0SEric Kohl CM_Move_DevNode(
6184f86e78d0SEric Kohl     _In_ DEVINST dnFromDevInst,
6185f86e78d0SEric Kohl     _In_ DEVINST dnToDevInst,
6186f86e78d0SEric Kohl     _In_ ULONG ulFlags)
6187c2c66affSColin Finck {
6188f86e78d0SEric Kohl     TRACE("CM_Move_DevNode(%lx %lx %lx)\n",
6189f86e78d0SEric Kohl           dnFromDevInst, dnToDevInst, ulFlags);
619065d3bf74SEric Kohl 
6191c2c66affSColin Finck     return CM_Move_DevNode_Ex(dnFromDevInst, dnToDevInst, ulFlags, NULL);
6192c2c66affSColin Finck }
6193c2c66affSColin Finck 
6194c2c66affSColin Finck 
6195c2c66affSColin Finck /***********************************************************************
6196c2c66affSColin Finck  * CM_Move_DevNode_Ex [SETUPAPI.@]
6197c2c66affSColin Finck  */
6198f86e78d0SEric Kohl CONFIGRET
6199f86e78d0SEric Kohl WINAPI
6200f86e78d0SEric Kohl CM_Move_DevNode_Ex(
6201f86e78d0SEric Kohl     _In_ DEVINST dnFromDevInst,
6202f86e78d0SEric Kohl     _In_ DEVINST dnToDevInst,
6203f86e78d0SEric Kohl     _In_ ULONG ulFlags,
6204f86e78d0SEric Kohl     _In_opt_ HMACHINE hMachine)
6205c2c66affSColin Finck {
6206c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
6207c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
6208c2c66affSColin Finck     LPWSTR lpFromDevInst;
6209c2c66affSColin Finck     LPWSTR lpToDevInst;
6210c2c66affSColin Finck     CONFIGRET ret;
6211c2c66affSColin Finck 
621260a21894SEric Kohl     FIXME("CM_Move_DevNode_Ex(%lx %lx %lx %p)\n",
6213c2c66affSColin Finck           dnFromDevInst, dnToDevInst, ulFlags, hMachine);
6214c2c66affSColin Finck 
6215c2c66affSColin Finck     if (!pSetupIsUserAdmin())
6216c2c66affSColin Finck         return CR_ACCESS_DENIED;
6217c2c66affSColin Finck 
6218c2c66affSColin Finck     if (dnFromDevInst == 0 || dnToDevInst == 0)
6219c2c66affSColin Finck         return CR_INVALID_DEVNODE;
6220c2c66affSColin Finck 
6221c2c66affSColin Finck     if (ulFlags != 0)
6222c2c66affSColin Finck         return CR_INVALID_FLAG;
6223c2c66affSColin Finck 
6224c2c66affSColin Finck     if (hMachine != NULL)
6225c2c66affSColin Finck     {
6226c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
6227c2c66affSColin Finck         if (BindingHandle == NULL)
6228c2c66affSColin Finck             return CR_FAILURE;
6229c2c66affSColin Finck 
6230c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
6231c2c66affSColin Finck         if (StringTable == 0)
6232c2c66affSColin Finck             return CR_FAILURE;
6233c2c66affSColin Finck     }
6234c2c66affSColin Finck     else
6235c2c66affSColin Finck     {
6236c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
6237c2c66affSColin Finck             return CR_FAILURE;
6238c2c66affSColin Finck     }
6239c2c66affSColin Finck 
6240c2c66affSColin Finck     lpFromDevInst = pSetupStringTableStringFromId(StringTable, dnFromDevInst);
6241c2c66affSColin Finck     if (lpFromDevInst == NULL)
6242c2c66affSColin Finck         return CR_INVALID_DEVNODE;
6243c2c66affSColin Finck 
6244c2c66affSColin Finck     lpToDevInst = pSetupStringTableStringFromId(StringTable, dnToDevInst);
6245c2c66affSColin Finck     if (lpToDevInst == NULL)
6246c2c66affSColin Finck         return CR_INVALID_DEVNODE;
6247c2c66affSColin Finck 
6248c2c66affSColin Finck     RpcTryExcept
6249c2c66affSColin Finck     {
6250c2c66affSColin Finck         ret = PNP_DeviceInstanceAction(BindingHandle,
6251c2c66affSColin Finck                                        PNP_DEVINST_MOVE,
6252c2c66affSColin Finck                                        ulFlags,
6253c2c66affSColin Finck                                        lpFromDevInst,
6254c2c66affSColin Finck                                        lpToDevInst);
6255c2c66affSColin Finck     }
6256c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
6257c2c66affSColin Finck     {
6258c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
6259c2c66affSColin Finck     }
6260c2c66affSColin Finck     RpcEndExcept;
6261c2c66affSColin Finck 
6262c2c66affSColin Finck     return ret;
6263c2c66affSColin Finck }
6264c2c66affSColin Finck 
6265c2c66affSColin Finck 
6266c2c66affSColin Finck /***********************************************************************
6267c2c66affSColin Finck  * CM_Next_Range [SETUPAPI.@]
6268c2c66affSColin Finck  */
6269c2c66affSColin Finck CONFIGRET
6270c2c66affSColin Finck WINAPI
6271c2c66affSColin Finck CM_Next_Range(
6272c2c66affSColin Finck     _Inout_ PRANGE_ELEMENT preElement,
6273c2c66affSColin Finck     _Out_ PDWORDLONG pullStart,
6274c2c66affSColin Finck     _Out_ PDWORDLONG pullEnd,
6275c2c66affSColin Finck     _In_ ULONG ulFlags)
6276c2c66affSColin Finck {
6277e88a6b20SEric Kohl     PINTERNAL_RANGE_LIST pRangeList;
6278e88a6b20SEric Kohl     PINTERNAL_RANGE pRange;
6279e88a6b20SEric Kohl     PLIST_ENTRY ListEntry;
6280e88a6b20SEric Kohl     CONFIGRET ret = CR_SUCCESS;
6281e88a6b20SEric Kohl 
6282c2c66affSColin Finck     FIXME("CM_Next_Range(%p %p %p %lx)\n",
6283c2c66affSColin Finck           preElement, pullStart, pullEnd, ulFlags);
628465d3bf74SEric Kohl 
6285e88a6b20SEric Kohl     pRange = (PINTERNAL_RANGE)preElement;
6286e88a6b20SEric Kohl 
6287e88a6b20SEric Kohl     if (pRange == NULL || pRange->pRangeList == NULL)
6288e88a6b20SEric Kohl         return CR_FAILURE;
6289e88a6b20SEric Kohl 
6290e88a6b20SEric Kohl     if (pullStart == NULL || pullEnd == NULL)
6291e88a6b20SEric Kohl         return CR_INVALID_POINTER;
6292e88a6b20SEric Kohl 
6293e88a6b20SEric Kohl     if (ulFlags != 0)
6294e88a6b20SEric Kohl         return CR_INVALID_FLAG;
6295e88a6b20SEric Kohl 
6296e88a6b20SEric Kohl     pRangeList = pRange->pRangeList;
6297e88a6b20SEric Kohl 
6298e88a6b20SEric Kohl     /* Lock the range list */
6299e88a6b20SEric Kohl     WaitForSingleObject(pRangeList->hMutex, INFINITE);
6300e88a6b20SEric Kohl 
6301e88a6b20SEric Kohl     /* Fail, if we reached the end of the list */
6302e88a6b20SEric Kohl     if (pRange->ListEntry.Flink == &pRangeList->ListHead)
6303e88a6b20SEric Kohl     {
6304e88a6b20SEric Kohl         ret = CR_FAILURE;
6305e88a6b20SEric Kohl         goto done;
6306e88a6b20SEric Kohl     }
6307e88a6b20SEric Kohl 
6308e88a6b20SEric Kohl     /* Get the next range */
6309e88a6b20SEric Kohl     ListEntry = pRangeList->ListHead.Flink;
6310e88a6b20SEric Kohl     pRange = CONTAINING_RECORD(ListEntry, INTERNAL_RANGE, ListEntry);
6311e88a6b20SEric Kohl 
6312e88a6b20SEric Kohl     /* Return the range data */
6313e88a6b20SEric Kohl     *pullStart = pRange->ullStart;
6314e88a6b20SEric Kohl     *pullEnd = pRange->ullEnd;
6315e88a6b20SEric Kohl     *preElement = (RANGE_ELEMENT)pRange;
6316e88a6b20SEric Kohl 
6317e88a6b20SEric Kohl done:
6318e88a6b20SEric Kohl     /* Unlock the range list */
6319e88a6b20SEric Kohl     ReleaseMutex(pRangeList->hMutex);
6320e88a6b20SEric Kohl 
6321e88a6b20SEric Kohl     return ret;
6322c2c66affSColin Finck }
6323c2c66affSColin Finck 
6324c2c66affSColin Finck 
6325c2c66affSColin Finck /***********************************************************************
6326c2c66affSColin Finck  * CM_Open_Class_KeyA [SETUPAPI.@]
6327c2c66affSColin Finck  */
6328f86e78d0SEric Kohl CONFIGRET
6329f86e78d0SEric Kohl WINAPI
6330f86e78d0SEric Kohl CM_Open_Class_KeyA(
6331f86e78d0SEric Kohl     _In_opt_ LPGUID pClassGuid,
6332f86e78d0SEric Kohl     _In_opt_ LPCSTR pszClassName,
6333f86e78d0SEric Kohl     _In_ REGSAM samDesired,
6334f86e78d0SEric Kohl     _In_ REGDISPOSITION Disposition,
6335f86e78d0SEric Kohl     _Out_ PHKEY phkClass,
6336f86e78d0SEric Kohl     _In_ ULONG ulFlags)
6337c2c66affSColin Finck {
6338f86e78d0SEric Kohl     TRACE("CM_Open_Class_KeyA(%p %s %lx %lx %p %lx)\n",
633960a21894SEric Kohl           debugstr_guid(pClassGuid), debugstr_a(pszClassName),
6340c2c66affSColin Finck           samDesired, Disposition, phkClass, ulFlags);
6341c2c66affSColin Finck 
6342c2c66affSColin Finck     return CM_Open_Class_Key_ExA(pClassGuid, pszClassName, samDesired,
6343c2c66affSColin Finck                                  Disposition, phkClass, ulFlags, NULL);
6344c2c66affSColin Finck }
6345c2c66affSColin Finck 
6346c2c66affSColin Finck 
6347c2c66affSColin Finck /***********************************************************************
6348c2c66affSColin Finck  * CM_Open_Class_KeyW [SETUPAPI.@]
6349c2c66affSColin Finck  */
6350f86e78d0SEric Kohl CONFIGRET
6351f86e78d0SEric Kohl WINAPI
6352f86e78d0SEric Kohl CM_Open_Class_KeyW(
6353f86e78d0SEric Kohl     _In_opt_ LPGUID pClassGuid,
6354f86e78d0SEric Kohl     _In_opt_ LPCWSTR pszClassName,
6355f86e78d0SEric Kohl     _In_ REGSAM samDesired,
6356f86e78d0SEric Kohl     _In_ REGDISPOSITION Disposition,
6357f86e78d0SEric Kohl     _Out_ PHKEY phkClass,
6358f86e78d0SEric Kohl     _In_ ULONG ulFlags)
6359c2c66affSColin Finck {
6360ab0119c6SThamatip Chitpong     TRACE("CM_Open_Class_KeyW(%p %s %lx %lx %p %lx)\n",
6361c2c66affSColin Finck           debugstr_guid(pClassGuid), debugstr_w(pszClassName),
6362c2c66affSColin Finck           samDesired, Disposition, phkClass, ulFlags);
6363c2c66affSColin Finck 
6364c2c66affSColin Finck     return CM_Open_Class_Key_ExW(pClassGuid, pszClassName, samDesired,
6365c2c66affSColin Finck                                  Disposition, phkClass, ulFlags, NULL);
6366c2c66affSColin Finck }
6367c2c66affSColin Finck 
6368c2c66affSColin Finck 
6369c2c66affSColin Finck /***********************************************************************
6370c2c66affSColin Finck  * CM_Open_Class_Key_ExA [SETUPAPI.@]
6371c2c66affSColin Finck  */
6372f86e78d0SEric Kohl CONFIGRET
6373f86e78d0SEric Kohl WINAPI
6374f86e78d0SEric Kohl CM_Open_Class_Key_ExA(
6375f86e78d0SEric Kohl     _In_opt_ LPGUID pClassGuid,
6376f86e78d0SEric Kohl     _In_opt_ LPCSTR pszClassName,
6377f86e78d0SEric Kohl     _In_ REGSAM samDesired,
6378f86e78d0SEric Kohl     _In_ REGDISPOSITION Disposition,
6379f86e78d0SEric Kohl     _Out_ PHKEY phkClass,
6380f86e78d0SEric Kohl     _In_ ULONG ulFlags,
6381f86e78d0SEric Kohl     _In_opt_ HMACHINE hMachine)
6382c2c66affSColin Finck {
6383c2c66affSColin Finck     LPWSTR pszClassNameW = NULL;
6384c2c66affSColin Finck     CONFIGRET ret;
6385c2c66affSColin Finck 
638660a21894SEric Kohl     TRACE("CM_Open_Class_Key_ExA(%p %s %lx %lx %p %lx %p)\n",
638760a21894SEric Kohl           debugstr_guid(pClassGuid), debugstr_a(pszClassName),
6388c2c66affSColin Finck           samDesired, Disposition, phkClass, ulFlags, hMachine);
6389c2c66affSColin Finck 
6390c2c66affSColin Finck     if (pszClassName != NULL)
6391c2c66affSColin Finck     {
6392c2c66affSColin Finck        if (pSetupCaptureAndConvertAnsiArg(pszClassName, &pszClassNameW))
6393c2c66affSColin Finck          return CR_INVALID_DATA;
6394c2c66affSColin Finck     }
6395c2c66affSColin Finck 
6396c2c66affSColin Finck     ret = CM_Open_Class_Key_ExW(pClassGuid, pszClassNameW, samDesired,
6397c2c66affSColin Finck                                 Disposition, phkClass, ulFlags, hMachine);
6398c2c66affSColin Finck 
6399c2c66affSColin Finck     if (pszClassNameW != NULL)
6400c2c66affSColin Finck         MyFree(pszClassNameW);
6401c2c66affSColin Finck 
6402c2c66affSColin Finck     return ret;
6403c2c66affSColin Finck }
6404c2c66affSColin Finck 
6405c2c66affSColin Finck 
6406c2c66affSColin Finck /***********************************************************************
6407c2c66affSColin Finck  * CM_Open_Class_Key_ExW [SETUPAPI.@]
6408c2c66affSColin Finck  */
6409f86e78d0SEric Kohl CONFIGRET
6410f86e78d0SEric Kohl WINAPI
6411f86e78d0SEric Kohl CM_Open_Class_Key_ExW(
6412f86e78d0SEric Kohl     _In_opt_ LPGUID pClassGuid,
6413f86e78d0SEric Kohl     _In_opt_ LPCWSTR pszClassName,
6414f86e78d0SEric Kohl     _In_ REGSAM samDesired,
6415f86e78d0SEric Kohl     _In_ REGDISPOSITION Disposition,
6416f86e78d0SEric Kohl     _Out_ PHKEY phkClass,
6417f86e78d0SEric Kohl     _In_ ULONG ulFlags,
6418f86e78d0SEric Kohl     _In_opt_ HMACHINE hMachine)
6419c2c66affSColin Finck {
6420c2c66affSColin Finck     WCHAR szKeyName[MAX_PATH];
6421c2c66affSColin Finck     LPWSTR lpGuidString;
6422c2c66affSColin Finck     DWORD dwDisposition;
6423c2c66affSColin Finck     DWORD dwError;
6424c2c66affSColin Finck     HKEY hKey;
6425c2c66affSColin Finck 
642660a21894SEric Kohl     TRACE("CM_Open_Class_Key_ExW(%p %s %lx %lx %p %lx %p)\n",
6427c2c66affSColin Finck           debugstr_guid(pClassGuid), debugstr_w(pszClassName),
6428c2c66affSColin Finck           samDesired, Disposition, phkClass, ulFlags, hMachine);
6429c2c66affSColin Finck 
6430c2c66affSColin Finck     /* Check Disposition and ulFlags */
6431c2c66affSColin Finck     if ((Disposition & ~RegDisposition_Bits) ||
6432c2c66affSColin Finck         (ulFlags & ~CM_OPEN_CLASS_KEY_BITS))
6433c2c66affSColin Finck         return CR_INVALID_FLAG;
6434c2c66affSColin Finck 
6435c2c66affSColin Finck     /* Check phkClass */
6436c2c66affSColin Finck     if (phkClass == NULL)
6437c2c66affSColin Finck         return CR_INVALID_POINTER;
6438c2c66affSColin Finck 
6439c2c66affSColin Finck     *phkClass = NULL;
6440c2c66affSColin Finck 
6441c2c66affSColin Finck     if (ulFlags == CM_OPEN_CLASS_KEY_INTERFACE &&
6442c2c66affSColin Finck         pszClassName != NULL)
6443c2c66affSColin Finck         return CR_INVALID_DATA;
6444c2c66affSColin Finck 
6445c2c66affSColin Finck     if (hMachine == NULL)
6446c2c66affSColin Finck     {
6447c2c66affSColin Finck         hKey = HKEY_LOCAL_MACHINE;
6448c2c66affSColin Finck     }
6449c2c66affSColin Finck     else
6450c2c66affSColin Finck     {
6451c2c66affSColin Finck         if (RegConnectRegistryW(((PMACHINE_INFO)hMachine)->szMachineName,
645206f9e122SEric Kohl                                 HKEY_LOCAL_MACHINE,
645306f9e122SEric Kohl                                 &hKey))
6454c2c66affSColin Finck             return CR_REGISTRY_ERROR;
6455c2c66affSColin Finck     }
6456c2c66affSColin Finck 
6457c2c66affSColin Finck     if (ulFlags & CM_OPEN_CLASS_KEY_INTERFACE)
6458c2c66affSColin Finck     {
6459c2c66affSColin Finck         lstrcpyW(szKeyName, DeviceClasses);
6460c2c66affSColin Finck     }
6461c2c66affSColin Finck     else
6462c2c66affSColin Finck     {
6463c2c66affSColin Finck         lstrcpyW(szKeyName, ControlClass);
6464c2c66affSColin Finck     }
6465c2c66affSColin Finck 
6466c2c66affSColin Finck     if (pClassGuid != NULL)
6467c2c66affSColin Finck     {
6468c2c66affSColin Finck         if (UuidToStringW((UUID*)pClassGuid, &lpGuidString) != RPC_S_OK)
6469c2c66affSColin Finck         {
6470c2c66affSColin Finck             RegCloseKey(hKey);
6471c2c66affSColin Finck             return CR_INVALID_DATA;
6472c2c66affSColin Finck         }
6473c2c66affSColin Finck 
64748da00cd9SHervé Poussineau         lstrcatW(szKeyName, BackslashOpenBrace);
6475c2c66affSColin Finck         lstrcatW(szKeyName, lpGuidString);
64768da00cd9SHervé Poussineau         lstrcatW(szKeyName, CloseBrace);
6477c2c66affSColin Finck     }
6478c2c66affSColin Finck 
6479c2c66affSColin Finck     if (Disposition == RegDisposition_OpenAlways)
6480c2c66affSColin Finck     {
6481c2c66affSColin Finck         dwError = RegCreateKeyExW(hKey, szKeyName, 0, NULL, 0, samDesired,
6482c2c66affSColin Finck                                   NULL, phkClass, &dwDisposition);
6483c2c66affSColin Finck     }
6484c2c66affSColin Finck     else
6485c2c66affSColin Finck     {
6486c2c66affSColin Finck         dwError = RegOpenKeyExW(hKey, szKeyName, 0, samDesired, phkClass);
6487c2c66affSColin Finck     }
6488c2c66affSColin Finck 
6489c2c66affSColin Finck     RegCloseKey(hKey);
6490c2c66affSColin Finck 
6491c2c66affSColin Finck     if (pClassGuid != NULL)
6492c2c66affSColin Finck         RpcStringFreeW(&lpGuidString);
6493c2c66affSColin Finck 
6494c2c66affSColin Finck     if (dwError != ERROR_SUCCESS)
6495c2c66affSColin Finck     {
6496c2c66affSColin Finck         *phkClass = NULL;
6497c2c66affSColin Finck         return CR_NO_SUCH_REGISTRY_KEY;
6498c2c66affSColin Finck     }
6499c2c66affSColin Finck 
6500c2c66affSColin Finck     if (pszClassName != NULL)
6501c2c66affSColin Finck     {
6502c2c66affSColin Finck         RegSetValueExW(*phkClass, Class, 0, REG_SZ, (LPBYTE)pszClassName,
6503c2c66affSColin Finck                        (lstrlenW(pszClassName) + 1) * sizeof(WCHAR));
6504c2c66affSColin Finck     }
6505c2c66affSColin Finck 
6506c2c66affSColin Finck     return CR_SUCCESS;
6507c2c66affSColin Finck }
6508c2c66affSColin Finck 
6509c2c66affSColin Finck 
6510c2c66affSColin Finck /***********************************************************************
6511c2c66affSColin Finck  * CM_Open_DevNode_Key [SETUPAPI.@]
6512c2c66affSColin Finck  */
651378cf2a04SEric Kohl CONFIGRET
651478cf2a04SEric Kohl WINAPI
651578cf2a04SEric Kohl CM_Open_DevNode_Key(
651678cf2a04SEric Kohl     _In_ DEVINST dnDevNode,
651778cf2a04SEric Kohl     _In_ REGSAM samDesired,
651878cf2a04SEric Kohl     _In_ ULONG ulHardwareProfile,
651978cf2a04SEric Kohl     _In_ REGDISPOSITION Disposition,
652078cf2a04SEric Kohl     _Out_ PHKEY phkDevice,
652178cf2a04SEric Kohl     _In_ ULONG ulFlags)
6522c2c66affSColin Finck {
652378cf2a04SEric Kohl     TRACE("CM_Open_DevNode_Key(%lx %lx %lu %lx %p %lx)\n",
652478cf2a04SEric Kohl           dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags);
652565d3bf74SEric Kohl 
6526c2c66affSColin Finck     return CM_Open_DevNode_Key_Ex(dnDevNode, samDesired, ulHardwareProfile,
6527c2c66affSColin Finck                                   Disposition, phkDevice, ulFlags, NULL);
6528c2c66affSColin Finck }
6529c2c66affSColin Finck 
6530c2c66affSColin Finck 
6531c2c66affSColin Finck /***********************************************************************
6532c2c66affSColin Finck  * CM_Open_DevNode_Key_Ex [SETUPAPI.@]
6533c2c66affSColin Finck  */
653478cf2a04SEric Kohl CONFIGRET
653578cf2a04SEric Kohl WINAPI
653678cf2a04SEric Kohl CM_Open_DevNode_Key_Ex(
653778cf2a04SEric Kohl     _In_ DEVINST dnDevNode,
653878cf2a04SEric Kohl     _In_ REGSAM samDesired,
653978cf2a04SEric Kohl     _In_ ULONG ulHardwareProfile,
654078cf2a04SEric Kohl     _In_ REGDISPOSITION Disposition,
654178cf2a04SEric Kohl     _Out_ PHKEY phkDevice,
654278cf2a04SEric Kohl     _In_ ULONG ulFlags,
6543f86e78d0SEric Kohl     _In_opt_ HMACHINE hMachine)
6544c2c66affSColin Finck {
654578cf2a04SEric Kohl     RPC_BINDING_HANDLE BindingHandle = NULL;
654678cf2a04SEric Kohl     HSTRING_TABLE StringTable = NULL;
654778cf2a04SEric Kohl     LPWSTR pszDevInst, pszKeyPath = NULL, pszInstancePath = NULL;
654878cf2a04SEric Kohl     LONG lError;
654906f9e122SEric Kohl     DWORD dwDisposition;
655006f9e122SEric Kohl     HKEY hRootKey = NULL;
655178cf2a04SEric Kohl     CONFIGRET ret = CR_CALL_NOT_IMPLEMENTED;
6552c2c66affSColin Finck 
655360a21894SEric Kohl     TRACE("CM_Open_DevNode_Key_Ex(%lx %lx %lu %lx %p %lx %p)\n",
655478cf2a04SEric Kohl           dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags, hMachine);
655578cf2a04SEric Kohl 
655678cf2a04SEric Kohl     if (phkDevice == NULL)
655778cf2a04SEric Kohl         return CR_INVALID_POINTER;
655878cf2a04SEric Kohl 
655978cf2a04SEric Kohl     *phkDevice = NULL;
656078cf2a04SEric Kohl 
656178cf2a04SEric Kohl     if (dnDevNode == 0)
656278cf2a04SEric Kohl         return CR_INVALID_DEVNODE;
656378cf2a04SEric Kohl 
656478cf2a04SEric Kohl     if (ulFlags & ~CM_REGISTRY_BITS)
656578cf2a04SEric Kohl         return CR_INVALID_FLAG;
656678cf2a04SEric Kohl 
656778cf2a04SEric Kohl     if (Disposition & ~RegDisposition_Bits)
656878cf2a04SEric Kohl         return CR_INVALID_DATA;
656978cf2a04SEric Kohl 
657078cf2a04SEric Kohl     if (hMachine != NULL)
657178cf2a04SEric Kohl     {
657278cf2a04SEric Kohl         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
657378cf2a04SEric Kohl         if (BindingHandle == NULL)
657478cf2a04SEric Kohl             return CR_FAILURE;
657578cf2a04SEric Kohl 
657678cf2a04SEric Kohl         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
657778cf2a04SEric Kohl         if (StringTable == 0)
657878cf2a04SEric Kohl             return CR_FAILURE;
657978cf2a04SEric Kohl     }
658078cf2a04SEric Kohl     else
658178cf2a04SEric Kohl     {
658278cf2a04SEric Kohl         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
658378cf2a04SEric Kohl             return CR_FAILURE;
658478cf2a04SEric Kohl     }
658578cf2a04SEric Kohl 
658678cf2a04SEric Kohl     pszDevInst = pSetupStringTableStringFromId(StringTable, dnDevNode);
658778cf2a04SEric Kohl     if (pszDevInst == NULL)
658878cf2a04SEric Kohl         return CR_INVALID_DEVNODE;
658978cf2a04SEric Kohl 
659078cf2a04SEric Kohl     TRACE("pszDevInst: %S\n", pszDevInst);
659178cf2a04SEric Kohl 
659206f9e122SEric Kohl     pszKeyPath = MyMalloc(512 * sizeof(WCHAR));
659378cf2a04SEric Kohl     if (pszKeyPath == NULL)
659478cf2a04SEric Kohl     {
659578cf2a04SEric Kohl         ret = CR_OUT_OF_MEMORY;
659678cf2a04SEric Kohl         goto done;
659778cf2a04SEric Kohl     }
659878cf2a04SEric Kohl 
659906f9e122SEric Kohl     pszInstancePath = MyMalloc(512 * sizeof(WCHAR));
660078cf2a04SEric Kohl     if (pszInstancePath == NULL)
660178cf2a04SEric Kohl     {
660278cf2a04SEric Kohl         ret = CR_OUT_OF_MEMORY;
660378cf2a04SEric Kohl         goto done;
660478cf2a04SEric Kohl     }
660578cf2a04SEric Kohl 
660678cf2a04SEric Kohl     ret = GetDeviceInstanceKeyPath(BindingHandle,
660778cf2a04SEric Kohl                                    pszDevInst,
660878cf2a04SEric Kohl                                    pszKeyPath,
660978cf2a04SEric Kohl                                    pszInstancePath,
661078cf2a04SEric Kohl                                    ulHardwareProfile,
661178cf2a04SEric Kohl                                    ulFlags);
661278cf2a04SEric Kohl     if (ret != CR_SUCCESS)
661378cf2a04SEric Kohl         goto done;
661478cf2a04SEric Kohl 
6615a2a37239SEric Kohl     TRACE("pszKeyPath: %S\n", pszKeyPath);
6616a2a37239SEric Kohl     TRACE("pszInstancePath: %S\n", pszInstancePath);
661778cf2a04SEric Kohl 
661878cf2a04SEric Kohl     wcscat(pszKeyPath, L"\\");
661978cf2a04SEric Kohl     wcscat(pszKeyPath, pszInstancePath);
662078cf2a04SEric Kohl 
6621a2a37239SEric Kohl     TRACE("pszKeyPath: %S\n", pszKeyPath);
662278cf2a04SEric Kohl 
662306f9e122SEric Kohl     if (hMachine == NULL)
662406f9e122SEric Kohl     {
662506f9e122SEric Kohl         hRootKey = HKEY_LOCAL_MACHINE;
662606f9e122SEric Kohl     }
662706f9e122SEric Kohl     else
662806f9e122SEric Kohl     {
662906f9e122SEric Kohl         if (RegConnectRegistryW(((PMACHINE_INFO)hMachine)->szMachineName,
663006f9e122SEric Kohl                                 HKEY_LOCAL_MACHINE,
663106f9e122SEric Kohl                                 &hRootKey))
663206f9e122SEric Kohl         {
663306f9e122SEric Kohl             ret = CR_REGISTRY_ERROR;
663406f9e122SEric Kohl             goto done;
663506f9e122SEric Kohl         }
663606f9e122SEric Kohl     }
663778cf2a04SEric Kohl 
663806f9e122SEric Kohl     if (Disposition == RegDisposition_OpenAlways)
663906f9e122SEric Kohl     {
664006f9e122SEric Kohl         lError = RegCreateKeyExW(hRootKey,
664106f9e122SEric Kohl                                  pszKeyPath,
664206f9e122SEric Kohl                                  0,
664306f9e122SEric Kohl                                  NULL,
664406f9e122SEric Kohl                                  0,
664506f9e122SEric Kohl                                  samDesired,
664606f9e122SEric Kohl                                  NULL,
664706f9e122SEric Kohl                                  phkDevice,
664806f9e122SEric Kohl                                  &dwDisposition);
664906f9e122SEric Kohl     }
665006f9e122SEric Kohl     else
665106f9e122SEric Kohl     {
665206f9e122SEric Kohl         lError = RegOpenKeyExW(hRootKey,
665378cf2a04SEric Kohl                                pszKeyPath,
665478cf2a04SEric Kohl                                0,
665578cf2a04SEric Kohl                                samDesired,
665678cf2a04SEric Kohl                                phkDevice);
665706f9e122SEric Kohl     }
665806f9e122SEric Kohl 
665978cf2a04SEric Kohl     if (lError != ERROR_SUCCESS)
666078cf2a04SEric Kohl     {
666178cf2a04SEric Kohl         *phkDevice = NULL;
666278cf2a04SEric Kohl         ret = CR_NO_SUCH_REGISTRY_KEY;
666378cf2a04SEric Kohl     }
666478cf2a04SEric Kohl 
666578cf2a04SEric Kohl done:
666606f9e122SEric Kohl     if ((hRootKey != NULL) && (hRootKey != HKEY_LOCAL_MACHINE))
666706f9e122SEric Kohl         RegCloseKey(hRootKey);
666806f9e122SEric Kohl 
666978cf2a04SEric Kohl     if (pszInstancePath != NULL)
667078cf2a04SEric Kohl         MyFree(pszInstancePath);
667178cf2a04SEric Kohl 
667278cf2a04SEric Kohl     if (pszKeyPath != NULL)
667378cf2a04SEric Kohl         MyFree(pszKeyPath);
667478cf2a04SEric Kohl 
667578cf2a04SEric Kohl     return ret;
6676c2c66affSColin Finck }
6677c2c66affSColin Finck 
6678c2c66affSColin Finck 
6679c2c66affSColin Finck /***********************************************************************
6680c2c66affSColin Finck  * CM_Query_And_Remove_SubTreeA [SETUPAPI.@]
6681c2c66affSColin Finck  */
668265d3bf74SEric Kohl CONFIGRET
668365d3bf74SEric Kohl WINAPI
668465d3bf74SEric Kohl CM_Query_And_Remove_SubTreeA(
668565d3bf74SEric Kohl     _In_ DEVINST dnAncestor,
668665d3bf74SEric Kohl     _Out_opt_ PPNP_VETO_TYPE pVetoType,
668765d3bf74SEric Kohl     _Out_writes_opt_(ulNameLength) LPSTR pszVetoName,
668865d3bf74SEric Kohl     _In_ ULONG ulNameLength,
668965d3bf74SEric Kohl     _In_ ULONG ulFlags)
6690c2c66affSColin Finck {
6691ab0119c6SThamatip Chitpong     TRACE("CM_Query_And_Remove_SubTreeA(%lx %p %p %lu %lx)\n",
669265d3bf74SEric Kohl           dnAncestor, pVetoType, pszVetoName, ulNameLength, ulFlags);
6693c2c66affSColin Finck 
6694c2c66affSColin Finck     return CM_Query_And_Remove_SubTree_ExA(dnAncestor, pVetoType, pszVetoName,
6695c2c66affSColin Finck                                            ulNameLength, ulFlags, NULL);
6696c2c66affSColin Finck }
6697c2c66affSColin Finck 
6698c2c66affSColin Finck 
6699c2c66affSColin Finck /***********************************************************************
6700c2c66affSColin Finck  * CM_Query_And_Remove_SubTreeW [SETUPAPI.@]
6701c2c66affSColin Finck  */
670265d3bf74SEric Kohl CONFIGRET
670365d3bf74SEric Kohl WINAPI
670465d3bf74SEric Kohl CM_Query_And_Remove_SubTreeW(
670565d3bf74SEric Kohl     _In_ DEVINST dnAncestor,
670665d3bf74SEric Kohl     _Out_opt_ PPNP_VETO_TYPE pVetoType,
670765d3bf74SEric Kohl     _Out_writes_opt_(ulNameLength) LPWSTR pszVetoName,
670865d3bf74SEric Kohl     _In_ ULONG ulNameLength,
670965d3bf74SEric Kohl     _In_ ULONG ulFlags)
6710c2c66affSColin Finck {
67115b5aaf66SSerge Gautherie     TRACE("CM_Query_And_Remove_SubTreeW(%lx %p %p %lu %lx)\n",
67125b5aaf66SSerge Gautherie           dnAncestor, pVetoType, pszVetoName, ulNameLength, ulFlags);
6713c2c66affSColin Finck 
6714c2c66affSColin Finck     return CM_Query_And_Remove_SubTree_ExW(dnAncestor, pVetoType, pszVetoName,
6715c2c66affSColin Finck                                            ulNameLength, ulFlags, NULL);
6716c2c66affSColin Finck }
6717c2c66affSColin Finck 
6718c2c66affSColin Finck 
6719c2c66affSColin Finck /***********************************************************************
6720c2c66affSColin Finck  * CM_Query_And_Remove_SubTree_ExA [SETUPAPI.@]
6721c2c66affSColin Finck  */
672265d3bf74SEric Kohl CONFIGRET
672365d3bf74SEric Kohl WINAPI
672465d3bf74SEric Kohl CM_Query_And_Remove_SubTree_ExA(
672565d3bf74SEric Kohl     _In_ DEVINST dnAncestor,
672665d3bf74SEric Kohl     _Out_opt_ PPNP_VETO_TYPE pVetoType,
672765d3bf74SEric Kohl     _Out_writes_opt_(ulNameLength) LPSTR pszVetoName,
672865d3bf74SEric Kohl     _In_ ULONG ulNameLength,
672965d3bf74SEric Kohl     _In_ ULONG ulFlags,
673065d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
6731c2c66affSColin Finck {
6732c2c66affSColin Finck     LPWSTR lpLocalVetoName;
6733c2c66affSColin Finck     CONFIGRET ret;
6734c2c66affSColin Finck 
67355b5aaf66SSerge Gautherie     TRACE("CM_Query_And_Remove_SubTree_ExA(%lx %p %p %lu %lx %p)\n",
67365b5aaf66SSerge Gautherie           dnAncestor, pVetoType, pszVetoName, ulNameLength,
673765d3bf74SEric Kohl           ulFlags, hMachine);
6738c2c66affSColin Finck 
6739c2c66affSColin Finck     if (pszVetoName == NULL && ulNameLength == 0)
6740c2c66affSColin Finck         return CR_INVALID_POINTER;
6741c2c66affSColin Finck 
6742c2c66affSColin Finck     lpLocalVetoName = HeapAlloc(GetProcessHeap(), 0, ulNameLength * sizeof(WCHAR));
6743c2c66affSColin Finck     if (lpLocalVetoName == NULL)
6744c2c66affSColin Finck         return CR_OUT_OF_MEMORY;
6745c2c66affSColin Finck 
6746c2c66affSColin Finck     ret = CM_Query_And_Remove_SubTree_ExW(dnAncestor, pVetoType, lpLocalVetoName,
6747c2c66affSColin Finck                                           ulNameLength, ulFlags, hMachine);
6748c2c66affSColin Finck     if (ret == CR_REMOVE_VETOED)
6749c2c66affSColin Finck     {
6750c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
6751c2c66affSColin Finck                                 0,
6752c2c66affSColin Finck                                 lpLocalVetoName,
6753c2c66affSColin Finck                                 ulNameLength,
6754c2c66affSColin Finck                                 pszVetoName,
6755c2c66affSColin Finck                                 ulNameLength,
6756c2c66affSColin Finck                                 NULL,
6757c2c66affSColin Finck                                 NULL) == 0)
6758c2c66affSColin Finck             ret = CR_FAILURE;
6759c2c66affSColin Finck     }
6760c2c66affSColin Finck 
6761c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, lpLocalVetoName);
6762c2c66affSColin Finck 
6763c2c66affSColin Finck     return ret;
6764c2c66affSColin Finck }
6765c2c66affSColin Finck 
6766c2c66affSColin Finck 
6767c2c66affSColin Finck /***********************************************************************
6768c2c66affSColin Finck  * CM_Query_And_Remove_SubTree_ExW [SETUPAPI.@]
6769c2c66affSColin Finck  */
677065d3bf74SEric Kohl CONFIGRET
677165d3bf74SEric Kohl WINAPI
677265d3bf74SEric Kohl CM_Query_And_Remove_SubTree_ExW(
677365d3bf74SEric Kohl     _In_ DEVINST dnAncestor,
677465d3bf74SEric Kohl     _Out_opt_ PPNP_VETO_TYPE pVetoType,
677565d3bf74SEric Kohl     _Out_writes_opt_(ulNameLength) LPWSTR pszVetoName,
677665d3bf74SEric Kohl     _In_ ULONG ulNameLength,
677765d3bf74SEric Kohl     _In_ ULONG ulFlags,
677865d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
6779c2c66affSColin Finck {
6780c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
6781c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
6782c2c66affSColin Finck     LPWSTR lpDevInst;
6783c2c66affSColin Finck     CONFIGRET ret;
6784c2c66affSColin Finck 
67855b5aaf66SSerge Gautherie     TRACE("CM_Query_And_Remove_SubTree_ExW(%lx %p %p %lu %lx %p)\n",
67865b5aaf66SSerge Gautherie           dnAncestor, pVetoType, pszVetoName, ulNameLength,
678765d3bf74SEric Kohl           ulFlags, hMachine);
6788c2c66affSColin Finck 
6789c2c66affSColin Finck     if (dnAncestor == 0)
6790c2c66affSColin Finck         return CR_INVALID_DEVNODE;
6791c2c66affSColin Finck 
6792c2c66affSColin Finck     if (ulFlags & ~CM_REMOVE_BITS)
6793c2c66affSColin Finck         return CR_INVALID_FLAG;
6794c2c66affSColin Finck 
6795c2c66affSColin Finck     if (pszVetoName == NULL && ulNameLength == 0)
6796c2c66affSColin Finck         return CR_INVALID_POINTER;
6797c2c66affSColin Finck 
6798c2c66affSColin Finck     if (hMachine != NULL)
6799c2c66affSColin Finck     {
6800c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
6801c2c66affSColin Finck         if (BindingHandle == NULL)
6802c2c66affSColin Finck             return CR_FAILURE;
6803c2c66affSColin Finck 
6804c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
6805c2c66affSColin Finck         if (StringTable == 0)
6806c2c66affSColin Finck             return CR_FAILURE;
6807c2c66affSColin Finck     }
6808c2c66affSColin Finck     else
6809c2c66affSColin Finck     {
6810c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
6811c2c66affSColin Finck             return CR_FAILURE;
6812c2c66affSColin Finck     }
6813c2c66affSColin Finck 
6814c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnAncestor);
6815c2c66affSColin Finck     if (lpDevInst == NULL)
6816c2c66affSColin Finck         return CR_INVALID_DEVNODE;
6817c2c66affSColin Finck 
6818c2c66affSColin Finck     RpcTryExcept
6819c2c66affSColin Finck     {
6820c2c66affSColin Finck         ret = PNP_QueryRemove(BindingHandle,
6821c2c66affSColin Finck                               lpDevInst,
6822c2c66affSColin Finck                               pVetoType,
6823c2c66affSColin Finck                               pszVetoName,
6824c2c66affSColin Finck                               ulNameLength,
6825c2c66affSColin Finck                               ulFlags);
6826c2c66affSColin Finck     }
6827c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
6828c2c66affSColin Finck     {
6829c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
6830c2c66affSColin Finck     }
6831c2c66affSColin Finck     RpcEndExcept;
6832c2c66affSColin Finck 
6833c2c66affSColin Finck     return ret;
6834c2c66affSColin Finck }
6835c2c66affSColin Finck 
6836c2c66affSColin Finck 
6837c2c66affSColin Finck /***********************************************************************
6838c2c66affSColin Finck  * CM_Query_Arbitrator_Free_Data [SETUPAPI.@]
6839c2c66affSColin Finck  */
684065d3bf74SEric Kohl CONFIGRET
684165d3bf74SEric Kohl WINAPI
684265d3bf74SEric Kohl CM_Query_Arbitrator_Free_Data(
684365d3bf74SEric Kohl     _Out_writes_bytes_(DataLen) PVOID pData,
684465d3bf74SEric Kohl     _In_ ULONG DataLen,
684565d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
684665d3bf74SEric Kohl     _In_ RESOURCEID ResourceID,
684765d3bf74SEric Kohl     _In_ ULONG ulFlags)
6848c2c66affSColin Finck {
684965d3bf74SEric Kohl     TRACE("CM_Query_Arbitrator_Free_Data(%p %lu %lx %lu 0x%08lx)\n",
685065d3bf74SEric Kohl           pData, DataLen, dnDevInst, ResourceID, ulFlags);
6851c2c66affSColin Finck 
6852c2c66affSColin Finck     return CM_Query_Arbitrator_Free_Data_Ex(pData, DataLen, dnDevInst,
6853c2c66affSColin Finck                                             ResourceID, ulFlags, NULL);
6854c2c66affSColin Finck }
6855c2c66affSColin Finck 
6856c2c66affSColin Finck 
6857c2c66affSColin Finck /***********************************************************************
6858c2c66affSColin Finck  * CM_Query_Arbitrator_Free_Data_Ex [SETUPAPI.@]
6859c2c66affSColin Finck  */
686065d3bf74SEric Kohl CONFIGRET
686165d3bf74SEric Kohl WINAPI
686265d3bf74SEric Kohl CM_Query_Arbitrator_Free_Data_Ex(
686365d3bf74SEric Kohl     _Out_writes_bytes_(DataLen) PVOID pData,
686465d3bf74SEric Kohl     _In_ ULONG DataLen,
686565d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
686665d3bf74SEric Kohl     _In_ RESOURCEID ResourceID,
686765d3bf74SEric Kohl     _In_ ULONG ulFlags,
686865d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
6869c2c66affSColin Finck {
6870c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
6871c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
6872c2c66affSColin Finck     LPWSTR lpDevInst;
6873c2c66affSColin Finck     CONFIGRET ret;
6874c2c66affSColin Finck 
687565d3bf74SEric Kohl     TRACE("CM_Query_Arbitrator_Free_Data_Ex(%p %lu %lx %lu 0x%08lx %p)\n",
687665d3bf74SEric Kohl           pData, DataLen, dnDevInst, ResourceID, ulFlags, hMachine);
6877c2c66affSColin Finck 
6878c2c66affSColin Finck     if (pData == NULL || DataLen == 0)
6879c2c66affSColin Finck         return CR_INVALID_POINTER;
6880c2c66affSColin Finck 
6881c2c66affSColin Finck     if (dnDevInst == 0)
6882c2c66affSColin Finck         return CR_INVALID_DEVINST;
6883c2c66affSColin Finck 
6884c2c66affSColin Finck     if (ulFlags & ~CM_QUERY_ARBITRATOR_BITS)
6885c2c66affSColin Finck         return CR_INVALID_FLAG;
6886c2c66affSColin Finck 
6887c2c66affSColin Finck     if (hMachine != NULL)
6888c2c66affSColin Finck     {
6889c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
6890c2c66affSColin Finck         if (BindingHandle == NULL)
6891c2c66affSColin Finck             return CR_FAILURE;
6892c2c66affSColin Finck 
6893c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
6894c2c66affSColin Finck         if (StringTable == 0)
6895c2c66affSColin Finck             return CR_FAILURE;
6896c2c66affSColin Finck     }
6897c2c66affSColin Finck     else
6898c2c66affSColin Finck     {
6899c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
6900c2c66affSColin Finck             return CR_FAILURE;
6901c2c66affSColin Finck     }
6902c2c66affSColin Finck 
6903c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
6904c2c66affSColin Finck     if (lpDevInst == NULL)
6905c2c66affSColin Finck         return CR_INVALID_DEVNODE;
6906c2c66affSColin Finck 
6907c2c66affSColin Finck     RpcTryExcept
6908c2c66affSColin Finck     {
6909c2c66affSColin Finck         ret = PNP_QueryArbitratorFreeData(BindingHandle,
6910c2c66affSColin Finck                                           pData,
6911c2c66affSColin Finck                                           DataLen,
6912c2c66affSColin Finck                                           lpDevInst,
6913c2c66affSColin Finck                                           ResourceID,
6914c2c66affSColin Finck                                           ulFlags);
6915c2c66affSColin Finck     }
6916c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
6917c2c66affSColin Finck     {
6918c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
6919c2c66affSColin Finck     }
6920c2c66affSColin Finck     RpcEndExcept;
6921c2c66affSColin Finck 
6922c2c66affSColin Finck     return ret;
6923c2c66affSColin Finck }
6924c2c66affSColin Finck 
6925c2c66affSColin Finck 
6926c2c66affSColin Finck /***********************************************************************
6927c2c66affSColin Finck  * CM_Query_Arbitrator_Free_Size [SETUPAPI.@]
6928c2c66affSColin Finck  */
692965d3bf74SEric Kohl CONFIGRET
693065d3bf74SEric Kohl WINAPI
693165d3bf74SEric Kohl CM_Query_Arbitrator_Free_Size(
693265d3bf74SEric Kohl     _Out_ PULONG pulSize,
693365d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
693465d3bf74SEric Kohl     _In_ RESOURCEID ResourceID,
693565d3bf74SEric Kohl     _In_ ULONG ulFlags)
6936c2c66affSColin Finck {
693765d3bf74SEric Kohl     TRACE("CM_Query_Arbitrator_Free_Size(%p %lu %lx 0x%08lx)\n",
693865d3bf74SEric Kohl           pulSize, dnDevInst,ResourceID, ulFlags);
6939c2c66affSColin Finck 
6940c2c66affSColin Finck     return CM_Query_Arbitrator_Free_Size_Ex(pulSize, dnDevInst, ResourceID,
6941c2c66affSColin Finck                                             ulFlags, NULL);
6942c2c66affSColin Finck }
6943c2c66affSColin Finck 
6944c2c66affSColin Finck 
6945c2c66affSColin Finck /***********************************************************************
6946c2c66affSColin Finck  * CM_Query_Arbitrator_Free_Size_Ex [SETUPAPI.@]
6947c2c66affSColin Finck  */
694865d3bf74SEric Kohl CONFIGRET
694965d3bf74SEric Kohl WINAPI
695065d3bf74SEric Kohl CM_Query_Arbitrator_Free_Size_Ex(
695165d3bf74SEric Kohl     _Out_ PULONG pulSize,
695265d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
695365d3bf74SEric Kohl     _In_ RESOURCEID ResourceID,
695465d3bf74SEric Kohl     _In_ ULONG ulFlags,
695565d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
6956c2c66affSColin Finck {
6957c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
6958c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
6959c2c66affSColin Finck     LPWSTR lpDevInst;
6960c2c66affSColin Finck     CONFIGRET ret;
6961c2c66affSColin Finck 
696265d3bf74SEric Kohl     TRACE("CM_Query_Arbitrator_Free_Size_Ex(%p %lu %lx 0x%08lx %p)\n",
696365d3bf74SEric Kohl           pulSize, dnDevInst,ResourceID, ulFlags, hMachine);
6964c2c66affSColin Finck 
6965c2c66affSColin Finck     if (pulSize == NULL)
6966c2c66affSColin Finck         return CR_INVALID_POINTER;
6967c2c66affSColin Finck 
6968c2c66affSColin Finck     if (dnDevInst == 0)
6969c2c66affSColin Finck         return CR_INVALID_DEVINST;
6970c2c66affSColin Finck 
6971c2c66affSColin Finck     if (ulFlags & ~CM_QUERY_ARBITRATOR_BITS)
6972c2c66affSColin Finck         return CR_INVALID_FLAG;
6973c2c66affSColin Finck 
6974c2c66affSColin Finck     if (hMachine != NULL)
6975c2c66affSColin Finck     {
6976c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
6977c2c66affSColin Finck         if (BindingHandle == NULL)
6978c2c66affSColin Finck             return CR_FAILURE;
6979c2c66affSColin Finck 
6980c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
6981c2c66affSColin Finck         if (StringTable == 0)
6982c2c66affSColin Finck             return CR_FAILURE;
6983c2c66affSColin Finck     }
6984c2c66affSColin Finck     else
6985c2c66affSColin Finck     {
6986c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
6987c2c66affSColin Finck             return CR_FAILURE;
6988c2c66affSColin Finck     }
6989c2c66affSColin Finck 
6990c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
6991c2c66affSColin Finck     if (lpDevInst == NULL)
6992c2c66affSColin Finck         return CR_INVALID_DEVNODE;
6993c2c66affSColin Finck 
6994c2c66affSColin Finck     RpcTryExcept
6995c2c66affSColin Finck     {
6996c2c66affSColin Finck         ret = PNP_QueryArbitratorFreeSize(BindingHandle,
6997c2c66affSColin Finck                                           pulSize,
6998c2c66affSColin Finck                                           lpDevInst,
6999c2c66affSColin Finck                                           ResourceID,
7000c2c66affSColin Finck                                           ulFlags);
7001c2c66affSColin Finck     }
7002c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
7003c2c66affSColin Finck     {
7004c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
7005c2c66affSColin Finck     }
7006c2c66affSColin Finck     RpcEndExcept;
7007c2c66affSColin Finck 
7008c2c66affSColin Finck     return ret;
7009c2c66affSColin Finck }
7010c2c66affSColin Finck 
7011c2c66affSColin Finck 
7012c2c66affSColin Finck /***********************************************************************
7013c2c66affSColin Finck  * CM_Query_Remove_SubTree [SETUPAPI.@]
7014c2c66affSColin Finck  *
7015c2c66affSColin Finck  * This function is obsolete in Windows XP and above.
7016c2c66affSColin Finck  */
701765d3bf74SEric Kohl CONFIGRET
701865d3bf74SEric Kohl WINAPI
701965d3bf74SEric Kohl CM_Query_Remove_SubTree(
702065d3bf74SEric Kohl     _In_ DEVINST dnAncestor,
702165d3bf74SEric Kohl     _In_ ULONG ulFlags)
7022c2c66affSColin Finck {
702365d3bf74SEric Kohl     TRACE("CM_Query_Remove_SubTree(%lx %lx)\n",
702465d3bf74SEric Kohl           dnAncestor, ulFlags);
702565d3bf74SEric Kohl 
7026c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
7027c2c66affSColin Finck }
7028c2c66affSColin Finck 
7029c2c66affSColin Finck 
7030c2c66affSColin Finck /***********************************************************************
7031c2c66affSColin Finck  * CM_Query_Remove_SubTree_Ex [SETUPAPI.@]
7032c2c66affSColin Finck  *
7033c2c66affSColin Finck  * This function is obsolete in Windows XP and above.
7034c2c66affSColin Finck  */
703565d3bf74SEric Kohl CONFIGRET
703665d3bf74SEric Kohl WINAPI
703765d3bf74SEric Kohl CM_Query_Remove_SubTree_Ex(
703865d3bf74SEric Kohl     _In_ DEVINST dnAncestor,
703965d3bf74SEric Kohl     _In_ ULONG ulFlags,
704065d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
7041c2c66affSColin Finck {
704260a21894SEric Kohl     TRACE("CM_Query_Remove_SubTree_Ex(%lx %lx %p)\n",
704365d3bf74SEric Kohl           dnAncestor, ulFlags, hMachine);
704465d3bf74SEric Kohl 
7045c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
7046c2c66affSColin Finck }
7047c2c66affSColin Finck 
7048c2c66affSColin Finck 
7049c2c66affSColin Finck /***********************************************************************
7050d7e40954SEric Kohl  * CM_Query_Resource_Conflict_List [SETUPAPI.@]
7051d7e40954SEric Kohl  */
7052d7e40954SEric Kohl CONFIGRET
7053d7e40954SEric Kohl WINAPI
7054d7e40954SEric Kohl CM_Query_Resource_Conflict_List(
7055d7e40954SEric Kohl     _Out_ PCONFLICT_LIST pclConflictList,
7056d7e40954SEric Kohl     _In_ DEVINST dnDevInst,
7057d7e40954SEric Kohl     _In_ RESOURCEID ResourceID,
7058d7e40954SEric Kohl     _In_ PCVOID ResourceData,
7059d7e40954SEric Kohl     _In_ ULONG ResourceLen,
7060d7e40954SEric Kohl     _In_ ULONG ulFlags,
7061d7e40954SEric Kohl     _In_opt_ HMACHINE hMachine)
7062d7e40954SEric Kohl {
7063cee1817eSEric Kohl     RPC_BINDING_HANDLE BindingHandle = NULL;
7064cee1817eSEric Kohl     HSTRING_TABLE StringTable = NULL;
7065cee1817eSEric Kohl     PPNP_CONFLICT_LIST pConflictBuffer = NULL;
7066cee1817eSEric Kohl     PCONFLICT_DATA pConflictData = NULL;
7067cee1817eSEric Kohl     ULONG ulBufferLength;
7068cee1817eSEric Kohl     LPWSTR lpDevInst;
7069cee1817eSEric Kohl     CONFIGRET ret;
7070cee1817eSEric Kohl 
7071d7e40954SEric Kohl     FIXME("CM_Query_Resource_Conflict_List(%p %lx %lu %p %lu %lx %p)\n",
7072d7e40954SEric Kohl           pclConflictList, dnDevInst, ResourceID, ResourceData,
7073d7e40954SEric Kohl           ResourceLen, ulFlags, hMachine);
7074d7e40954SEric Kohl 
7075cee1817eSEric Kohl     if (dnDevInst == 0)
7076cee1817eSEric Kohl         return CR_INVALID_DEVNODE;
7077cee1817eSEric Kohl 
7078cee1817eSEric Kohl     if (ulFlags & ~CM_RESDES_WIDTH_BITS)
7079cee1817eSEric Kohl         return CR_INVALID_FLAG;
7080cee1817eSEric Kohl 
7081cee1817eSEric Kohl     if (pclConflictList == NULL ||
7082cee1817eSEric Kohl         ResourceData == NULL ||
7083cee1817eSEric Kohl         ResourceLen == 0)
7084cee1817eSEric Kohl         return CR_INVALID_POINTER;
7085cee1817eSEric Kohl 
7086cee1817eSEric Kohl     if (ResourceID == 0)
7087cee1817eSEric Kohl         return CR_INVALID_RESOURCEID;
7088cee1817eSEric Kohl 
7089cee1817eSEric Kohl     *pclConflictList = 0;
7090cee1817eSEric Kohl 
7091cee1817eSEric Kohl     if (hMachine != NULL)
7092cee1817eSEric Kohl     {
7093cee1817eSEric Kohl         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
7094cee1817eSEric Kohl         if (BindingHandle == NULL)
7095cee1817eSEric Kohl             return CR_FAILURE;
7096cee1817eSEric Kohl 
7097cee1817eSEric Kohl         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
7098cee1817eSEric Kohl         if (StringTable == 0)
7099cee1817eSEric Kohl             return CR_FAILURE;
7100cee1817eSEric Kohl     }
7101cee1817eSEric Kohl     else
7102cee1817eSEric Kohl     {
7103cee1817eSEric Kohl         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
7104cee1817eSEric Kohl             return CR_FAILURE;
7105cee1817eSEric Kohl     }
7106cee1817eSEric Kohl 
7107cee1817eSEric Kohl     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
7108cee1817eSEric Kohl     if (lpDevInst == NULL)
7109cee1817eSEric Kohl         return CR_INVALID_DEVNODE;
7110cee1817eSEric Kohl 
7111b13990bdSSerge Gautherie     pConflictData = MyMalloc(sizeof(CONFLICT_DATA));
7112cee1817eSEric Kohl     if (pConflictData == NULL)
7113cee1817eSEric Kohl     {
7114cee1817eSEric Kohl         ret = CR_OUT_OF_MEMORY;
7115cee1817eSEric Kohl         goto done;
7116cee1817eSEric Kohl     }
7117cee1817eSEric Kohl 
7118cee1817eSEric Kohl     ulBufferLength = sizeof(PNP_CONFLICT_LIST) +
7119cee1817eSEric Kohl                      sizeof(PNP_CONFLICT_STRINGS) +
7120cee1817eSEric Kohl                      (sizeof(wchar_t) * 200);
7121cee1817eSEric Kohl     pConflictBuffer = MyMalloc(ulBufferLength);
7122cee1817eSEric Kohl     if (pConflictBuffer == NULL)
7123cee1817eSEric Kohl     {
7124cee1817eSEric Kohl         ret = CR_OUT_OF_MEMORY;
7125cee1817eSEric Kohl         goto done;
7126cee1817eSEric Kohl     }
7127cee1817eSEric Kohl 
7128cee1817eSEric Kohl     RpcTryExcept
7129cee1817eSEric Kohl     {
7130cee1817eSEric Kohl         ret = PNP_QueryResConfList(BindingHandle,
7131cee1817eSEric Kohl                                    lpDevInst,
7132cee1817eSEric Kohl                                    ResourceID,
7133cee1817eSEric Kohl                                    (PBYTE)ResourceData,
7134cee1817eSEric Kohl                                    ResourceLen,
7135cee1817eSEric Kohl                                    (PBYTE)pConflictBuffer,
7136cee1817eSEric Kohl                                    ulBufferLength,
7137cee1817eSEric Kohl                                    ulFlags);
7138cee1817eSEric Kohl     }
7139cee1817eSEric Kohl     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
7140cee1817eSEric Kohl     {
7141cee1817eSEric Kohl         ret = RpcStatusToCmStatus(RpcExceptionCode());
7142cee1817eSEric Kohl     }
7143cee1817eSEric Kohl     RpcEndExcept;
7144cee1817eSEric Kohl 
7145cee1817eSEric Kohl     if (ret != CR_SUCCESS)
7146cee1817eSEric Kohl         goto done;
7147cee1817eSEric Kohl 
7148cee1817eSEric Kohl     pConflictData->ulMagic = CONFLICT_MAGIC;
7149cee1817eSEric Kohl     pConflictData->pConflictList = pConflictBuffer;
7150cee1817eSEric Kohl 
7151cee1817eSEric Kohl     *pclConflictList = (CONFLICT_LIST)pConflictData;
7152cee1817eSEric Kohl 
7153cee1817eSEric Kohl done:
7154cee1817eSEric Kohl     if (ret != CR_SUCCESS)
7155cee1817eSEric Kohl     {
7156cee1817eSEric Kohl         if (pConflictBuffer != NULL)
7157cee1817eSEric Kohl             MyFree(pConflictBuffer);
7158cee1817eSEric Kohl 
7159cee1817eSEric Kohl         if (pConflictData != NULL)
7160cee1817eSEric Kohl             MyFree(pConflictData);
7161cee1817eSEric Kohl     }
7162cee1817eSEric Kohl 
7163cee1817eSEric Kohl     return ret;
7164d7e40954SEric Kohl }
7165d7e40954SEric Kohl 
7166d7e40954SEric Kohl 
7167d7e40954SEric Kohl /***********************************************************************
7168c2c66affSColin Finck  * CM_Reenumerate_DevNode [SETUPAPI.@]
7169c2c66affSColin Finck  */
717065d3bf74SEric Kohl CONFIGRET
717165d3bf74SEric Kohl WINAPI
717265d3bf74SEric Kohl CM_Reenumerate_DevNode(
717365d3bf74SEric Kohl     _In_ DEVINST dnDevInst,
717465d3bf74SEric Kohl     _In_ ULONG ulFlags)
7175c2c66affSColin Finck {
717665d3bf74SEric Kohl     TRACE("CM_Reenumerate_DevNode(%lx %lx)\n",
717765d3bf74SEric Kohl           dnDevInst, ulFlags);
717865d3bf74SEric Kohl 
7179c2c66affSColin Finck     return CM_Reenumerate_DevNode_Ex(dnDevInst, ulFlags, NULL);
7180c2c66affSColin Finck }
7181c2c66affSColin Finck 
7182c2c66affSColin Finck 
7183c2c66affSColin Finck /***********************************************************************
7184c2c66affSColin Finck  * CM_Reenumerate_DevNode_Ex [SETUPAPI.@]
7185c2c66affSColin Finck  */
7186c2c66affSColin Finck CONFIGRET WINAPI
7187c2c66affSColin Finck CM_Reenumerate_DevNode_Ex(
7188c7fc2ef4SEric Kohl     _In_ DEVINST dnDevInst,
7189c7fc2ef4SEric Kohl     _In_ ULONG ulFlags,
719065d3bf74SEric Kohl     _In_opt_ HMACHINE hMachine)
7191c2c66affSColin Finck {
7192c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
7193c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
7194c2c66affSColin Finck     LPWSTR lpDevInst;
7195c2c66affSColin Finck     CONFIGRET ret;
7196c2c66affSColin Finck 
719760a21894SEric Kohl     FIXME("CM_Reenumerate_DevNode_Ex(%lx %lx %p)\n",
719865d3bf74SEric Kohl           dnDevInst, ulFlags, hMachine);
7199c2c66affSColin Finck 
7200c2c66affSColin Finck     if (dnDevInst == 0)
7201c2c66affSColin Finck         return CR_INVALID_DEVNODE;
7202c2c66affSColin Finck 
7203c2c66affSColin Finck     if (ulFlags & ~CM_REENUMERATE_BITS)
7204c2c66affSColin Finck         return CR_INVALID_FLAG;
7205c2c66affSColin Finck 
7206c2c66affSColin Finck     if (hMachine != NULL)
7207c2c66affSColin Finck     {
7208c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
7209c2c66affSColin Finck         if (BindingHandle == NULL)
7210c2c66affSColin Finck             return CR_FAILURE;
7211c2c66affSColin Finck 
7212c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
7213c2c66affSColin Finck         if (StringTable == 0)
7214c2c66affSColin Finck             return CR_FAILURE;
7215c2c66affSColin Finck     }
7216c2c66affSColin Finck     else
7217c2c66affSColin Finck     {
7218c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
7219c2c66affSColin Finck             return CR_FAILURE;
7220c2c66affSColin Finck     }
7221c2c66affSColin Finck 
7222c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
7223c2c66affSColin Finck     if (lpDevInst == NULL)
7224c2c66affSColin Finck         return CR_INVALID_DEVNODE;
7225c2c66affSColin Finck 
7226c2c66affSColin Finck     RpcTryExcept
7227c2c66affSColin Finck     {
7228c2c66affSColin Finck         ret = PNP_DeviceInstanceAction(BindingHandle,
7229c2c66affSColin Finck                                        PNP_DEVINST_REENUMERATE,
7230c2c66affSColin Finck                                        ulFlags,
7231c2c66affSColin Finck                                        lpDevInst,
7232c2c66affSColin Finck                                        NULL);
7233c2c66affSColin Finck     }
7234c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
7235c2c66affSColin Finck     {
7236c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
7237c2c66affSColin Finck     }
7238c2c66affSColin Finck     RpcEndExcept;
7239c2c66affSColin Finck 
7240c2c66affSColin Finck     return ret;
7241c2c66affSColin Finck }
7242c2c66affSColin Finck 
7243c2c66affSColin Finck 
7244c2c66affSColin Finck /***********************************************************************
724560a21894SEric Kohl  * CM_Register_Device_Driver [SETUPAPI.@]
724660a21894SEric Kohl  */
724760a21894SEric Kohl CONFIGRET
724860a21894SEric Kohl WINAPI
724960a21894SEric Kohl CM_Register_Device_Driver(
725060a21894SEric Kohl     _In_ DEVINST dnDevInst,
725160a21894SEric Kohl     _In_ ULONG ulFlags)
725260a21894SEric Kohl {
725360a21894SEric Kohl     TRACE("CM_Register_Device_Driver(%lx 0x%08lx)\n",
725460a21894SEric Kohl           dnDevInst, ulFlags);
725560a21894SEric Kohl 
725660a21894SEric Kohl     return CM_Register_Device_Driver_Ex(dnDevInst, ulFlags, NULL);
725760a21894SEric Kohl }
725860a21894SEric Kohl 
725960a21894SEric Kohl 
726060a21894SEric Kohl /***********************************************************************
726160a21894SEric Kohl  * CM_Register_Device_Driver_Ex [SETUPAPI.@]
726260a21894SEric Kohl  */
726360a21894SEric Kohl CONFIGRET
726460a21894SEric Kohl WINAPI
726560a21894SEric Kohl CM_Register_Device_Driver_Ex(
726660a21894SEric Kohl     _In_ DEVINST dnDevInst,
726760a21894SEric Kohl     _In_ ULONG ulFlags,
726860a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
726960a21894SEric Kohl {
727060a21894SEric Kohl     RPC_BINDING_HANDLE BindingHandle = NULL;
727160a21894SEric Kohl     HSTRING_TABLE StringTable = NULL;
727260a21894SEric Kohl     LPWSTR lpDevInst;
727360a21894SEric Kohl     CONFIGRET ret;
727460a21894SEric Kohl 
727560a21894SEric Kohl     TRACE("CM_Register_Device_Driver_Ex(%lx 0x%08lx %p)\n",
727660a21894SEric Kohl           dnDevInst, ulFlags, hMachine);
727760a21894SEric Kohl 
727860a21894SEric Kohl     if (dnDevInst == 0)
727960a21894SEric Kohl         return CR_INVALID_DEVNODE;
728060a21894SEric Kohl 
728160a21894SEric Kohl     if (ulFlags & ~CM_REGISTER_DEVICE_DRIVER_BITS)
728260a21894SEric Kohl         return CR_INVALID_FLAG;
728360a21894SEric Kohl 
728460a21894SEric Kohl     if (hMachine != NULL)
728560a21894SEric Kohl     {
728660a21894SEric Kohl         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
728760a21894SEric Kohl         if (BindingHandle == NULL)
728860a21894SEric Kohl             return CR_FAILURE;
728960a21894SEric Kohl 
729060a21894SEric Kohl         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
729160a21894SEric Kohl         if (StringTable == 0)
729260a21894SEric Kohl             return CR_FAILURE;
729360a21894SEric Kohl     }
729460a21894SEric Kohl     else
729560a21894SEric Kohl     {
729660a21894SEric Kohl         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
729760a21894SEric Kohl             return CR_FAILURE;
729860a21894SEric Kohl     }
729960a21894SEric Kohl 
730060a21894SEric Kohl     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
730160a21894SEric Kohl     if (lpDevInst == NULL)
730260a21894SEric Kohl         return CR_INVALID_DEVNODE;
730360a21894SEric Kohl 
730460a21894SEric Kohl     RpcTryExcept
730560a21894SEric Kohl     {
730660a21894SEric Kohl         ret = PNP_RegisterDriver(BindingHandle,
730760a21894SEric Kohl                                  lpDevInst,
730860a21894SEric Kohl                                  ulFlags);
730960a21894SEric Kohl     }
731060a21894SEric Kohl     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
731160a21894SEric Kohl     {
731260a21894SEric Kohl         ret = RpcStatusToCmStatus(RpcExceptionCode());
731360a21894SEric Kohl     }
731460a21894SEric Kohl     RpcEndExcept;
731560a21894SEric Kohl 
731660a21894SEric Kohl     return ret;
731760a21894SEric Kohl }
731860a21894SEric Kohl 
731960a21894SEric Kohl 
732060a21894SEric Kohl /***********************************************************************
7321c2c66affSColin Finck  * CM_Register_Device_InterfaceA [SETUPAPI.@]
7322c2c66affSColin Finck  */
732360a21894SEric Kohl CONFIGRET
732460a21894SEric Kohl WINAPI
732560a21894SEric Kohl CM_Register_Device_InterfaceA(
732660a21894SEric Kohl     _In_ DEVINST dnDevInst,
732760a21894SEric Kohl     _In_ LPGUID InterfaceClassGuid,
732860a21894SEric Kohl     _In_opt_ LPCSTR pszReference,
732960a21894SEric Kohl     _Out_writes_(*pulLength) LPSTR pszDeviceInterface,
733060a21894SEric Kohl     _Inout_ PULONG pulLength,
733160a21894SEric Kohl     _In_ ULONG ulFlags)
7332c2c66affSColin Finck {
733360a21894SEric Kohl     TRACE("CM_Register_Device_InterfaceA(%lx %s %s %p %p %lx)\n",
733460a21894SEric Kohl           dnDevInst, debugstr_guid(InterfaceClassGuid),
7335c2c66affSColin Finck           pszReference, pszDeviceInterface, pulLength, ulFlags);
7336c2c66affSColin Finck 
7337c2c66affSColin Finck     return CM_Register_Device_Interface_ExA(dnDevInst, InterfaceClassGuid,
7338c2c66affSColin Finck                                             pszReference, pszDeviceInterface,
7339c2c66affSColin Finck                                             pulLength, ulFlags, NULL);
7340c2c66affSColin Finck }
7341c2c66affSColin Finck 
7342c2c66affSColin Finck 
7343c2c66affSColin Finck /***********************************************************************
7344c2c66affSColin Finck  * CM_Register_Device_InterfaceW [SETUPAPI.@]
7345c2c66affSColin Finck  */
734660a21894SEric Kohl CONFIGRET
734760a21894SEric Kohl WINAPI
734860a21894SEric Kohl CM_Register_Device_InterfaceW(
734960a21894SEric Kohl     _In_ DEVINST dnDevInst,
735060a21894SEric Kohl     _In_ LPGUID InterfaceClassGuid,
735160a21894SEric Kohl     _In_opt_ LPCWSTR pszReference,
735260a21894SEric Kohl     _Out_writes_(*pulLength) LPWSTR pszDeviceInterface,
735360a21894SEric Kohl     _Inout_ PULONG pulLength,
735460a21894SEric Kohl     _In_ ULONG ulFlags)
7355c2c66affSColin Finck {
735660a21894SEric Kohl     TRACE("CM_Register_Device_InterfaceW(%lx %s %s %p %p %lx)\n",
735760a21894SEric Kohl           dnDevInst, debugstr_guid(InterfaceClassGuid),
7358c2c66affSColin Finck           debugstr_w(pszReference), pszDeviceInterface, pulLength, ulFlags);
7359c2c66affSColin Finck 
7360c2c66affSColin Finck     return CM_Register_Device_Interface_ExW(dnDevInst, InterfaceClassGuid,
7361c2c66affSColin Finck                                             pszReference, pszDeviceInterface,
7362c2c66affSColin Finck                                             pulLength, ulFlags, NULL);
7363c2c66affSColin Finck }
7364c2c66affSColin Finck 
7365c2c66affSColin Finck 
7366c2c66affSColin Finck /***********************************************************************
7367c2c66affSColin Finck  * CM_Register_Device_Interface_ExA [SETUPAPI.@]
7368c2c66affSColin Finck  */
736960a21894SEric Kohl CONFIGRET
737060a21894SEric Kohl WINAPI
737160a21894SEric Kohl CM_Register_Device_Interface_ExA(
737260a21894SEric Kohl     _In_ DEVINST dnDevInst,
737360a21894SEric Kohl     _In_ LPGUID InterfaceClassGuid,
737460a21894SEric Kohl     _In_opt_ LPCSTR pszReference,
737560a21894SEric Kohl     _Out_writes_(*pulLength) LPSTR pszDeviceInterface,
737660a21894SEric Kohl     _Inout_ PULONG pulLength,
737760a21894SEric Kohl     _In_ ULONG ulFlags,
737860a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
7379c2c66affSColin Finck {
7380c2c66affSColin Finck     LPWSTR pszReferenceW = NULL;
73818943354dSSerge Gautherie     LPWSTR pszDeviceInterfaceW;
7382c2c66affSColin Finck     ULONG ulLength;
7383c2c66affSColin Finck     CONFIGRET ret;
7384c2c66affSColin Finck 
738560a21894SEric Kohl     TRACE("CM_Register_Device_Interface_ExA(%lx %s %s %p %p %lx %p)\n",
738660a21894SEric Kohl           dnDevInst, debugstr_guid(InterfaceClassGuid), debugstr_a(pszReference),
738760a21894SEric Kohl           pszDeviceInterface, pulLength, ulFlags, hMachine);
7388c2c66affSColin Finck 
7389c2c66affSColin Finck     if (pulLength == NULL || pszDeviceInterface == NULL)
7390c2c66affSColin Finck         return CR_INVALID_POINTER;
7391c2c66affSColin Finck 
7392c2c66affSColin Finck     if (pszReference != NULL)
7393c2c66affSColin Finck     {
7394c2c66affSColin Finck         if (pSetupCaptureAndConvertAnsiArg(pszReference, &pszReferenceW))
7395c2c66affSColin Finck             return CR_INVALID_DATA;
7396c2c66affSColin Finck     }
7397c2c66affSColin Finck 
7398c2c66affSColin Finck     ulLength = *pulLength;
7399c2c66affSColin Finck 
7400c2c66affSColin Finck     pszDeviceInterfaceW = HeapAlloc(GetProcessHeap(), 0, ulLength * sizeof(WCHAR));
7401c2c66affSColin Finck     if (pszDeviceInterfaceW == NULL)
7402c2c66affSColin Finck     {
7403c2c66affSColin Finck         ret = CR_OUT_OF_MEMORY;
7404c2c66affSColin Finck         goto Done;
7405c2c66affSColin Finck     }
7406c2c66affSColin Finck 
7407c2c66affSColin Finck     ret = CM_Register_Device_Interface_ExW(dnDevInst,
7408c2c66affSColin Finck                                            InterfaceClassGuid,
7409c2c66affSColin Finck                                            pszReferenceW,
7410c2c66affSColin Finck                                            pszDeviceInterfaceW,
7411c2c66affSColin Finck                                            &ulLength,
7412c2c66affSColin Finck                                            ulFlags,
7413c2c66affSColin Finck                                            hMachine);
7414c2c66affSColin Finck     if (ret == CR_SUCCESS)
7415c2c66affSColin Finck     {
7416c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
7417c2c66affSColin Finck                                 0,
7418c2c66affSColin Finck                                 pszDeviceInterfaceW,
7419c2c66affSColin Finck                                 ulLength,
7420c2c66affSColin Finck                                 pszDeviceInterface,
7421c2c66affSColin Finck                                 *pulLength,
7422c2c66affSColin Finck                                 NULL,
7423c2c66affSColin Finck                                 NULL) == 0)
7424c2c66affSColin Finck             ret = CR_FAILURE;
7425c2c66affSColin Finck     }
7426c2c66affSColin Finck 
7427c2c66affSColin Finck     *pulLength = ulLength;
7428c2c66affSColin Finck 
7429c2c66affSColin Finck Done:
7430c2c66affSColin Finck     if (pszDeviceInterfaceW != NULL)
7431c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, pszDeviceInterfaceW);
7432c2c66affSColin Finck 
7433c2c66affSColin Finck     if (pszReferenceW != NULL)
7434c2c66affSColin Finck         MyFree(pszReferenceW);
7435c2c66affSColin Finck 
7436c2c66affSColin Finck     return ret;
7437c2c66affSColin Finck }
7438c2c66affSColin Finck 
7439c2c66affSColin Finck 
7440c2c66affSColin Finck /***********************************************************************
7441c2c66affSColin Finck  * CM_Register_Device_Interface_ExW [SETUPAPI.@]
7442c2c66affSColin Finck  */
744360a21894SEric Kohl CONFIGRET
744460a21894SEric Kohl WINAPI
744560a21894SEric Kohl CM_Register_Device_Interface_ExW(
744660a21894SEric Kohl     _In_ DEVINST dnDevInst,
744760a21894SEric Kohl     _In_ LPGUID InterfaceClassGuid,
744860a21894SEric Kohl     _In_opt_ LPCWSTR pszReference,
744960a21894SEric Kohl     _Out_writes_(*pulLength) LPWSTR pszDeviceInterface,
745060a21894SEric Kohl     _Inout_ PULONG pulLength,
745160a21894SEric Kohl     _In_ ULONG ulFlags,
745260a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
7453c2c66affSColin Finck {
7454c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
7455c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
7456c2c66affSColin Finck     LPWSTR lpDevInst;
7457c2c66affSColin Finck     ULONG ulTransferLength;
7458c2c66affSColin Finck     CONFIGRET ret;
7459c2c66affSColin Finck 
746060a21894SEric Kohl     TRACE("CM_Register_Device_Interface_ExW(%lx %s %s %p %p %lx %p)\n",
746160a21894SEric Kohl           dnDevInst, debugstr_guid(InterfaceClassGuid), debugstr_w(pszReference),
746260a21894SEric Kohl           pszDeviceInterface, pulLength, ulFlags, hMachine);
7463c2c66affSColin Finck 
7464c2c66affSColin Finck     if (dnDevInst == 0)
7465c2c66affSColin Finck         return CR_INVALID_DEVNODE;
7466c2c66affSColin Finck 
7467c2c66affSColin Finck     if (InterfaceClassGuid == NULL ||
7468c2c66affSColin Finck         pszDeviceInterface == NULL ||
7469c2c66affSColin Finck         pulLength == NULL)
7470c2c66affSColin Finck         return CR_INVALID_POINTER;
7471c2c66affSColin Finck 
7472c2c66affSColin Finck     if (ulFlags != 0)
7473c2c66affSColin Finck         return CR_INVALID_FLAG;
7474c2c66affSColin Finck 
7475c2c66affSColin Finck     if (hMachine != NULL)
7476c2c66affSColin Finck     {
7477c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
7478c2c66affSColin Finck         if (BindingHandle == NULL)
7479c2c66affSColin Finck             return CR_FAILURE;
7480c2c66affSColin Finck 
7481c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
7482c2c66affSColin Finck         if (StringTable == 0)
7483c2c66affSColin Finck             return CR_FAILURE;
7484c2c66affSColin Finck     }
7485c2c66affSColin Finck     else
7486c2c66affSColin Finck     {
7487c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
7488c2c66affSColin Finck             return CR_FAILURE;
7489c2c66affSColin Finck     }
7490c2c66affSColin Finck 
7491c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
7492c2c66affSColin Finck     if (lpDevInst == NULL)
7493c2c66affSColin Finck         return CR_INVALID_DEVNODE;
7494c2c66affSColin Finck 
7495c2c66affSColin Finck     ulTransferLength = *pulLength;
7496c2c66affSColin Finck 
7497c2c66affSColin Finck     RpcTryExcept
7498c2c66affSColin Finck     {
7499c2c66affSColin Finck         ret = PNP_RegisterDeviceClassAssociation(BindingHandle,
7500c2c66affSColin Finck                                                  lpDevInst,
7501c2c66affSColin Finck                                                  InterfaceClassGuid,
7502c2c66affSColin Finck                                                  (LPWSTR)pszReference,
7503c2c66affSColin Finck                                                  pszDeviceInterface,
7504c2c66affSColin Finck                                                  pulLength,
7505c2c66affSColin Finck                                                  &ulTransferLength,
7506c2c66affSColin Finck                                                  0);
7507c2c66affSColin Finck     }
7508c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
7509c2c66affSColin Finck     {
7510c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
7511c2c66affSColin Finck     }
7512c2c66affSColin Finck     RpcEndExcept;
7513c2c66affSColin Finck 
7514c2c66affSColin Finck     return ret;
7515c2c66affSColin Finck }
7516c2c66affSColin Finck 
7517c2c66affSColin Finck 
7518c2c66affSColin Finck /***********************************************************************
7519c2c66affSColin Finck  * CM_Remove_SubTree [SETUPAPI.@]
7520c2c66affSColin Finck  *
7521c2c66affSColin Finck  * This function is obsolete in Windows XP and above.
7522c2c66affSColin Finck  */
752360a21894SEric Kohl CONFIGRET
752460a21894SEric Kohl WINAPI
752560a21894SEric Kohl CM_Remove_SubTree(
752660a21894SEric Kohl     _In_ DEVINST dnAncestor,
752760a21894SEric Kohl     _In_ ULONG ulFlags)
7528c2c66affSColin Finck {
752960a21894SEric Kohl     TRACE("CM_Remove_SubTree(%lx %lx)\n",
753060a21894SEric Kohl           dnAncestor, ulFlags);
753160a21894SEric Kohl 
7532c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
7533c2c66affSColin Finck }
7534c2c66affSColin Finck 
7535c2c66affSColin Finck 
7536c2c66affSColin Finck /***********************************************************************
7537c2c66affSColin Finck  * CM_Remove_SubTree_Ex [SETUPAPI.@]
7538c2c66affSColin Finck  *
7539c2c66affSColin Finck  * This function is obsolete in Windows XP and above.
7540c2c66affSColin Finck  */
754160a21894SEric Kohl CONFIGRET
754260a21894SEric Kohl WINAPI
754360a21894SEric Kohl CM_Remove_SubTree_Ex(
754460a21894SEric Kohl     _In_ DEVINST dnAncestor,
754560a21894SEric Kohl     _In_ ULONG ulFlags,
754660a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
7547c2c66affSColin Finck {
754860a21894SEric Kohl     TRACE("CM_Remove_SubTree_Ex(%lx %lx %p)\n",
754960a21894SEric Kohl           dnAncestor, ulFlags, hMachine);
755060a21894SEric Kohl 
7551c2c66affSColin Finck     return CR_CALL_NOT_IMPLEMENTED;
7552c2c66affSColin Finck }
7553c2c66affSColin Finck 
7554c2c66affSColin Finck 
7555c2c66affSColin Finck /***********************************************************************
7556c2c66affSColin Finck  * CM_Request_Device_EjectA [SETUPAPI.@]
7557c2c66affSColin Finck  */
755860a21894SEric Kohl CONFIGRET
755960a21894SEric Kohl WINAPI
756060a21894SEric Kohl CM_Request_Device_EjectA(
756160a21894SEric Kohl     _In_ DEVINST dnDevInst,
756260a21894SEric Kohl     _Out_opt_ PPNP_VETO_TYPE pVetoType,
756360a21894SEric Kohl     _Out_writes_opt_(ulNameLength) LPSTR pszVetoName,
756460a21894SEric Kohl     _In_ ULONG ulNameLength,
756560a21894SEric Kohl     _In_ ULONG ulFlags)
7566c2c66affSColin Finck {
75675b5aaf66SSerge Gautherie     TRACE("CM_Request_Device_EjectA(%lx %p %p %lu %lx)\n",
75685b5aaf66SSerge Gautherie           dnDevInst, pVetoType, pszVetoName, ulNameLength, ulFlags);
756960a21894SEric Kohl 
7570c2c66affSColin Finck     return CM_Request_Device_Eject_ExA(dnDevInst, pVetoType, pszVetoName,
7571c2c66affSColin Finck                                        ulNameLength, ulFlags, NULL);
7572c2c66affSColin Finck }
7573c2c66affSColin Finck 
7574c2c66affSColin Finck 
7575c2c66affSColin Finck /***********************************************************************
7576c2c66affSColin Finck  * CM_Request_Device_EjectW [SETUPAPI.@]
7577c2c66affSColin Finck  */
757860a21894SEric Kohl CONFIGRET
757960a21894SEric Kohl WINAPI
758060a21894SEric Kohl CM_Request_Device_EjectW(
758160a21894SEric Kohl     _In_ DEVINST dnDevInst,
758260a21894SEric Kohl     _Out_opt_ PPNP_VETO_TYPE pVetoType,
758360a21894SEric Kohl     _Out_writes_opt_(ulNameLength) LPWSTR pszVetoName,
758460a21894SEric Kohl     _In_ ULONG ulNameLength,
758560a21894SEric Kohl     _In_ ULONG ulFlags)
7586c2c66affSColin Finck {
75875b5aaf66SSerge Gautherie     TRACE("CM_Request_Device_EjectW(%lx %p %p %lu %lx)\n",
75885b5aaf66SSerge Gautherie           dnDevInst, pVetoType, pszVetoName, ulNameLength, ulFlags);
758960a21894SEric Kohl 
7590c2c66affSColin Finck     return CM_Request_Device_Eject_ExW(dnDevInst, pVetoType, pszVetoName,
7591c2c66affSColin Finck                                        ulNameLength, ulFlags, NULL);
7592c2c66affSColin Finck }
7593c2c66affSColin Finck 
7594c2c66affSColin Finck 
7595c2c66affSColin Finck /***********************************************************************
7596c2c66affSColin Finck  * CM_Request_Device_Eject_ExA [SETUPAPI.@]
7597c2c66affSColin Finck  */
759860a21894SEric Kohl CONFIGRET
759960a21894SEric Kohl WINAPI
760060a21894SEric Kohl CM_Request_Device_Eject_ExA(
760160a21894SEric Kohl     _In_ DEVINST dnDevInst,
760260a21894SEric Kohl     _Out_opt_ PPNP_VETO_TYPE pVetoType,
760360a21894SEric Kohl     _Out_writes_opt_(ulNameLength) LPSTR pszVetoName,
760460a21894SEric Kohl     _In_ ULONG ulNameLength,
760560a21894SEric Kohl     _In_ ULONG ulFlags,
760660a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
7607c2c66affSColin Finck {
76087f346b1aSThamatip Chitpong     LPWSTR lpLocalVetoName = NULL;
7609c2c66affSColin Finck     CONFIGRET ret;
7610c2c66affSColin Finck 
76115b5aaf66SSerge Gautherie     TRACE("CM_Request_Device_Eject_ExA(%lx %p %p %lu %lx %p)\n",
76125b5aaf66SSerge Gautherie           dnDevInst, pVetoType, pszVetoName, ulNameLength, ulFlags, hMachine);
7613c2c66affSColin Finck 
76147f346b1aSThamatip Chitpong     if (ulNameLength != 0)
76157f346b1aSThamatip Chitpong     {
76167f346b1aSThamatip Chitpong         if (pszVetoName == NULL)
7617c2c66affSColin Finck             return CR_INVALID_POINTER;
7618c2c66affSColin Finck 
7619c2c66affSColin Finck         lpLocalVetoName = HeapAlloc(GetProcessHeap(), 0, ulNameLength * sizeof(WCHAR));
7620c2c66affSColin Finck         if (lpLocalVetoName == NULL)
7621c2c66affSColin Finck             return CR_OUT_OF_MEMORY;
76227f346b1aSThamatip Chitpong     }
7623c2c66affSColin Finck 
7624c2c66affSColin Finck     ret = CM_Request_Device_Eject_ExW(dnDevInst, pVetoType, lpLocalVetoName,
7625c2c66affSColin Finck                                       ulNameLength, ulFlags, hMachine);
76267f346b1aSThamatip Chitpong     if (ret == CR_REMOVE_VETOED && ulNameLength != 0)
7627c2c66affSColin Finck     {
7628c2c66affSColin Finck         if (WideCharToMultiByte(CP_ACP,
7629c2c66affSColin Finck                                 0,
7630c2c66affSColin Finck                                 lpLocalVetoName,
7631c2c66affSColin Finck                                 ulNameLength,
7632c2c66affSColin Finck                                 pszVetoName,
7633c2c66affSColin Finck                                 ulNameLength,
7634c2c66affSColin Finck                                 NULL,
7635c2c66affSColin Finck                                 NULL) == 0)
7636c2c66affSColin Finck             ret = CR_FAILURE;
7637c2c66affSColin Finck     }
7638c2c66affSColin Finck 
7639c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, lpLocalVetoName);
7640c2c66affSColin Finck 
7641c2c66affSColin Finck     return ret;
7642c2c66affSColin Finck }
7643c2c66affSColin Finck 
7644c2c66affSColin Finck 
7645c2c66affSColin Finck /***********************************************************************
7646c2c66affSColin Finck  * CM_Request_Device_Eject_ExW [SETUPAPI.@]
7647c2c66affSColin Finck  */
764860a21894SEric Kohl CONFIGRET
764960a21894SEric Kohl WINAPI
765060a21894SEric Kohl CM_Request_Device_Eject_ExW(
765160a21894SEric Kohl     _In_ DEVINST dnDevInst,
765260a21894SEric Kohl     _Out_opt_ PPNP_VETO_TYPE pVetoType,
765360a21894SEric Kohl     _Out_writes_opt_(ulNameLength) LPWSTR pszVetoName,
765460a21894SEric Kohl     _In_ ULONG ulNameLength,
765560a21894SEric Kohl     _In_ ULONG ulFlags,
765660a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
7657c2c66affSColin Finck {
7658c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
7659c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
7660c2c66affSColin Finck     LPWSTR lpDevInst;
7661c2c66affSColin Finck     CONFIGRET ret;
7662c2c66affSColin Finck 
76635b5aaf66SSerge Gautherie     TRACE("CM_Request_Device_Eject_ExW(%lx %p %p %lu %lx %p)\n",
76645b5aaf66SSerge Gautherie           dnDevInst, pVetoType, pszVetoName, ulNameLength, ulFlags, hMachine);
7665c2c66affSColin Finck 
7666c2c66affSColin Finck     if (dnDevInst == 0)
7667c2c66affSColin Finck         return CR_INVALID_DEVNODE;
7668c2c66affSColin Finck 
7669c2c66affSColin Finck     if (ulFlags != 0)
7670c2c66affSColin Finck         return CR_INVALID_FLAG;
7671c2c66affSColin Finck 
76727f346b1aSThamatip Chitpong     if (pszVetoName == NULL && ulNameLength != 0)
7673c2c66affSColin Finck         return CR_INVALID_POINTER;
7674c2c66affSColin Finck 
767540bc5bf4SThamatip Chitpong     /* Windows 2003 SP2 ignores pszVetoName when ulNameLength is zero
767640bc5bf4SThamatip Chitpong      * and behaves like when pszVetoName is NULL */
767740bc5bf4SThamatip Chitpong     if (ulNameLength == 0)
767840bc5bf4SThamatip Chitpong         pszVetoName = NULL;
767940bc5bf4SThamatip Chitpong 
7680c2c66affSColin Finck     if (hMachine != NULL)
7681c2c66affSColin Finck     {
7682c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
7683c2c66affSColin Finck         if (BindingHandle == NULL)
7684c2c66affSColin Finck             return CR_FAILURE;
7685c2c66affSColin Finck 
7686c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
7687c2c66affSColin Finck         if (StringTable == 0)
7688c2c66affSColin Finck             return CR_FAILURE;
7689c2c66affSColin Finck     }
7690c2c66affSColin Finck     else
7691c2c66affSColin Finck     {
7692c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
7693c2c66affSColin Finck             return CR_FAILURE;
7694c2c66affSColin Finck     }
7695c2c66affSColin Finck 
7696c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
7697c2c66affSColin Finck     if (lpDevInst == NULL)
7698c2c66affSColin Finck         return CR_INVALID_DEVNODE;
7699c2c66affSColin Finck 
7700c2c66affSColin Finck     RpcTryExcept
7701c2c66affSColin Finck     {
7702c2c66affSColin Finck         ret = PNP_RequestDeviceEject(BindingHandle,
7703c2c66affSColin Finck                                      lpDevInst,
7704c2c66affSColin Finck                                      pVetoType,
7705c2c66affSColin Finck                                      pszVetoName,
7706c2c66affSColin Finck                                      ulNameLength,
7707c2c66affSColin Finck                                      ulFlags);
7708c2c66affSColin Finck     }
7709c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
7710c2c66affSColin Finck     {
7711c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
7712c2c66affSColin Finck     }
7713c2c66affSColin Finck     RpcEndExcept;
7714c2c66affSColin Finck 
7715c2c66affSColin Finck     return ret;
7716c2c66affSColin Finck }
7717c2c66affSColin Finck 
7718c2c66affSColin Finck 
7719c2c66affSColin Finck /***********************************************************************
7720c2c66affSColin Finck  * CM_Request_Eject_PC [SETUPAPI.@]
7721c2c66affSColin Finck  */
772260a21894SEric Kohl CONFIGRET
772360a21894SEric Kohl WINAPI
772460a21894SEric Kohl CM_Request_Eject_PC(VOID)
7725c2c66affSColin Finck {
772660a21894SEric Kohl     TRACE("CM_Request_Eject_PC()\n");
772760a21894SEric Kohl 
7728c2c66affSColin Finck     return CM_Request_Eject_PC_Ex(NULL);
7729c2c66affSColin Finck }
7730c2c66affSColin Finck 
7731c2c66affSColin Finck 
7732c2c66affSColin Finck /***********************************************************************
7733c2c66affSColin Finck  * CM_Request_Eject_PC_Ex [SETUPAPI.@]
7734c2c66affSColin Finck  */
773560a21894SEric Kohl CONFIGRET
773660a21894SEric Kohl WINAPI
773760a21894SEric Kohl CM_Request_Eject_PC_Ex(
773860a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
7739c2c66affSColin Finck {
7740c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
7741c2c66affSColin Finck     CONFIGRET ret;
7742c2c66affSColin Finck 
774360a21894SEric Kohl     TRACE("CM_Request_Eject_PC_Ex(%p)\n", hMachine);
7744c2c66affSColin Finck 
7745c2c66affSColin Finck     if (hMachine != NULL)
7746c2c66affSColin Finck     {
7747c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
7748c2c66affSColin Finck         if (BindingHandle == NULL)
7749c2c66affSColin Finck             return CR_FAILURE;
7750c2c66affSColin Finck     }
7751c2c66affSColin Finck     else
7752c2c66affSColin Finck     {
7753c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
7754c2c66affSColin Finck             return CR_FAILURE;
7755c2c66affSColin Finck     }
7756c2c66affSColin Finck 
7757c2c66affSColin Finck     RpcTryExcept
7758c2c66affSColin Finck     {
7759c2c66affSColin Finck         ret = PNP_RequestEjectPC(BindingHandle);
7760c2c66affSColin Finck     }
7761c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
7762c2c66affSColin Finck     {
7763c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
7764c2c66affSColin Finck     }
7765c2c66affSColin Finck     RpcEndExcept;
7766c2c66affSColin Finck 
7767c2c66affSColin Finck     return ret;
7768c2c66affSColin Finck }
7769c2c66affSColin Finck 
7770c2c66affSColin Finck 
7771c2c66affSColin Finck /***********************************************************************
7772c2c66affSColin Finck  * CM_Run_Detection [SETUPAPI.@]
7773c2c66affSColin Finck  */
777460a21894SEric Kohl CONFIGRET
777560a21894SEric Kohl WINAPI
777660a21894SEric Kohl CM_Run_Detection(
777760a21894SEric Kohl     _In_ ULONG ulFlags)
7778c2c66affSColin Finck {
777960a21894SEric Kohl     TRACE("CM_Run_Detection(%lx)\n", ulFlags);
778060a21894SEric Kohl 
7781c2c66affSColin Finck     return CM_Run_Detection_Ex(ulFlags, NULL);
7782c2c66affSColin Finck }
7783c2c66affSColin Finck 
7784c2c66affSColin Finck 
7785c2c66affSColin Finck /***********************************************************************
7786c2c66affSColin Finck  * CM_Run_Detection_Ex [SETUPAPI.@]
7787c2c66affSColin Finck  */
778860a21894SEric Kohl CONFIGRET
778960a21894SEric Kohl WINAPI
779060a21894SEric Kohl CM_Run_Detection_Ex(
779160a21894SEric Kohl     _In_ ULONG ulFlags,
779260a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
7793c2c66affSColin Finck {
7794c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
7795c2c66affSColin Finck     CONFIGRET ret;
7796c2c66affSColin Finck 
779760a21894SEric Kohl     TRACE("CM_Run_Detection_Ex(%lx %p)\n",
779860a21894SEric Kohl           ulFlags, hMachine);
7799c2c66affSColin Finck 
7800c2c66affSColin Finck     if (!pSetupIsUserAdmin())
7801c2c66affSColin Finck         return CR_ACCESS_DENIED;
7802c2c66affSColin Finck 
7803c2c66affSColin Finck     if (ulFlags & ~CM_DETECT_BITS)
7804c2c66affSColin Finck         return CR_INVALID_FLAG;
7805c2c66affSColin Finck 
7806c2c66affSColin Finck     if (hMachine != NULL)
7807c2c66affSColin Finck     {
7808c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
7809c2c66affSColin Finck         if (BindingHandle == NULL)
7810c2c66affSColin Finck             return CR_FAILURE;
7811c2c66affSColin Finck     }
7812c2c66affSColin Finck     else
7813c2c66affSColin Finck     {
7814c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
7815c2c66affSColin Finck             return CR_FAILURE;
7816c2c66affSColin Finck     }
7817c2c66affSColin Finck 
7818c2c66affSColin Finck     RpcTryExcept
7819c2c66affSColin Finck     {
7820c2c66affSColin Finck         ret = PNP_RunDetection(BindingHandle,
7821c2c66affSColin Finck                                ulFlags);
7822c2c66affSColin Finck     }
7823c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
7824c2c66affSColin Finck     {
7825c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
7826c2c66affSColin Finck     }
7827c2c66affSColin Finck     RpcEndExcept;
7828c2c66affSColin Finck 
7829c2c66affSColin Finck     return ret;
7830c2c66affSColin Finck }
7831c2c66affSColin Finck 
7832c2c66affSColin Finck 
7833c2c66affSColin Finck /***********************************************************************
7834c2c66affSColin Finck  * CM_Set_Class_Registry_PropertyA [SETUPAPI.@]
7835c2c66affSColin Finck  */
783660a21894SEric Kohl CONFIGRET
783760a21894SEric Kohl WINAPI
783860a21894SEric Kohl CM_Set_Class_Registry_PropertyA(
783960a21894SEric Kohl     _In_ LPGUID ClassGuid,
784060a21894SEric Kohl     _In_ ULONG ulProperty,
784160a21894SEric Kohl     _In_reads_bytes_opt_(ulLength) PCVOID Buffer,
784260a21894SEric Kohl     _In_ ULONG ulLength,
784360a21894SEric Kohl     _In_ ULONG ulFlags,
784460a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
7845c2c66affSColin Finck {
7846*b667d82fSEric Kohl     LPWSTR lpBuffer;
7847*b667d82fSEric Kohl     ULONG ulType;
7848*b667d82fSEric Kohl     CONFIGRET ret;
7849*b667d82fSEric Kohl 
7850*b667d82fSEric Kohl     TRACE("CM_Set_Class_Registry_PropertyA(%p %lx %p %lu %lx %p)\n",
7851c2c66affSColin Finck           ClassGuid, ulProperty, Buffer, ulLength, ulFlags, hMachine);
785260a21894SEric Kohl 
7853*b667d82fSEric Kohl     if (ClassGuid == NULL)
7854*b667d82fSEric Kohl         return CR_INVALID_POINTER;
7855*b667d82fSEric Kohl 
7856*b667d82fSEric Kohl     if ((Buffer == NULL) && (ulLength != 0))
7857*b667d82fSEric Kohl         return CR_INVALID_POINTER;
7858*b667d82fSEric Kohl 
7859*b667d82fSEric Kohl     if (ulFlags != 0)
7860*b667d82fSEric Kohl         return CR_INVALID_FLAG;
7861*b667d82fSEric Kohl 
7862*b667d82fSEric Kohl     if (Buffer == NULL)
7863*b667d82fSEric Kohl     {
7864*b667d82fSEric Kohl         ret = CM_Set_Class_Registry_PropertyW(ClassGuid,
7865*b667d82fSEric Kohl                                               ulProperty,
7866*b667d82fSEric Kohl                                               Buffer,
7867*b667d82fSEric Kohl                                               ulLength,
7868*b667d82fSEric Kohl                                               ulFlags,
7869*b667d82fSEric Kohl                                               hMachine);
7870*b667d82fSEric Kohl     }
7871*b667d82fSEric Kohl     else
7872*b667d82fSEric Kohl     {
7873*b667d82fSEric Kohl         /* Get property type */
7874*b667d82fSEric Kohl         ulType = GetRegistryPropertyType(ulProperty);
7875*b667d82fSEric Kohl 
7876*b667d82fSEric Kohl         /* Allocate buffer if needed */
7877*b667d82fSEric Kohl         if ((ulType == REG_SZ) || (ulType == REG_MULTI_SZ))
7878*b667d82fSEric Kohl         {
7879*b667d82fSEric Kohl             lpBuffer = MyMalloc(ulLength * sizeof(WCHAR));
7880*b667d82fSEric Kohl             if (lpBuffer == NULL)
7881*b667d82fSEric Kohl             {
7882*b667d82fSEric Kohl                 ret = CR_OUT_OF_MEMORY;
7883*b667d82fSEric Kohl             }
7884*b667d82fSEric Kohl             else
7885*b667d82fSEric Kohl             {
7886*b667d82fSEric Kohl                 if (!MultiByteToWideChar(CP_ACP, 0, Buffer,
7887*b667d82fSEric Kohl                                          ulLength, lpBuffer, ulLength))
7888*b667d82fSEric Kohl                 {
7889*b667d82fSEric Kohl                     MyFree(lpBuffer);
7890*b667d82fSEric Kohl                     ret = CR_FAILURE;
7891*b667d82fSEric Kohl                 }
7892*b667d82fSEric Kohl                 else
7893*b667d82fSEric Kohl                 {
7894*b667d82fSEric Kohl                     ret = CM_Set_Class_Registry_PropertyW(ClassGuid,
7895*b667d82fSEric Kohl                                                           ulProperty,
7896*b667d82fSEric Kohl                                                           lpBuffer,
7897*b667d82fSEric Kohl                                                           ulLength * sizeof(WCHAR),
7898*b667d82fSEric Kohl                                                           ulFlags,
7899*b667d82fSEric Kohl                                                           hMachine);
7900*b667d82fSEric Kohl                     MyFree(lpBuffer);
7901*b667d82fSEric Kohl                 }
7902*b667d82fSEric Kohl             }
7903*b667d82fSEric Kohl         }
7904*b667d82fSEric Kohl         else
7905*b667d82fSEric Kohl         {
7906*b667d82fSEric Kohl             ret = CM_Set_Class_Registry_PropertyW(ClassGuid,
7907*b667d82fSEric Kohl                                                   ulProperty,
7908*b667d82fSEric Kohl                                                   Buffer,
7909*b667d82fSEric Kohl                                                   ulLength,
7910*b667d82fSEric Kohl                                                   ulFlags,
7911*b667d82fSEric Kohl                                                   hMachine);
7912*b667d82fSEric Kohl         }
7913*b667d82fSEric Kohl 
7914*b667d82fSEric Kohl     }
7915*b667d82fSEric Kohl 
7916*b667d82fSEric Kohl     return ret;
7917c2c66affSColin Finck }
7918c2c66affSColin Finck 
7919c2c66affSColin Finck 
7920c2c66affSColin Finck /***********************************************************************
7921c2c66affSColin Finck  * CM_Set_Class_Registry_PropertyW [SETUPAPI.@]
7922c2c66affSColin Finck  */
792360a21894SEric Kohl CONFIGRET
792460a21894SEric Kohl WINAPI
792560a21894SEric Kohl CM_Set_Class_Registry_PropertyW(
792660a21894SEric Kohl     _In_ LPGUID ClassGuid,
792760a21894SEric Kohl     _In_ ULONG ulProperty,
792860a21894SEric Kohl     _In_reads_bytes_opt_(ulLength) PCVOID Buffer,
792960a21894SEric Kohl     _In_ ULONG ulLength,
793060a21894SEric Kohl     _In_ ULONG ulFlags,
793160a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
7932c2c66affSColin Finck {
793318c3f39cSEric Kohl     RPC_BINDING_HANDLE BindingHandle = NULL;
793418c3f39cSEric Kohl     WCHAR szGuidString[PNP_MAX_GUID_STRING_LEN + 1];
793518c3f39cSEric Kohl     ULONG ulType = 0;
793618c3f39cSEric Kohl     CONFIGRET ret;
793718c3f39cSEric Kohl 
793818c3f39cSEric Kohl     TRACE("CM_Set_Class_Registry_PropertyW(%p %lx %p %lu %lx %p)\n",
7939c2c66affSColin Finck           ClassGuid, ulProperty, Buffer, ulLength, ulFlags, hMachine);
794060a21894SEric Kohl 
794118c3f39cSEric Kohl     if (ClassGuid == NULL)
794218c3f39cSEric Kohl         return CR_INVALID_POINTER;
794318c3f39cSEric Kohl 
794418c3f39cSEric Kohl     if ((Buffer == NULL) && (ulLength != 0))
794518c3f39cSEric Kohl         return CR_INVALID_POINTER;
794618c3f39cSEric Kohl 
794718c3f39cSEric Kohl     if (ulFlags != 0)
794818c3f39cSEric Kohl         return CR_INVALID_FLAG;
794918c3f39cSEric Kohl 
795018c3f39cSEric Kohl     if (pSetupStringFromGuid(ClassGuid,
795118c3f39cSEric Kohl                              szGuidString,
795218c3f39cSEric Kohl                              PNP_MAX_GUID_STRING_LEN) != 0)
795318c3f39cSEric Kohl         return CR_INVALID_DATA;
795418c3f39cSEric Kohl 
795518c3f39cSEric Kohl     if ((ulProperty < CM_CRP_MIN) || (ulProperty > CM_CRP_MAX))
795618c3f39cSEric Kohl         return CR_INVALID_PROPERTY;
795718c3f39cSEric Kohl 
795818c3f39cSEric Kohl     if (hMachine != NULL)
795918c3f39cSEric Kohl     {
796018c3f39cSEric Kohl         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
796118c3f39cSEric Kohl         if (BindingHandle == NULL)
796218c3f39cSEric Kohl             return CR_FAILURE;
796318c3f39cSEric Kohl     }
796418c3f39cSEric Kohl     else
796518c3f39cSEric Kohl     {
796618c3f39cSEric Kohl         if (!PnpGetLocalHandles(&BindingHandle, NULL))
796718c3f39cSEric Kohl             return CR_FAILURE;
796818c3f39cSEric Kohl     }
796918c3f39cSEric Kohl 
797018c3f39cSEric Kohl     ulType = GetRegistryPropertyType(ulProperty);
797118c3f39cSEric Kohl     if ((ulType == REG_DWORD) && (ulLength != sizeof(DWORD)))
797218c3f39cSEric Kohl         return CR_INVALID_DATA;
797318c3f39cSEric Kohl 
797418c3f39cSEric Kohl     if (ulProperty == CM_CRP_SECURITY_SDS)
797518c3f39cSEric Kohl     {
797618c3f39cSEric Kohl         FIXME("Conversion from text SD to binary SD is not implemented yet!\n");
7977c2c66affSColin Finck         return CR_CALL_NOT_IMPLEMENTED;
7978c2c66affSColin Finck     }
7979c2c66affSColin Finck 
798018c3f39cSEric Kohl     RpcTryExcept
798118c3f39cSEric Kohl     {
798218c3f39cSEric Kohl         ret = PNP_SetClassRegProp(BindingHandle,
798318c3f39cSEric Kohl                                   szGuidString,
798418c3f39cSEric Kohl                                   ulProperty,
798518c3f39cSEric Kohl                                   ulType,
798618c3f39cSEric Kohl                                   (LPBYTE)Buffer,
798718c3f39cSEric Kohl                                   ulLength,
798818c3f39cSEric Kohl                                   ulFlags);
798918c3f39cSEric Kohl     }
799018c3f39cSEric Kohl     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
799118c3f39cSEric Kohl     {
799218c3f39cSEric Kohl         ret = RpcStatusToCmStatus(RpcExceptionCode());
799318c3f39cSEric Kohl     }
799418c3f39cSEric Kohl     RpcEndExcept;
799518c3f39cSEric Kohl 
799618c3f39cSEric Kohl     return ret;
799718c3f39cSEric Kohl }
799818c3f39cSEric Kohl 
7999c2c66affSColin Finck 
8000c2c66affSColin Finck /***********************************************************************
8001c2c66affSColin Finck  * CM_Set_DevNode_Problem [SETUPAPI.@]
8002c2c66affSColin Finck  */
800360a21894SEric Kohl CONFIGRET
800460a21894SEric Kohl WINAPI
800560a21894SEric Kohl CM_Set_DevNode_Problem(
800660a21894SEric Kohl     _In_ DEVINST dnDevInst,
800760a21894SEric Kohl     _In_ ULONG ulProblem,
800860a21894SEric Kohl     _In_ ULONG ulFlags)
8009c2c66affSColin Finck {
801060a21894SEric Kohl     TRACE("CM_Set_DevNode_Problem(%lx %lx %lx)\n",
801160a21894SEric Kohl           dnDevInst, ulProblem, ulFlags);
801260a21894SEric Kohl 
8013c2c66affSColin Finck     return CM_Set_DevNode_Problem_Ex(dnDevInst, ulProblem, ulFlags, NULL);
8014c2c66affSColin Finck }
8015c2c66affSColin Finck 
8016c2c66affSColin Finck 
8017c2c66affSColin Finck /***********************************************************************
8018c2c66affSColin Finck  * CM_Set_DevNode_Problem_Ex [SETUPAPI.@]
8019c2c66affSColin Finck  */
802060a21894SEric Kohl CONFIGRET
802160a21894SEric Kohl WINAPI
802260a21894SEric Kohl CM_Set_DevNode_Problem_Ex(
802360a21894SEric Kohl     _In_ DEVINST dnDevInst,
802460a21894SEric Kohl     _In_ ULONG ulProblem,
802560a21894SEric Kohl     _In_ ULONG ulFlags,
802660a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
8027c2c66affSColin Finck {
8028c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
8029c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
8030c2c66affSColin Finck     LPWSTR lpDevInst;
8031c2c66affSColin Finck     CONFIGRET ret;
8032c2c66affSColin Finck 
803360a21894SEric Kohl     TRACE("CM_Set_DevNode_Problem_Ex(%lx %lx %lx %p)\n",
803460a21894SEric Kohl           dnDevInst, ulProblem, ulFlags, hMachine);
8035c2c66affSColin Finck 
8036c2c66affSColin Finck     if (dnDevInst == 0)
8037c2c66affSColin Finck         return CR_INVALID_DEVNODE;
8038c2c66affSColin Finck 
8039c2c66affSColin Finck     if (ulFlags & ~CM_SET_DEVNODE_PROBLEM_BITS)
8040c2c66affSColin Finck         return CR_INVALID_FLAG;
8041c2c66affSColin Finck 
8042c2c66affSColin Finck     if (hMachine != NULL)
8043c2c66affSColin Finck     {
8044c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
8045c2c66affSColin Finck         if (BindingHandle == NULL)
8046c2c66affSColin Finck             return CR_FAILURE;
8047c2c66affSColin Finck 
8048c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
8049c2c66affSColin Finck         if (StringTable == 0)
8050c2c66affSColin Finck             return CR_FAILURE;
8051c2c66affSColin Finck     }
8052c2c66affSColin Finck     else
8053c2c66affSColin Finck     {
8054c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
8055c2c66affSColin Finck             return CR_FAILURE;
8056c2c66affSColin Finck     }
8057c2c66affSColin Finck 
8058c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
8059c2c66affSColin Finck     if (lpDevInst == NULL)
8060c2c66affSColin Finck         return CR_INVALID_DEVNODE;
8061c2c66affSColin Finck 
8062c2c66affSColin Finck     RpcTryExcept
8063c2c66affSColin Finck     {
8064c2c66affSColin Finck         ret = PNP_SetDeviceProblem(BindingHandle,
8065c2c66affSColin Finck                                    lpDevInst,
8066c2c66affSColin Finck                                    ulProblem,
8067c2c66affSColin Finck                                    ulFlags);
8068c2c66affSColin Finck     }
8069c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
8070c2c66affSColin Finck     {
8071c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
8072c2c66affSColin Finck     }
8073c2c66affSColin Finck     RpcEndExcept;
8074c2c66affSColin Finck 
8075c2c66affSColin Finck     return ret;
8076c2c66affSColin Finck }
8077c2c66affSColin Finck 
8078c2c66affSColin Finck 
8079c2c66affSColin Finck /***********************************************************************
8080c2c66affSColin Finck  * CM_Set_DevNode_Registry_PropertyA [SETUPAPI.@]
8081c2c66affSColin Finck  */
808260a21894SEric Kohl CONFIGRET
808360a21894SEric Kohl WINAPI
808460a21894SEric Kohl CM_Set_DevNode_Registry_PropertyA(
808560a21894SEric Kohl   _In_ DEVINST dnDevInst,
808660a21894SEric Kohl   _In_ ULONG ulProperty,
808760a21894SEric Kohl   _In_reads_bytes_opt_(ulLength) PCVOID Buffer,
808860a21894SEric Kohl   _In_ ULONG ulLength,
808960a21894SEric Kohl   _In_ ULONG ulFlags)
8090c2c66affSColin Finck {
809160a21894SEric Kohl     TRACE("CM_Set_DevNode_Registry_PropertyA(%lx %lu %p %lx %lx)\n",
8092c2c66affSColin Finck           dnDevInst, ulProperty, Buffer, ulLength, ulFlags);
809360a21894SEric Kohl 
8094c2c66affSColin Finck     return CM_Set_DevNode_Registry_Property_ExA(dnDevInst, ulProperty,
8095c2c66affSColin Finck                                                 Buffer, ulLength,
8096c2c66affSColin Finck                                                 ulFlags, NULL);
8097c2c66affSColin Finck }
8098c2c66affSColin Finck 
8099c2c66affSColin Finck 
8100c2c66affSColin Finck /***********************************************************************
8101c2c66affSColin Finck  * CM_Set_DevNode_Registry_PropertyW [SETUPAPI.@]
8102c2c66affSColin Finck  */
810360a21894SEric Kohl CONFIGRET
810460a21894SEric Kohl WINAPI
810560a21894SEric Kohl CM_Set_DevNode_Registry_PropertyW(
810660a21894SEric Kohl     _In_ DEVINST dnDevInst,
810760a21894SEric Kohl     _In_ ULONG ulProperty,
810860a21894SEric Kohl     _In_reads_bytes_opt_(ulLength) PCVOID Buffer,
810960a21894SEric Kohl     _In_ ULONG ulLength,
811060a21894SEric Kohl     _In_ ULONG ulFlags)
8111c2c66affSColin Finck {
811260a21894SEric Kohl     TRACE("CM_Set_DevNode_Registry_PropertyW(%lx %lu %p %lx %lx)\n",
8113c2c66affSColin Finck           dnDevInst, ulProperty, Buffer, ulLength, ulFlags);
811460a21894SEric Kohl 
8115c2c66affSColin Finck     return CM_Set_DevNode_Registry_Property_ExW(dnDevInst, ulProperty,
8116c2c66affSColin Finck                                                 Buffer, ulLength,
8117c2c66affSColin Finck                                                 ulFlags, NULL);
8118c2c66affSColin Finck }
8119c2c66affSColin Finck 
8120c2c66affSColin Finck 
8121c2c66affSColin Finck /***********************************************************************
8122c2c66affSColin Finck  * CM_Set_DevNode_Registry_Property_ExA [SETUPAPI.@]
8123c2c66affSColin Finck  */
812460a21894SEric Kohl CONFIGRET
812560a21894SEric Kohl WINAPI
812660a21894SEric Kohl CM_Set_DevNode_Registry_Property_ExA(
812760a21894SEric Kohl     _In_ DEVINST dnDevInst,
812860a21894SEric Kohl     _In_ ULONG ulProperty,
812960a21894SEric Kohl     _In_reads_bytes_opt_(ulLength) PCVOID Buffer,
813060a21894SEric Kohl     _In_ ULONG ulLength,
813160a21894SEric Kohl     _In_ ULONG ulFlags,
813260a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
8133c2c66affSColin Finck {
8134c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
8135c2c66affSColin Finck     LPWSTR lpBuffer;
8136c2c66affSColin Finck     ULONG ulType;
8137c2c66affSColin Finck 
813860a21894SEric Kohl     FIXME("CM_Set_DevNode_Registry_Property_ExA(%lx %lu %p %lx %lx %p)\n",
8139c2c66affSColin Finck           dnDevInst, ulProperty, Buffer, ulLength, ulFlags, hMachine);
8140c2c66affSColin Finck 
8141c2c66affSColin Finck     if (Buffer == NULL && ulLength != 0)
8142c2c66affSColin Finck         return CR_INVALID_POINTER;
8143c2c66affSColin Finck 
8144c2c66affSColin Finck     if (ulProperty < CM_DRP_MIN || ulProperty > CM_DRP_MAX)
8145c2c66affSColin Finck         return CR_INVALID_PROPERTY;
8146c2c66affSColin Finck 
8147c2c66affSColin Finck     if (Buffer == NULL)
8148c2c66affSColin Finck     {
8149c2c66affSColin Finck         ret = CM_Set_DevNode_Registry_Property_ExW(dnDevInst,
8150c2c66affSColin Finck                                                    ulProperty,
8151c2c66affSColin Finck                                                    NULL,
8152c2c66affSColin Finck                                                    0,
8153c2c66affSColin Finck                                                    ulFlags,
8154c2c66affSColin Finck                                                    hMachine);
8155c2c66affSColin Finck     }
8156c2c66affSColin Finck     else
8157c2c66affSColin Finck     {
8158c2c66affSColin Finck         /* Get property type */
8159c2c66affSColin Finck         ulType = GetRegistryPropertyType(ulProperty);
8160c2c66affSColin Finck 
8161c2c66affSColin Finck         /* Allocate buffer if needed */
8162c2c66affSColin Finck         if (ulType == REG_SZ ||
8163c2c66affSColin Finck             ulType == REG_MULTI_SZ)
8164c2c66affSColin Finck         {
8165c2c66affSColin Finck             lpBuffer = MyMalloc(ulLength * sizeof(WCHAR));
8166c2c66affSColin Finck             if (lpBuffer == NULL)
8167c2c66affSColin Finck             {
8168c2c66affSColin Finck                 ret = CR_OUT_OF_MEMORY;
8169c2c66affSColin Finck             }
8170c2c66affSColin Finck             else
8171c2c66affSColin Finck             {
8172c2c66affSColin Finck                 if (!MultiByteToWideChar(CP_ACP, 0, Buffer,
8173c2c66affSColin Finck                                          ulLength, lpBuffer, ulLength))
8174c2c66affSColin Finck                 {
8175c2c66affSColin Finck                     MyFree(lpBuffer);
8176c2c66affSColin Finck                     ret = CR_FAILURE;
8177c2c66affSColin Finck                 }
8178c2c66affSColin Finck                 else
8179c2c66affSColin Finck                 {
8180c2c66affSColin Finck                     ret = CM_Set_DevNode_Registry_Property_ExW(dnDevInst,
8181c2c66affSColin Finck                                                                ulProperty,
8182c2c66affSColin Finck                                                                lpBuffer,
8183c2c66affSColin Finck                                                                ulLength * sizeof(WCHAR),
8184c2c66affSColin Finck                                                                ulFlags,
8185c2c66affSColin Finck                                                                hMachine);
8186c2c66affSColin Finck                     MyFree(lpBuffer);
8187c2c66affSColin Finck                 }
8188c2c66affSColin Finck             }
8189c2c66affSColin Finck         }
8190c2c66affSColin Finck         else
8191c2c66affSColin Finck         {
8192c2c66affSColin Finck             ret = CM_Set_DevNode_Registry_Property_ExW(dnDevInst,
8193c2c66affSColin Finck                                                        ulProperty,
8194c2c66affSColin Finck                                                        Buffer,
8195c2c66affSColin Finck                                                        ulLength,
8196c2c66affSColin Finck                                                        ulFlags,
8197c2c66affSColin Finck                                                        hMachine);
8198c2c66affSColin Finck         }
8199c2c66affSColin Finck 
8200c2c66affSColin Finck         ret = CR_CALL_NOT_IMPLEMENTED;
8201c2c66affSColin Finck     }
8202c2c66affSColin Finck 
8203c2c66affSColin Finck     return ret;
8204c2c66affSColin Finck }
8205c2c66affSColin Finck 
8206c2c66affSColin Finck 
8207c2c66affSColin Finck /***********************************************************************
8208c2c66affSColin Finck  * CM_Set_DevNode_Registry_Property_ExW [SETUPAPI.@]
8209c2c66affSColin Finck  */
821060a21894SEric Kohl CONFIGRET
821160a21894SEric Kohl WINAPI
821260a21894SEric Kohl CM_Set_DevNode_Registry_Property_ExW(
821360a21894SEric Kohl     _In_ DEVINST dnDevInst,
821460a21894SEric Kohl     _In_ ULONG ulProperty,
821560a21894SEric Kohl     _In_reads_bytes_opt_(ulLength) PCVOID Buffer,
821660a21894SEric Kohl     _In_ ULONG ulLength,
821760a21894SEric Kohl     _In_ ULONG ulFlags,
821860a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
8219c2c66affSColin Finck {
8220c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
8221c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
8222c2c66affSColin Finck     LPWSTR lpDevInst;
8223c2c66affSColin Finck     ULONG ulType;
8224c2c66affSColin Finck     CONFIGRET ret;
8225c2c66affSColin Finck 
822660a21894SEric Kohl     TRACE("CM_Set_DevNode_Registry_Property_ExW(%lx %lu %p %lx %lx %p)\n",
8227c2c66affSColin Finck           dnDevInst, ulProperty, Buffer, ulLength, ulFlags, hMachine);
8228c2c66affSColin Finck 
8229c2c66affSColin Finck     if (dnDevInst == 0)
8230c2c66affSColin Finck         return CR_INVALID_DEVNODE;
8231c2c66affSColin Finck 
8232c2c66affSColin Finck     if (ulProperty <  CM_DRP_MIN || ulProperty > CM_DRP_MAX)
8233c2c66affSColin Finck         return CR_INVALID_PROPERTY;
8234c2c66affSColin Finck 
8235c2c66affSColin Finck     if (Buffer != NULL && ulLength == 0)
8236c2c66affSColin Finck         return CR_INVALID_POINTER;
8237c2c66affSColin Finck 
8238c2c66affSColin Finck     if (ulFlags != 0)
8239c2c66affSColin Finck         return CR_INVALID_FLAG;
8240c2c66affSColin Finck 
8241c2c66affSColin Finck     if (hMachine != NULL)
8242c2c66affSColin Finck     {
8243c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
8244c2c66affSColin Finck         if (BindingHandle == NULL)
8245c2c66affSColin Finck             return CR_FAILURE;
8246c2c66affSColin Finck 
8247c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
8248c2c66affSColin Finck         if (StringTable == 0)
8249c2c66affSColin Finck             return CR_FAILURE;
8250c2c66affSColin Finck     }
8251c2c66affSColin Finck     else
8252c2c66affSColin Finck     {
8253c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
8254c2c66affSColin Finck             return CR_FAILURE;
8255c2c66affSColin Finck     }
8256c2c66affSColin Finck 
8257c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
8258c2c66affSColin Finck     if (lpDevInst == NULL)
8259c2c66affSColin Finck         return CR_INVALID_DEVNODE;
8260c2c66affSColin Finck 
8261c2c66affSColin Finck     /* Get property type */
8262c2c66affSColin Finck     ulType = GetRegistryPropertyType(ulProperty);
8263c2c66affSColin Finck 
8264c2c66affSColin Finck     RpcTryExcept
8265c2c66affSColin Finck     {
8266c2c66affSColin Finck         ret = PNP_SetDeviceRegProp(BindingHandle,
8267c2c66affSColin Finck                                    lpDevInst,
8268c2c66affSColin Finck                                    ulProperty,
8269c2c66affSColin Finck                                    ulType,
8270c2c66affSColin Finck                                    (BYTE *)Buffer,
8271c2c66affSColin Finck                                    ulLength,
8272c2c66affSColin Finck                                    ulFlags);
8273c2c66affSColin Finck     }
8274c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
8275c2c66affSColin Finck     {
8276c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
8277c2c66affSColin Finck     }
8278c2c66affSColin Finck     RpcEndExcept;
8279c2c66affSColin Finck 
8280c2c66affSColin Finck     return ret;
8281c2c66affSColin Finck }
8282c2c66affSColin Finck 
8283c2c66affSColin Finck 
8284c2c66affSColin Finck /***********************************************************************
8285c2c66affSColin Finck  * CM_Set_HW_Prof [SETUPAPI.@]
8286c2c66affSColin Finck  */
828760a21894SEric Kohl CONFIGRET
828860a21894SEric Kohl WINAPI
828960a21894SEric Kohl CM_Set_HW_Prof(
829060a21894SEric Kohl     _In_ ULONG ulHardwareProfile,
829160a21894SEric Kohl     _In_ ULONG ulFlags)
8292c2c66affSColin Finck {
829360a21894SEric Kohl     TRACE("CM_Set_HW_Prof(%lu %lx)\n",
829460a21894SEric Kohl           ulHardwareProfile, ulFlags);
829560a21894SEric Kohl 
8296c2c66affSColin Finck     return CM_Set_HW_Prof_Ex(ulHardwareProfile, ulFlags, NULL);
8297c2c66affSColin Finck }
8298c2c66affSColin Finck 
8299c2c66affSColin Finck 
8300c2c66affSColin Finck /***********************************************************************
8301c2c66affSColin Finck  * CM_Set_HW_Prof_Ex [SETUPAPI.@]
8302c2c66affSColin Finck  */
830360a21894SEric Kohl CONFIGRET
830460a21894SEric Kohl WINAPI
830560a21894SEric Kohl CM_Set_HW_Prof_Ex(
830660a21894SEric Kohl     _In_ ULONG ulHardwareProfile,
830760a21894SEric Kohl     _In_ ULONG ulFlags,
830860a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
8309c2c66affSColin Finck {
8310c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
8311c2c66affSColin Finck     CONFIGRET ret;
8312c2c66affSColin Finck 
831360a21894SEric Kohl     TRACE("CM_Set_HW_Prof_Ex(%lu %lx %p)\n",
831460a21894SEric Kohl           ulHardwareProfile, ulFlags, hMachine);
8315c2c66affSColin Finck 
8316c2c66affSColin Finck     if (!pSetupIsUserAdmin())
8317c2c66affSColin Finck         return CR_ACCESS_DENIED;
8318c2c66affSColin Finck 
8319c2c66affSColin Finck     if (ulFlags != 0)
8320c2c66affSColin Finck         return CR_INVALID_FLAG;
8321c2c66affSColin Finck 
8322c2c66affSColin Finck     if (hMachine != NULL)
8323c2c66affSColin Finck     {
8324c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
8325c2c66affSColin Finck         if (BindingHandle == NULL)
8326c2c66affSColin Finck             return CR_FAILURE;
8327c2c66affSColin Finck     }
8328c2c66affSColin Finck     else
8329c2c66affSColin Finck     {
8330c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
8331c2c66affSColin Finck             return CR_FAILURE;
8332c2c66affSColin Finck     }
8333c2c66affSColin Finck 
8334c2c66affSColin Finck     RpcTryExcept
8335c2c66affSColin Finck     {
8336c2c66affSColin Finck         ret = PNP_SetHwProf(BindingHandle, ulHardwareProfile, ulFlags);
8337c2c66affSColin Finck     }
8338c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
8339c2c66affSColin Finck     {
8340c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
8341c2c66affSColin Finck     }
8342c2c66affSColin Finck     RpcEndExcept;
8343c2c66affSColin Finck 
8344c2c66affSColin Finck     return ret;
8345c2c66affSColin Finck }
8346c2c66affSColin Finck 
8347c2c66affSColin Finck 
8348c2c66affSColin Finck /***********************************************************************
8349c2c66affSColin Finck  * CM_Set_HW_Prof_FlagsA [SETUPAPI.@]
8350c2c66affSColin Finck  */
835160a21894SEric Kohl CONFIGRET
835260a21894SEric Kohl WINAPI
835360a21894SEric Kohl CM_Set_HW_Prof_FlagsA(
835460a21894SEric Kohl     _In_ DEVINSTID_A szDevInstName,
835560a21894SEric Kohl     _In_ ULONG ulConfig,
835660a21894SEric Kohl     _In_ ULONG ulValue,
835760a21894SEric Kohl     _In_ ULONG ulFlags)
8358c2c66affSColin Finck {
835960a21894SEric Kohl     TRACE("CM_Set_HW_Prof_FlagsA(%s %lu %lu %lx)\n",
836060a21894SEric Kohl           debugstr_a(szDevInstName), ulConfig, ulValue, ulFlags);
836160a21894SEric Kohl 
8362c2c66affSColin Finck     return CM_Set_HW_Prof_Flags_ExA(szDevInstName, ulConfig, ulValue,
8363c2c66affSColin Finck                                     ulFlags, NULL);
8364c2c66affSColin Finck }
8365c2c66affSColin Finck 
8366c2c66affSColin Finck 
8367c2c66affSColin Finck /***********************************************************************
8368c2c66affSColin Finck  * CM_Set_HW_Prof_FlagsW [SETUPAPI.@]
8369c2c66affSColin Finck  */
837060a21894SEric Kohl CONFIGRET
837160a21894SEric Kohl WINAPI
837260a21894SEric Kohl CM_Set_HW_Prof_FlagsW(
837360a21894SEric Kohl     _In_ DEVINSTID_W szDevInstName,
837460a21894SEric Kohl     _In_ ULONG ulConfig,
837560a21894SEric Kohl     _In_ ULONG ulValue,
837660a21894SEric Kohl     _In_ ULONG ulFlags)
8377c2c66affSColin Finck {
837860a21894SEric Kohl     TRACE("CM_Set_HW_Prof_FlagsW(%s %lu %lu %lx)\n",
837960a21894SEric Kohl           debugstr_w(szDevInstName), ulConfig, ulValue, ulFlags);
838060a21894SEric Kohl 
8381c2c66affSColin Finck     return CM_Set_HW_Prof_Flags_ExW(szDevInstName, ulConfig, ulValue,
8382c2c66affSColin Finck                                     ulFlags, NULL);
8383c2c66affSColin Finck }
8384c2c66affSColin Finck 
8385c2c66affSColin Finck 
8386c2c66affSColin Finck /***********************************************************************
8387c2c66affSColin Finck  * CM_Set_HW_Prof_Flags_ExA [SETUPAPI.@]
8388c2c66affSColin Finck  */
838960a21894SEric Kohl CONFIGRET
839060a21894SEric Kohl WINAPI
839160a21894SEric Kohl CM_Set_HW_Prof_Flags_ExA(
839260a21894SEric Kohl     _In_ DEVINSTID_A szDevInstName,
839360a21894SEric Kohl     _In_ ULONG ulConfig,
839460a21894SEric Kohl     _In_ ULONG ulValue,
839560a21894SEric Kohl     _In_ ULONG ulFlags,
839660a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
8397c2c66affSColin Finck {
8398c2c66affSColin Finck     DEVINSTID_W pszDevIdW = NULL;
8399c2c66affSColin Finck     CONFIGRET ret = CR_SUCCESS;
8400c2c66affSColin Finck 
840160a21894SEric Kohl     TRACE("CM_Set_HW_Prof_Flags_ExA(%s %lu %lu %lx %p)\n",
840260a21894SEric Kohl           debugstr_a(szDevInstName), ulConfig, ulValue, ulFlags, hMachine);
8403c2c66affSColin Finck 
8404c2c66affSColin Finck     if (szDevInstName != NULL)
8405c2c66affSColin Finck     {
8406c2c66affSColin Finck        if (pSetupCaptureAndConvertAnsiArg(szDevInstName, &pszDevIdW))
8407c2c66affSColin Finck          return CR_INVALID_DEVICE_ID;
8408c2c66affSColin Finck     }
8409c2c66affSColin Finck 
8410c2c66affSColin Finck     ret = CM_Set_HW_Prof_Flags_ExW(pszDevIdW, ulConfig, ulValue,
8411c2c66affSColin Finck                                    ulFlags, hMachine);
8412c2c66affSColin Finck 
8413c2c66affSColin Finck     if (pszDevIdW != NULL)
8414c2c66affSColin Finck         MyFree(pszDevIdW);
8415c2c66affSColin Finck 
8416c2c66affSColin Finck     return ret;
8417c2c66affSColin Finck }
8418c2c66affSColin Finck 
8419c2c66affSColin Finck 
8420c2c66affSColin Finck /***********************************************************************
8421c2c66affSColin Finck  * CM_Set_HW_Prof_Flags_ExW [SETUPAPI.@]
8422c2c66affSColin Finck  */
842360a21894SEric Kohl CONFIGRET
842460a21894SEric Kohl WINAPI
842560a21894SEric Kohl CM_Set_HW_Prof_Flags_ExW(
842660a21894SEric Kohl     _In_ DEVINSTID_W szDevInstName,
842760a21894SEric Kohl     _In_ ULONG ulConfig,
842860a21894SEric Kohl     _In_ ULONG ulValue,
842960a21894SEric Kohl     _In_ ULONG ulFlags,
843060a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
8431c2c66affSColin Finck {
8432c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
8433c2c66affSColin Finck     CONFIGRET ret;
8434c2c66affSColin Finck 
843560a21894SEric Kohl     FIXME("CM_Set_HW_Prof_Flags_ExW(%s %lu %lu %lx %p)\n",
843660a21894SEric Kohl           debugstr_w(szDevInstName), ulConfig, ulValue, ulFlags, hMachine);
8437c2c66affSColin Finck 
8438c2c66affSColin Finck     if (szDevInstName == NULL)
8439c2c66affSColin Finck         return CR_INVALID_POINTER;
8440c2c66affSColin Finck 
8441c2c66affSColin Finck     if (ulFlags & ~ CM_SET_HW_PROF_FLAGS_BITS)
8442c2c66affSColin Finck         return CR_INVALID_FLAG;
8443c2c66affSColin Finck 
8444c2c66affSColin Finck     /* FIXME: Check whether szDevInstName is valid */
8445c2c66affSColin Finck 
8446c2c66affSColin Finck     if (hMachine != NULL)
8447c2c66affSColin Finck     {
8448c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
8449c2c66affSColin Finck         if (BindingHandle == NULL)
8450c2c66affSColin Finck             return CR_FAILURE;
8451c2c66affSColin Finck     }
8452c2c66affSColin Finck     else
8453c2c66affSColin Finck     {
8454c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
8455c2c66affSColin Finck             return CR_FAILURE;
8456c2c66affSColin Finck     }
8457c2c66affSColin Finck 
8458c2c66affSColin Finck     RpcTryExcept
8459c2c66affSColin Finck     {
8460c2c66affSColin Finck         ret = PNP_HwProfFlags(BindingHandle, PNP_SET_HWPROFFLAGS, szDevInstName,
8461c2c66affSColin Finck                               ulConfig, &ulValue, NULL, NULL, 0, 0);
8462c2c66affSColin Finck     }
8463c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
8464c2c66affSColin Finck     {
8465c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
8466c2c66affSColin Finck     }
8467c2c66affSColin Finck     RpcEndExcept;
8468c2c66affSColin Finck 
8469c2c66affSColin Finck     return ret;
8470c2c66affSColin Finck }
8471c2c66affSColin Finck 
8472c2c66affSColin Finck 
8473c2c66affSColin Finck /***********************************************************************
8474c2c66affSColin Finck  * CM_Setup_DevNode [SETUPAPI.@]
8475c2c66affSColin Finck  */
847660a21894SEric Kohl CONFIGRET
847760a21894SEric Kohl WINAPI
847860a21894SEric Kohl CM_Setup_DevNode(
847960a21894SEric Kohl     _In_ DEVINST dnDevInst,
848060a21894SEric Kohl     _In_ ULONG ulFlags)
8481c2c66affSColin Finck {
848260a21894SEric Kohl     TRACE("CM_Setup_DevNode(%lx %lx)\n",
848360a21894SEric Kohl           dnDevInst, ulFlags);
848460a21894SEric Kohl 
8485c2c66affSColin Finck     return CM_Setup_DevNode_Ex(dnDevInst, ulFlags, NULL);
8486c2c66affSColin Finck }
8487c2c66affSColin Finck 
8488c2c66affSColin Finck 
8489c2c66affSColin Finck /***********************************************************************
8490c2c66affSColin Finck  * CM_Setup_DevNode_Ex [SETUPAPI.@]
8491c2c66affSColin Finck  */
849260a21894SEric Kohl CONFIGRET
849360a21894SEric Kohl WINAPI
849460a21894SEric Kohl CM_Setup_DevNode_Ex(
849560a21894SEric Kohl     _In_ DEVINST dnDevInst,
849660a21894SEric Kohl     _In_ ULONG ulFlags,
849760a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
8498c2c66affSColin Finck {
8499c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
8500c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
8501c2c66affSColin Finck     LPWSTR lpDevInst;
8502c2c66affSColin Finck     CONFIGRET ret;
8503c2c66affSColin Finck 
850460a21894SEric Kohl     FIXME("CM_Setup_DevNode_Ex(%lx %lx %p)\n",
850560a21894SEric Kohl           dnDevInst, ulFlags, hMachine);
8506c2c66affSColin Finck 
8507c2c66affSColin Finck     if (!pSetupIsUserAdmin())
8508c2c66affSColin Finck         return CR_ACCESS_DENIED;
8509c2c66affSColin Finck 
8510c2c66affSColin Finck     if (dnDevInst == 0)
8511c2c66affSColin Finck         return CR_INVALID_DEVNODE;
8512c2c66affSColin Finck 
8513c2c66affSColin Finck     if (ulFlags & ~CM_SETUP_BITS)
8514c2c66affSColin Finck         return CR_INVALID_FLAG;
8515c2c66affSColin Finck 
8516c2c66affSColin Finck     if (hMachine != NULL)
8517c2c66affSColin Finck     {
8518c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
8519c2c66affSColin Finck         if (BindingHandle == NULL)
8520c2c66affSColin Finck             return CR_FAILURE;
8521c2c66affSColin Finck 
8522c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
8523c2c66affSColin Finck         if (StringTable == 0)
8524c2c66affSColin Finck             return CR_FAILURE;
8525c2c66affSColin Finck     }
8526c2c66affSColin Finck     else
8527c2c66affSColin Finck     {
8528c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
8529c2c66affSColin Finck             return CR_FAILURE;
8530c2c66affSColin Finck     }
8531c2c66affSColin Finck 
8532c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
8533c2c66affSColin Finck     if (lpDevInst == NULL)
8534c2c66affSColin Finck         return CR_INVALID_DEVNODE;
8535c2c66affSColin Finck 
8536c2c66affSColin Finck     RpcTryExcept
8537c2c66affSColin Finck     {
8538c2c66affSColin Finck         ret = PNP_DeviceInstanceAction(BindingHandle,
8539c2c66affSColin Finck                                        PNP_DEVINST_SETUP,
8540c2c66affSColin Finck                                        ulFlags,
8541c2c66affSColin Finck                                        lpDevInst,
8542c2c66affSColin Finck                                        NULL);
8543c2c66affSColin Finck     }
8544c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
8545c2c66affSColin Finck     {
8546c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
8547c2c66affSColin Finck     }
8548c2c66affSColin Finck     RpcEndExcept;
8549c2c66affSColin Finck 
8550c2c66affSColin Finck     return ret;
8551c2c66affSColin Finck }
8552c2c66affSColin Finck 
8553c2c66affSColin Finck 
8554c2c66affSColin Finck /***********************************************************************
8555c2c66affSColin Finck  * CM_Test_Range_Available [SETUPAPI.@]
8556c2c66affSColin Finck  */
8557c2c66affSColin Finck CONFIGRET
8558c2c66affSColin Finck WINAPI
8559c2c66affSColin Finck CM_Test_Range_Available(
8560c2c66affSColin Finck     _In_ DWORDLONG ullStartValue,
8561c2c66affSColin Finck     _In_ DWORDLONG ullEndValue,
8562c2c66affSColin Finck     _In_ RANGE_LIST rlh,
8563c2c66affSColin Finck     _In_ ULONG ulFlags)
8564c2c66affSColin Finck {
8565f24fbb65SEric Kohl     PINTERNAL_RANGE_LIST pRangeList;
8566f24fbb65SEric Kohl     PINTERNAL_RANGE pRange;
8567f24fbb65SEric Kohl     PLIST_ENTRY ListEntry;
8568f24fbb65SEric Kohl     CONFIGRET ret = CR_SUCCESS;
8569f24fbb65SEric Kohl 
8570c2c66affSColin Finck     FIXME("CM_Test_Range_Available(%I64u %I64u %p %lx)\n",
8571c2c66affSColin Finck           ullStartValue, ullEndValue, rlh, ulFlags);
8572f24fbb65SEric Kohl 
8573f24fbb65SEric Kohl     pRangeList = (PINTERNAL_RANGE_LIST)rlh;
8574f24fbb65SEric Kohl 
8575f24fbb65SEric Kohl     if (!IsValidRangeList(pRangeList))
8576f24fbb65SEric Kohl         return CR_INVALID_RANGE_LIST;
8577f24fbb65SEric Kohl 
8578f24fbb65SEric Kohl     if (ulFlags != 0)
8579f24fbb65SEric Kohl         return CR_INVALID_FLAG;
8580f24fbb65SEric Kohl 
8581f24fbb65SEric Kohl     if (ullStartValue > ullEndValue)
8582f24fbb65SEric Kohl         return CR_INVALID_RANGE;
8583f24fbb65SEric Kohl 
8584f24fbb65SEric Kohl     /* Lock the range list */
8585f24fbb65SEric Kohl     WaitForSingleObject(pRangeList->hMutex, INFINITE);
8586f24fbb65SEric Kohl 
8587f24fbb65SEric Kohl     /* Check the ranges */
8588f24fbb65SEric Kohl     ListEntry = &pRangeList->ListHead;
8589f24fbb65SEric Kohl     while (ListEntry->Flink == &pRangeList->ListHead)
8590f24fbb65SEric Kohl     {
8591f24fbb65SEric Kohl         pRange = CONTAINING_RECORD(ListEntry, INTERNAL_RANGE, ListEntry);
8592f24fbb65SEric Kohl 
8593f24fbb65SEric Kohl         /* Check if the start value is within the current range */
8594f24fbb65SEric Kohl         if ((ullStartValue >= pRange->ullStart) && (ullStartValue <= pRange->ullEnd))
8595f24fbb65SEric Kohl         {
8596f24fbb65SEric Kohl             ret = CR_FAILURE;
8597f24fbb65SEric Kohl             break;
8598f24fbb65SEric Kohl         }
8599f24fbb65SEric Kohl 
8600f24fbb65SEric Kohl         /* Check if the end value is within the current range */
8601f24fbb65SEric Kohl         if ((ullEndValue >= pRange->ullStart) && (ullEndValue <= pRange->ullEnd))
8602f24fbb65SEric Kohl         {
8603f24fbb65SEric Kohl             ret = CR_FAILURE;
8604f24fbb65SEric Kohl             break;
8605f24fbb65SEric Kohl         }
8606f24fbb65SEric Kohl 
8607f24fbb65SEric Kohl         /* Check if the current range lies inside of the start-end interval */
8608f24fbb65SEric Kohl         if ((ullStartValue <= pRange->ullStart) && (ullEndValue >= pRange->ullEnd))
8609f24fbb65SEric Kohl         {
8610f24fbb65SEric Kohl             ret = CR_FAILURE;
8611f24fbb65SEric Kohl             break;
8612f24fbb65SEric Kohl         }
8613f24fbb65SEric Kohl 
8614f24fbb65SEric Kohl         ListEntry = ListEntry->Flink;
8615f24fbb65SEric Kohl     }
8616f24fbb65SEric Kohl 
8617f24fbb65SEric Kohl     /* Unlock the range list */
8618f24fbb65SEric Kohl     ReleaseMutex(pRangeList->hMutex);
8619f24fbb65SEric Kohl 
8620f24fbb65SEric Kohl     return ret;
8621c2c66affSColin Finck }
8622c2c66affSColin Finck 
8623c2c66affSColin Finck 
8624c2c66affSColin Finck /***********************************************************************
8625c2c66affSColin Finck  * CM_Uninstall_DevNode [SETUPAPI.@]
8626c2c66affSColin Finck  */
862760a21894SEric Kohl CONFIGRET
862860a21894SEric Kohl WINAPI
862960a21894SEric Kohl CM_Uninstall_DevNode(
863060a21894SEric Kohl     _In_ DEVINST dnPhantom,
863160a21894SEric Kohl     _In_ ULONG ulFlags)
8632c2c66affSColin Finck {
863360a21894SEric Kohl     TRACE("CM_Uninstall_DevNode(%lx %lx)\n",
863460a21894SEric Kohl           dnPhantom, ulFlags);
863560a21894SEric Kohl 
8636c2c66affSColin Finck     return CM_Uninstall_DevNode_Ex(dnPhantom, ulFlags, NULL);
8637c2c66affSColin Finck }
8638c2c66affSColin Finck 
8639c2c66affSColin Finck 
8640c2c66affSColin Finck /***********************************************************************
8641c2c66affSColin Finck  * CM_Uninstall_DevNode_Ex [SETUPAPI.@]
8642c2c66affSColin Finck  */
864360a21894SEric Kohl CONFIGRET
864460a21894SEric Kohl WINAPI
864560a21894SEric Kohl CM_Uninstall_DevNode_Ex(
864660a21894SEric Kohl     _In_ DEVINST dnPhantom,
864760a21894SEric Kohl     _In_ ULONG ulFlags,
864860a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
8649c2c66affSColin Finck {
8650c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
8651c2c66affSColin Finck     HSTRING_TABLE StringTable = NULL;
8652c2c66affSColin Finck     LPWSTR lpDevInst;
8653c2c66affSColin Finck     CONFIGRET ret;
8654c2c66affSColin Finck 
865560a21894SEric Kohl     TRACE("CM_Uninstall_DevNode_Ex(%lx %lx %p)\n",
865660a21894SEric Kohl           dnPhantom, ulFlags, hMachine);
8657c2c66affSColin Finck 
8658c2c66affSColin Finck     if (dnPhantom == 0)
8659c2c66affSColin Finck         return CR_INVALID_DEVNODE;
8660c2c66affSColin Finck 
8661c2c66affSColin Finck     if (ulFlags != 0)
8662c2c66affSColin Finck         return CR_INVALID_FLAG;
8663c2c66affSColin Finck 
8664c2c66affSColin Finck     if (hMachine != NULL)
8665c2c66affSColin Finck     {
8666c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
8667c2c66affSColin Finck         if (BindingHandle == NULL)
8668c2c66affSColin Finck             return CR_FAILURE;
8669c2c66affSColin Finck 
8670c2c66affSColin Finck         StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
8671c2c66affSColin Finck         if (StringTable == 0)
8672c2c66affSColin Finck             return CR_FAILURE;
8673c2c66affSColin Finck     }
8674c2c66affSColin Finck     else
8675c2c66affSColin Finck     {
8676c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
8677c2c66affSColin Finck             return CR_FAILURE;
8678c2c66affSColin Finck     }
8679c2c66affSColin Finck 
8680c2c66affSColin Finck     lpDevInst = pSetupStringTableStringFromId(StringTable, dnPhantom);
8681c2c66affSColin Finck     if (lpDevInst == NULL)
8682c2c66affSColin Finck         return CR_INVALID_DEVNODE;
8683c2c66affSColin Finck 
8684c2c66affSColin Finck     RpcTryExcept
8685c2c66affSColin Finck     {
8686c2c66affSColin Finck         ret = PNP_UninstallDevInst(BindingHandle,
8687c2c66affSColin Finck                                    lpDevInst,
8688c2c66affSColin Finck                                    ulFlags);
8689c2c66affSColin Finck     }
8690c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
8691c2c66affSColin Finck     {
8692c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
8693c2c66affSColin Finck     }
8694c2c66affSColin Finck     RpcEndExcept;
8695c2c66affSColin Finck 
8696c2c66affSColin Finck     return ret;
8697c2c66affSColin Finck }
8698c2c66affSColin Finck 
8699c2c66affSColin Finck 
8700c2c66affSColin Finck /***********************************************************************
8701c2c66affSColin Finck  * CM_Unregister_Device_InterfaceA [SETUPAPI.@]
8702c2c66affSColin Finck  */
870360a21894SEric Kohl CONFIGRET
870460a21894SEric Kohl WINAPI
870560a21894SEric Kohl CM_Unregister_Device_InterfaceA(
870660a21894SEric Kohl     _In_ LPCSTR pszDeviceInterface,
870760a21894SEric Kohl     _In_ ULONG ulFlags)
8708c2c66affSColin Finck {
870960a21894SEric Kohl     TRACE("CM_Unregister_Device_InterfaceA(%s %lx)\n",
871060a21894SEric Kohl           debugstr_a(pszDeviceInterface), ulFlags);
8711c2c66affSColin Finck 
8712c2c66affSColin Finck     return CM_Unregister_Device_Interface_ExA(pszDeviceInterface,
8713c2c66affSColin Finck                                               ulFlags, NULL);
8714c2c66affSColin Finck }
8715c2c66affSColin Finck 
8716c2c66affSColin Finck 
8717c2c66affSColin Finck /***********************************************************************
8718c2c66affSColin Finck  * CM_Unregister_Device_InterfaceW [SETUPAPI.@]
8719c2c66affSColin Finck  */
872060a21894SEric Kohl CONFIGRET
872160a21894SEric Kohl WINAPI
872260a21894SEric Kohl CM_Unregister_Device_InterfaceW(
872360a21894SEric Kohl     _In_ LPCWSTR pszDeviceInterface,
872460a21894SEric Kohl     _In_ ULONG ulFlags)
8725c2c66affSColin Finck {
872660a21894SEric Kohl     TRACE("CM_Unregister_Device_InterfaceW(%s %lx)\n",
872760a21894SEric Kohl           debugstr_w(pszDeviceInterface), ulFlags);
8728c2c66affSColin Finck 
8729c2c66affSColin Finck     return CM_Unregister_Device_Interface_ExW(pszDeviceInterface,
8730c2c66affSColin Finck                                               ulFlags, NULL);
8731c2c66affSColin Finck }
8732c2c66affSColin Finck 
8733c2c66affSColin Finck 
8734c2c66affSColin Finck /***********************************************************************
8735c2c66affSColin Finck  * CM_Unregister_Device_Interface_ExA [SETUPAPI.@]
8736c2c66affSColin Finck  */
873760a21894SEric Kohl CONFIGRET
873860a21894SEric Kohl WINAPI
873960a21894SEric Kohl CM_Unregister_Device_Interface_ExA(
874060a21894SEric Kohl     _In_ LPCSTR pszDeviceInterface,
874160a21894SEric Kohl     _In_ ULONG ulFlags,
874260a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
8743c2c66affSColin Finck {
8744c2c66affSColin Finck     LPWSTR pszDeviceInterfaceW = NULL;
8745c2c66affSColin Finck     CONFIGRET ret;
8746c2c66affSColin Finck 
874760a21894SEric Kohl     TRACE("CM_Unregister_Device_Interface_ExA(%s %lx %p)\n",
874860a21894SEric Kohl           debugstr_a(pszDeviceInterface), ulFlags, hMachine);
8749c2c66affSColin Finck 
8750c2c66affSColin Finck     if (pszDeviceInterface == NULL)
8751c2c66affSColin Finck         return CR_INVALID_POINTER;
8752c2c66affSColin Finck 
8753c2c66affSColin Finck     if (pSetupCaptureAndConvertAnsiArg(pszDeviceInterface, &pszDeviceInterfaceW))
8754c2c66affSColin Finck         return CR_INVALID_DATA;
8755c2c66affSColin Finck 
8756c2c66affSColin Finck     ret = CM_Unregister_Device_Interface_ExW(pszDeviceInterfaceW,
8757c2c66affSColin Finck                                              ulFlags, hMachine);
8758c2c66affSColin Finck 
8759c2c66affSColin Finck     if (pszDeviceInterfaceW != NULL)
8760c2c66affSColin Finck         MyFree(pszDeviceInterfaceW);
8761c2c66affSColin Finck 
8762c2c66affSColin Finck     return ret;
8763c2c66affSColin Finck }
8764c2c66affSColin Finck 
8765c2c66affSColin Finck 
8766c2c66affSColin Finck /***********************************************************************
8767c2c66affSColin Finck  * CM_Unregister_Device_Interface_ExW [SETUPAPI.@]
8768c2c66affSColin Finck  */
876960a21894SEric Kohl CONFIGRET
877060a21894SEric Kohl WINAPI
877160a21894SEric Kohl CM_Unregister_Device_Interface_ExW(
877260a21894SEric Kohl     _In_ LPCWSTR pszDeviceInterface,
877360a21894SEric Kohl     _In_ ULONG ulFlags,
877460a21894SEric Kohl     _In_opt_ HMACHINE hMachine)
8775c2c66affSColin Finck {
8776c2c66affSColin Finck     RPC_BINDING_HANDLE BindingHandle = NULL;
8777c2c66affSColin Finck     CONFIGRET ret;
8778c2c66affSColin Finck 
877960a21894SEric Kohl     TRACE("CM_Unregister_Device_Interface_ExW(%s %lx %p)\n",
878060a21894SEric Kohl           debugstr_w(pszDeviceInterface), ulFlags, hMachine);
8781c2c66affSColin Finck 
8782c2c66affSColin Finck     if (pszDeviceInterface == NULL)
8783c2c66affSColin Finck         return CR_INVALID_POINTER;
8784c2c66affSColin Finck 
8785c2c66affSColin Finck     if (ulFlags != 0)
8786c2c66affSColin Finck         return CR_INVALID_FLAG;
8787c2c66affSColin Finck 
8788c2c66affSColin Finck     if (hMachine != NULL)
8789c2c66affSColin Finck     {
8790c2c66affSColin Finck         BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
8791c2c66affSColin Finck         if (BindingHandle == NULL)
8792c2c66affSColin Finck             return CR_FAILURE;
8793c2c66affSColin Finck     }
8794c2c66affSColin Finck     else
8795c2c66affSColin Finck     {
8796c2c66affSColin Finck         if (!PnpGetLocalHandles(&BindingHandle, NULL))
8797c2c66affSColin Finck             return CR_FAILURE;
8798c2c66affSColin Finck     }
8799c2c66affSColin Finck 
8800c2c66affSColin Finck     RpcTryExcept
8801c2c66affSColin Finck     {
8802c2c66affSColin Finck         ret = PNP_UnregisterDeviceClassAssociation(BindingHandle,
8803c2c66affSColin Finck                                                    (LPWSTR)pszDeviceInterface,
8804c2c66affSColin Finck                                                    ulFlags);
8805c2c66affSColin Finck     }
8806c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
8807c2c66affSColin Finck     {
8808c2c66affSColin Finck         ret = RpcStatusToCmStatus(RpcExceptionCode());
8809c2c66affSColin Finck     }
8810c2c66affSColin Finck     RpcEndExcept;
8811c2c66affSColin Finck 
8812c2c66affSColin Finck     return ret;
8813c2c66affSColin Finck }
8814