+static
+VOID
+SplitDeviceInstanceId(
+ _In_ PWSTR pszDeviceInstanceId,
+ _Out_ PWSTR pszDeviceId,
+ _Out_ PWSTR pszInstanceId)
+{
+ PWCHAR ptr;
+
+ wcscpy(pszDeviceId, pszDeviceInstanceId);
+
+ ptr = wcschr(pszDeviceId, L'\\');
+ if (ptr != NULL)
+ {
+ *ptr = UNICODE_NULL;
+ ptr++;
+
+ wcscpy(pszInstanceId, ptr);
+ }
+ else
+ {
+ *pszInstanceId = UNICODE_NULL;
+ }
+}
+
+
+static
+CONFIGRET
+GetDeviceInstanceKeyPath(
+ _In_ RPC_BINDING_HANDLE BindingHandle,
+ _In_ PWSTR pszDeviceInst,
+ _Out_ PWSTR pszKeyPath,
+ _Out_ PWSTR pszInstancePath,
+ _In_ ULONG ulHardwareProfile,
+ _In_ ULONG ulFlags)
+{
+ PWSTR pszBuffer = NULL;
+ ULONG ulType = 0;
+ ULONG ulTransferLength, ulLength;
+ CONFIGRET ret = CR_SUCCESS;
+
+ TRACE("GetDeviceInstanceKeyPath()\n");
+
+ if (ulFlags & CM_REGISTRY_SOFTWARE)
+ {
+ /* Software Key Path */
+ ret = CR_CALL_NOT_IMPLEMENTED;
+ }
+ else
+ {
+ /* Hardware Key Path */
+
+ ulTransferLength = 300 * sizeof(WCHAR);
+ ulLength = 300 * sizeof(WCHAR);
+
+ pszBuffer = MyMalloc(ulTransferLength);
+ if (pszBuffer == NULL)
+ {
+ ERR("MyMalloc() failed\n");
+ ret = CR_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ ret = PNP_GetDeviceRegProp(BindingHandle,
+ pszDeviceInst,
+ CM_DRP_DRIVER,
+ &ulType,
+ (PVOID)pszBuffer,
+ &ulTransferLength,
+ &ulLength,
+ 0);
+ if (ret != CR_SUCCESS)
+ {
+ ERR("PNP_GetDeviceRegProp() failed (Error %lu)\n", ret);
+ goto done;
+ }
+
+ TRACE("szBuffer: %S\n", pszBuffer);
+
+ SplitDeviceInstanceId(pszBuffer,
+ pszBuffer,
+ pszInstancePath);
+
+ TRACE("szBuffer: %S\n", pszBuffer);
+
+ if (ulFlags & CM_REGISTRY_CONFIG)
+ {
+ if (ulHardwareProfile == 0)
+ {
+ wsprintfW(pszKeyPath,
+ L"%s\\%s\\%s\\%s",
+ L"System\\CurrentControlSet\\Hardware Profiles",
+ L"Current",
+ L"System\\CurrentControlSet\\Control\\Class",
+ pszBuffer);
+ }
+ else
+ {
+ wsprintfW(pszKeyPath,
+ L"%s\\%04lu\\%s\\%s",
+ L"System\\CurrentControlSet\\Hardware Profiles",
+ ulHardwareProfile,
+ L"System\\CurrentControlSet\\Control\\Class",
+ pszBuffer);
+ }
+ }
+ else
+ {
+ wsprintfW(pszKeyPath,
+ L"%s\\%s",
+ L"System\\CurrentControlSet\\Control\\Class",
+ pszBuffer);
+ }
+ }
+
+done:
+ if (pszBuffer != NULL)
+ MyFree(pszBuffer);
+
+ return ret;
+}
+
+