[MSPORTS]
[reactos.git] / reactos / dll / win32 / msports / classinst.c
index 4502d5f..1ac86bf 100644 (file)
@@ -257,8 +257,6 @@ InstallSerialPort(IN HDEVINFO DeviceInfoSet,
                                        DeviceInfoData);
     if (dwPortNumber != 0)
     {
-        swprintf(szPortName, L"COM%u", dwPortNumber);
-
         ComDBClaimPort(hComDB,
                        dwPortNumber,
                        FALSE,
@@ -266,9 +264,12 @@ InstallSerialPort(IN HDEVINFO DeviceInfoSet,
     }
     else
     {
-        wcscpy(szPortName, L"COMx");
+        ComDBClaimNextFreePort(hComDB,
+                               &dwPortNumber);
     }
 
+    swprintf(szPortName, L"COM%u", dwPortNumber);
+
     /* Close the com port database */
     if (hComDB != HCOMDB_INVALID_HANDLE_VALUE)
         ComDBClose(hComDB);