Author: cgutman
Date: Sun Aug 11 19:57:47 2013
New Revision: 59699
URL: 
http://svn.reactos.org/svn/reactos?rev=59699&view=rev
Log:
[UMPNPMGR]
- Handle the CM_CREATE_DEVNODE_GENERATE_ID flag
[SETUPAPI]
- Use the correct ID (the newly generated instance ID) when creating the device info if
the DICD_GENERATE_ID flag was passed in
Modified:
    trunk/reactos/base/services/umpnpmgr/umpnpmgr.c
    trunk/reactos/dll/win32/setupapi/cfgmgr.c
    trunk/reactos/dll/win32/setupapi/devinst.c
Modified: trunk/reactos/base/services/umpnpmgr/umpnpmgr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/umpnpmgr/ump…
==============================================================================
--- trunk/reactos/base/services/umpnpmgr/umpnpmgr.c     [iso-8859-1] (original)
+++ trunk/reactos/base/services/umpnpmgr/umpnpmgr.c     [iso-8859-1] Sun Aug 11 19:57:47
2013
@@ -1613,16 +1613,42 @@
     if (ulFlags & CM_CREATE_DEVNODE_GENERATE_ID)
     {
-        /* FIXME */
-        DPRINT1("CM_CREATE_DEVNODE_GENERATE_ID support not implemented yet!\n",
ret);
-        ret = CR_CALL_NOT_IMPLEMENTED;
-        goto done;
-    }
-
-    /* Create the device instance */
-    ret = CreateDeviceInstance(pszDeviceID);
-
-done:;
+        WCHAR szGeneratedInstance[MAX_DEVICE_ID_LEN];
+        DWORD dwInstanceNumber;
+
+        /* Generated ID is: Root\<Device ID>\<Instance number> */
+        dwInstanceNumber = 0;
+        do
+        {
+            swprintf(szGeneratedInstance, L"Root\\%ls\\%04d",
+                     pszDeviceID, dwInstanceNumber);
+
+            /* Try to create a device instance with this ID */
+            ret = CreateDeviceInstance(szGeneratedInstance);
+
+            dwInstanceNumber++;
+        }
+        while (ret == CR_ALREADY_SUCH_DEVINST);
+
+        if (ret == CR_SUCCESS)
+        {
+            /* pszDeviceID is an out parameter too for generated IDs */
+            if (wcslen(szGeneratedInstance) > ulLength)
+            {
+                ret = CR_BUFFER_SMALL;
+            }
+            else
+            {
+                wcscpy(pszDeviceID, szGeneratedInstance);
+            }
+        }
+    }
+    else
+    {
+        /* Create the device instance */
+        ret = CreateDeviceInstance(pszDeviceID);
+    }
+
     DPRINT("PNP_CreateDevInst() done (returns %lx)\n", ret);
     return ret;
Modified: trunk/reactos/dll/win32/setupapi/cfgmgr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/setupapi/cfgmgr.…
==============================================================================
--- trunk/reactos/dll/win32/setupapi/cfgmgr.c   [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/setupapi/cfgmgr.c   [iso-8859-1] Sun Aug 11 19:57:47 2013
@@ -681,7 +681,9 @@
     if (ret == CR_SUCCESS)
     {
-        *pdnDevInst = pSetupStringTableAddString(StringTable, pDeviceID, 1);
+        /* If CM_CREATE_DEVINST_GENERATE_ID was passed in, PNP_CreateDevInst
+         * will return the generated device ID in szLocalDeviceID */
+        *pdnDevInst = pSetupStringTableAddString(StringTable, szLocalDeviceID, 1);
         if (*pdnDevInst == 0)
             ret = CR_NO_SUCH_DEVNODE;
     }
Modified: trunk/reactos/dll/win32/setupapi/devinst.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/setupapi/devinst…
==============================================================================
--- trunk/reactos/dll/win32/setupapi/devinst.c  [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/setupapi/devinst.c  [iso-8859-1] Sun Aug 11 19:57:47 2013
@@ -1727,6 +1727,7 @@
     CONFIGRET cr;
     DEVINST RootDevInst;
     DEVINST DevInst;
+    WCHAR GenInstanceId[MAX_DEVICE_ID_LEN];
     TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet, debugstr_w(DeviceName),
         debugstr_guid(ClassGuid), debugstr_w(DeviceDescription),
@@ -1787,6 +1788,24 @@
     {
         SetLastError(GetErrorCodeFromCrCode(cr));
         return FALSE;
+    }
+
+    if (CreationFlags & DICD_GENERATE_ID)
+    {
+        /* Grab the actual instance ID that was created */
+        cr = CM_Get_Device_ID_Ex(DevInst,
+                                 GenInstanceId,
+                                 MAX_DEVICE_ID_LEN,
+                                 0,
+                                 set->hMachine);
+        if (cr != CR_SUCCESS)
+        {
+            SetLastError(GetErrorCodeFromCrCode(cr));
+            return FALSE;
+        }
+
+        DeviceName = GenInstanceId;
+        TRACE("Using generated instance ID: %s\n", debugstr_w(DeviceName));
     }
     if (CreateDeviceInfo(set, DeviceName, ClassGuid, &deviceInfo))