ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

classinst.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:     ReactOS system libraries
00003  * LICENSE:     GPL - See COPYING in the top level directory
00004  * FILE:        dlls\win32\msports\classinst.c
00005  * PURPOSE:     Ports class installer
00006  * PROGRAMMERS: Copyright 2011 Eric Kohl
00007  */
00008 
00009 #include "precomp.h"
00010 
00011 WINE_DEFAULT_DEBUG_CHANNEL(msports);
00012 
00013 
00014 typedef enum _PORT_TYPE
00015 {
00016     UnknownPort,
00017     ParallelPort,
00018     SerialPort
00019 } PORT_TYPE;
00020 
00021 LPWSTR pszCom = L"COM";
00022 LPWSTR pszLpt = L"LPT";
00023 
00024 
00025 BOOL
00026 GetBootResourceList(HDEVINFO DeviceInfoSet,
00027                     PSP_DEVINFO_DATA DeviceInfoData,
00028                     PCM_RESOURCE_LIST *ppResourceList)
00029 {
00030     HKEY hDeviceKey = NULL;
00031     HKEY hConfigKey = NULL;
00032     LPBYTE lpBuffer = NULL;
00033     DWORD dwDataSize;
00034     LONG lError;
00035     BOOL ret = FALSE;
00036 
00037     *ppResourceList = NULL;
00038 
00039     hDeviceKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
00040                                          DeviceInfoData,
00041                                          DICS_FLAG_GLOBAL,
00042                                          0,
00043                                          DIREG_DEV,
00044                                          NULL,
00045                                          NULL);
00046     if (!hDeviceKey)
00047         return FALSE;
00048 
00049     lError = RegOpenKeyExW(hDeviceKey,
00050                            L"LogConf",
00051                            0,
00052                            KEY_QUERY_VALUE,
00053                            &hConfigKey);
00054     if (lError != ERROR_SUCCESS)
00055         goto done;
00056 
00057     /* Get the configuration data size */
00058     lError = RegQueryValueExW(hConfigKey,
00059                               L"BootConfig",
00060                               NULL,
00061                               NULL,
00062                               NULL,
00063                               &dwDataSize);
00064     if (lError != ERROR_SUCCESS)
00065         goto done;
00066 
00067     /* Allocate the buffer */
00068     lpBuffer = HeapAlloc(GetProcessHeap(), 0, dwDataSize);
00069     if (lpBuffer == NULL)
00070         goto done;
00071 
00072     /* Retrieve the configuration data */
00073     lError = RegQueryValueExW(hConfigKey,
00074                               L"BootConfig",
00075                               NULL,
00076                               NULL,
00077                              (LPBYTE)lpBuffer,
00078                               &dwDataSize);
00079     if (lError == ERROR_SUCCESS)
00080         ret = TRUE;
00081 
00082 done:
00083     if (ret == FALSE && lpBuffer != NULL)
00084         HeapFree(GetProcessHeap(), 0, lpBuffer);
00085 
00086     if (hConfigKey)
00087         RegCloseKey(hConfigKey);
00088 
00089     if (hDeviceKey)
00090         RegCloseKey(hDeviceKey);
00091 
00092     if (ret == TRUE)
00093         *ppResourceList = (PCM_RESOURCE_LIST)lpBuffer;
00094 
00095     return ret;
00096 }
00097 
00098 
00099 DWORD
00100 GetSerialPortNumber(IN HDEVINFO DeviceInfoSet,
00101                     IN PSP_DEVINFO_DATA DeviceInfoData)
00102 {
00103     PCM_RESOURCE_LIST lpResourceList = NULL;
00104     PCM_PARTIAL_RESOURCE_DESCRIPTOR lpResDes;
00105     ULONG i;
00106     DWORD dwBaseAddress = 0;
00107     DWORD dwPortNumber = 0;
00108 
00109     TRACE("GetSerialPortNumber(%p, %p)\n",
00110           DeviceInfoSet, DeviceInfoData);
00111 
00112     if (GetBootResourceList(DeviceInfoSet,
00113                             DeviceInfoData,
00114                             &lpResourceList))
00115     {
00116         TRACE("Full resource descriptors: %ul\n", lpResourceList->Count);
00117         if (lpResourceList->Count > 0)
00118         {
00119             TRACE("Partial resource descriptors: %ul\n", lpResourceList->List[0].PartialResourceList.Count);
00120 
00121             for (i = 0; i < lpResourceList->List[0].PartialResourceList.Count; i++)
00122             {
00123                 lpResDes = &lpResourceList->List[0].PartialResourceList.PartialDescriptors[i];
00124                 TRACE("Type: %u\n", lpResDes->Type);
00125 
00126                 switch (lpResDes->Type)
00127                 {
00128                     case CmResourceTypePort:
00129                         TRACE("Port: Start: %I64x  Length: %lu\n",
00130                               lpResDes->u.Port.Start.QuadPart,
00131                               lpResDes->u.Port.Length);
00132                         if (lpResDes->u.Port.Start.HighPart == 0)
00133                             dwBaseAddress = (DWORD)lpResDes->u.Port.Start.LowPart;
00134                         break;
00135 
00136                     case CmResourceTypeInterrupt:
00137                         TRACE("Interrupt: Level: %lu  Vector: %lu\n",
00138                               lpResDes->u.Interrupt.Level,
00139                               lpResDes->u.Interrupt.Vector);
00140                         break;
00141                 }
00142             }
00143         }
00144 
00145         HeapFree(GetProcessHeap(), 0, lpResourceList);
00146     }
00147 
00148     switch (dwBaseAddress)
00149     {
00150         case 0x3f8:
00151             dwPortNumber = 1;
00152             break;
00153 
00154         case 0x2f8:
00155             dwPortNumber = 2;
00156             break;
00157 
00158         case 0x3e8:
00159             dwPortNumber = 3;
00160             break;
00161 
00162         case 0x2e8:
00163             dwPortNumber = 4;
00164             break;
00165     }
00166 
00167     return dwPortNumber;
00168 }
00169 
00170 
00171 DWORD
00172 GetParallelPortNumber(IN HDEVINFO DeviceInfoSet,
00173                       IN PSP_DEVINFO_DATA DeviceInfoData)
00174 {
00175     PCM_RESOURCE_LIST lpResourceList = NULL;
00176     PCM_PARTIAL_RESOURCE_DESCRIPTOR lpResDes;
00177     ULONG i;
00178     DWORD dwBaseAddress = 0;
00179     DWORD dwPortNumber = 0;
00180 
00181     TRACE("GetParallelPortNumber(%p, %p)\n",
00182           DeviceInfoSet, DeviceInfoData);
00183 
00184     if (GetBootResourceList(DeviceInfoSet,
00185                             DeviceInfoData,
00186                             &lpResourceList))
00187     {
00188         TRACE("Full resource descriptors: %ul\n", lpResourceList->Count);
00189         if (lpResourceList->Count > 0)
00190         {
00191             TRACE("Partial resource descriptors: %ul\n", lpResourceList->List[0].PartialResourceList.Count);
00192 
00193             for (i = 0; i < lpResourceList->List[0].PartialResourceList.Count; i++)
00194             {
00195                 lpResDes = &lpResourceList->List[0].PartialResourceList.PartialDescriptors[i];
00196                 TRACE("Type: %u\n", lpResDes->Type);
00197 
00198                 switch (lpResDes->Type)
00199                 {
00200                     case CmResourceTypePort:
00201                         TRACE("Port: Start: %I64x  Length: %lu\n",
00202                               lpResDes->u.Port.Start.QuadPart,
00203                               lpResDes->u.Port.Length);
00204                         if (lpResDes->u.Port.Start.HighPart == 0)
00205                             dwBaseAddress = (DWORD)lpResDes->u.Port.Start.LowPart;
00206                         break;
00207 
00208                     case CmResourceTypeInterrupt:
00209                         TRACE("Interrupt: Level: %lu  Vector: %lu\n",
00210                               lpResDes->u.Interrupt.Level,
00211                               lpResDes->u.Interrupt.Vector);
00212                         break;
00213                 }
00214 
00215             }
00216 
00217         }
00218 
00219         HeapFree(GetProcessHeap(), 0, lpResourceList);
00220     }
00221 
00222     switch (dwBaseAddress)
00223     {
00224         case 0x378:
00225             dwPortNumber = 1;
00226             break;
00227 
00228         case 0x278:
00229             dwPortNumber = 2;
00230             break;
00231     }
00232 
00233     return dwPortNumber;
00234 }
00235 
00236 
00237 static DWORD
00238 InstallSerialPort(IN HDEVINFO DeviceInfoSet,
00239                   IN PSP_DEVINFO_DATA DeviceInfoData)
00240 {
00241     WCHAR szDeviceDescription[256];
00242     WCHAR szFriendlyName[256];
00243     WCHAR szPortName[8];
00244     DWORD dwPortNumber = 0;
00245     DWORD dwSize;
00246     HCOMDB hComDB = HCOMDB_INVALID_HANDLE_VALUE;
00247     HKEY hKey;
00248     LONG lError;
00249 
00250     TRACE("InstallSerialPort(%p, %p)\n",
00251           DeviceInfoSet, DeviceInfoData);
00252 
00253     /* Open the com port database */
00254     ComDBOpen(&hComDB);
00255 
00256     /* Try to read the 'PortName' value and determine the port number */
00257     hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
00258                                    DeviceInfoData,
00259                                    DICS_FLAG_GLOBAL,
00260                                    0,
00261                                    DIREG_DEV,
00262                                    NULL,
00263                                    NULL);
00264     if (hKey != INVALID_HANDLE_VALUE)
00265     {
00266         dwSize = sizeof(szPortName);
00267         lError = RegQueryValueEx(hKey,
00268                                  L"PortName",
00269                                  NULL,
00270                                  NULL,
00271                                  (PBYTE)szPortName,
00272                                  &dwSize);
00273         if (lError  == ERROR_SUCCESS)
00274         {
00275             if (_wcsnicmp(szPortName, pszCom, wcslen(pszCom)) == 0)
00276             {
00277                 dwPortNumber = _wtoi(szPortName + wcslen(pszCom));
00278                 TRACE("COM port number found: %lu\n", dwPortNumber);
00279             }
00280         }
00281 
00282         RegCloseKey(hKey);
00283     }
00284 
00285     /* Determine the port number from its resources ... */
00286     if (dwPortNumber == 0)
00287         dwPortNumber = GetSerialPortNumber(DeviceInfoSet,
00288                                            DeviceInfoData);
00289 
00290     if (dwPortNumber != 0)
00291     {
00292         /* ... and claim the port number in the database */
00293         ComDBClaimPort(hComDB,
00294                        dwPortNumber,
00295                        FALSE,
00296                        NULL);
00297     }
00298     else
00299     {
00300         /* ... or claim the next free port number */
00301         ComDBClaimNextFreePort(hComDB,
00302                                &dwPortNumber);
00303     }
00304 
00305     /* Build the name of the port device */
00306     swprintf(szPortName, L"%s%u", pszCom, dwPortNumber);
00307 
00308     /* Close the com port database */
00309     if (hComDB != HCOMDB_INVALID_HANDLE_VALUE)
00310         ComDBClose(hComDB);
00311 
00312     /* Set the 'PortName' value */
00313     hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
00314                                    DeviceInfoData,
00315                                    DICS_FLAG_GLOBAL,
00316                                    0,
00317                                    DIREG_DEV,
00318                                    NULL,
00319                                    NULL);
00320     if (hKey != INVALID_HANDLE_VALUE)
00321     {
00322         RegSetValueExW(hKey,
00323                        L"PortName",
00324                        0,
00325                        REG_SZ,
00326                        (LPBYTE)szPortName,
00327                        (wcslen(szPortName) + 1) * sizeof(WCHAR));
00328 
00329         RegCloseKey(hKey);
00330     }
00331 
00332     /* Install the device */
00333     if (!SetupDiInstallDevice(DeviceInfoSet,
00334                               DeviceInfoData))
00335     {
00336         return GetLastError();
00337     }
00338 
00339     /* Get the device description... */
00340     if (SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet,
00341                                           DeviceInfoData,
00342                                           SPDRP_DEVICEDESC,
00343                                           NULL,
00344                                           (LPBYTE)szDeviceDescription,
00345                                           256 * sizeof(WCHAR),
00346                                           NULL))
00347     {
00348         /* ... and use it to build a new friendly name */
00349         swprintf(szFriendlyName,
00350                  L"%s (%s)",
00351                  szDeviceDescription,
00352                  szPortName);
00353     }
00354     else
00355     {
00356         /* ... or build a generic friendly name */
00357         swprintf(szFriendlyName,
00358                  L"Serial Port (%s)",
00359                  szPortName);
00360     }
00361 
00362     /* Set the friendly name for the device */
00363     SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet,
00364                                       DeviceInfoData,
00365                                       SPDRP_FRIENDLYNAME,
00366                                       (LPBYTE)szFriendlyName,
00367                                       (wcslen(szFriendlyName) + 1) * sizeof(WCHAR));
00368 
00369     return ERROR_SUCCESS;
00370 }
00371 
00372 
00373 static DWORD
00374 InstallParallelPort(IN HDEVINFO DeviceInfoSet,
00375                     IN PSP_DEVINFO_DATA DeviceInfoData)
00376 {
00377     WCHAR szDeviceDescription[256];
00378     WCHAR szFriendlyName[256];
00379     WCHAR szPortName[8];
00380     DWORD dwPortNumber = 0;
00381     DWORD dwSize;
00382     LONG lError;
00383     HKEY hKey;
00384 
00385     TRACE("InstallParallelPort(%p, %p)\n",
00386           DeviceInfoSet, DeviceInfoData);
00387 
00388     /* Try to read the 'PortName' value and determine the port number */
00389     hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
00390                                    DeviceInfoData,
00391                                    DICS_FLAG_GLOBAL,
00392                                    0,
00393                                    DIREG_DEV,
00394                                    NULL,
00395                                    NULL);
00396     if (hKey != INVALID_HANDLE_VALUE)
00397     {
00398         dwSize = sizeof(szPortName);
00399         lError = RegQueryValueEx(hKey,
00400                                  L"PortName",
00401                                  NULL,
00402                                  NULL,
00403                                  (PBYTE)szPortName,
00404                                  &dwSize);
00405         if (lError  == ERROR_SUCCESS)
00406         {
00407             if (_wcsnicmp(szPortName, pszLpt, wcslen(pszLpt)) == 0)
00408             {
00409                 dwPortNumber = _wtoi(szPortName + wcslen(pszLpt));
00410                 TRACE("LPT port number found: %lu\n", dwPortNumber);
00411             }
00412         }
00413 
00414         RegCloseKey(hKey);
00415     }
00416 
00417     /* ... try to determine the port number from its resources */
00418     if (dwPortNumber == 0)
00419         dwPortNumber = GetParallelPortNumber(DeviceInfoSet,
00420                                              DeviceInfoData);
00421 
00422     if (dwPortNumber == 0)
00423     {
00424         /* FIXME */
00425     }
00426 
00427     if (dwPortNumber != 0)
00428     {
00429         swprintf(szPortName, L"%s%u", pszLpt, dwPortNumber);
00430     }
00431     else
00432     {
00433         wcscpy(szPortName, L"LPTx");
00434     }
00435 
00436     if (dwPortNumber != 0)
00437     {
00438     /* Set the 'PortName' value */
00439     hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
00440                                    DeviceInfoData,
00441                                    DICS_FLAG_GLOBAL,
00442                                    0,
00443                                    DIREG_DEV,
00444                                    NULL,
00445                                    NULL);
00446     if (hKey != INVALID_HANDLE_VALUE)
00447     {
00448         RegSetValueExW(hKey,
00449                        L"PortName",
00450                        0,
00451                        REG_SZ,
00452                        (LPBYTE)szPortName,
00453                        (wcslen(szPortName) + 1) * sizeof(WCHAR));
00454 
00455         RegCloseKey(hKey);
00456     }
00457     }
00458 
00459     /* Install the device */
00460     if (!SetupDiInstallDevice(DeviceInfoSet,
00461                               DeviceInfoData))
00462     {
00463         return GetLastError();
00464     }
00465 
00466     /* Get the device description... */
00467     if (SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet,
00468                                           DeviceInfoData,
00469                                           SPDRP_DEVICEDESC,
00470                                           NULL,
00471                                           (LPBYTE)szDeviceDescription,
00472                                           256 * sizeof(WCHAR),
00473                                           NULL))
00474     {
00475         /* ... and use it to build a new friendly name */
00476         swprintf(szFriendlyName,
00477                  L"%s (%s)",
00478                  szDeviceDescription,
00479                  szPortName);
00480     }
00481     else
00482     {
00483         /* ... or build a generic friendly name */
00484         swprintf(szFriendlyName,
00485                  L"Parallel Port (%s)",
00486                  szPortName);
00487     }
00488 
00489     /* Set the friendly name for the device */
00490     SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet,
00491                                       DeviceInfoData,
00492                                       SPDRP_FRIENDLYNAME,
00493                                       (LPBYTE)szFriendlyName,
00494                                       (wcslen(szFriendlyName) + 1) * sizeof(WCHAR));
00495 
00496     return ERROR_SUCCESS;
00497 }
00498 
00499 
00500 VOID
00501 InstallDeviceData(IN HDEVINFO DeviceInfoSet,
00502                   IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
00503 {
00504     HKEY hKey = NULL;
00505     HINF hInf = INVALID_HANDLE_VALUE;
00506     SP_DRVINFO_DATA DriverInfoData;
00507     PSP_DRVINFO_DETAIL_DATA DriverInfoDetailData;
00508     WCHAR InfSectionWithExt[256];
00509     BYTE buffer[2048];
00510     DWORD dwRequired;
00511 
00512     TRACE("InstallDeviceData()\n");
00513 
00514     hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
00515                                    DeviceInfoData,
00516                                    DICS_FLAG_GLOBAL,
00517                                    0,
00518                                    DIREG_DRV,
00519                                    NULL,
00520                                    NULL);
00521     if (hKey == NULL)
00522         goto done;
00523 
00524     DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
00525     if (!SetupDiGetSelectedDriverW(DeviceInfoSet,
00526                                    DeviceInfoData,
00527                                    &DriverInfoData))
00528     {
00529         goto done;
00530     }
00531 
00532     DriverInfoDetailData = (PSP_DRVINFO_DETAIL_DATA)buffer;
00533     DriverInfoDetailData->cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
00534     if (!SetupDiGetDriverInfoDetailW(DeviceInfoSet,
00535                                      DeviceInfoData,
00536                                      &DriverInfoData,
00537                                      DriverInfoDetailData,
00538                                      2048,
00539                                      &dwRequired))
00540     {
00541         if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
00542             goto done;
00543     }
00544 
00545     TRACE("Inf file name: %S\n", DriverInfoDetailData->InfFileName);
00546 
00547     hInf = SetupOpenInfFileW(DriverInfoDetailData->InfFileName,
00548                              NULL,
00549                              INF_STYLE_WIN4,
00550                              NULL);
00551     if (hInf == INVALID_HANDLE_VALUE)
00552         goto done;
00553 
00554     TRACE("Section name: %S\n", DriverInfoDetailData->SectionName);
00555 
00556     SetupDiGetActualSectionToInstallW(hInf,
00557                                       DriverInfoDetailData->SectionName,
00558                                       InfSectionWithExt,
00559                                       256,
00560                                       NULL,
00561                                       NULL);
00562 
00563     TRACE("InfSectionWithExt: %S\n", InfSectionWithExt);
00564 
00565     SetupInstallFromInfSectionW(NULL,
00566                                 hInf,
00567                                 InfSectionWithExt,
00568                                 SPINST_REGISTRY,
00569                                 hKey,
00570                                 NULL,
00571                                 0,
00572                                 NULL,
00573                                 NULL,
00574                                 NULL,
00575                                 NULL);
00576 
00577     TRACE("Done\n");
00578 
00579 done:;
00580     if (hKey != NULL)
00581         RegCloseKey(hKey);
00582 
00583     if (hInf != INVALID_HANDLE_VALUE)
00584         SetupCloseInfFile(hInf);
00585 }
00586 
00587 
00588 
00589 PORT_TYPE
00590 GetPortType(IN HDEVINFO DeviceInfoSet,
00591             IN PSP_DEVINFO_DATA DeviceInfoData)
00592 {
00593     HKEY hKey = NULL;
00594     DWORD dwSize;
00595     DWORD dwType = 0;
00596     BYTE bData = 0;
00597     PORT_TYPE PortType = UnknownPort;
00598     LONG lError;
00599 
00600     TRACE("GetPortType()\n");
00601 
00602     hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
00603                                    DeviceInfoData,
00604                                    DICS_FLAG_GLOBAL,
00605                                    0,
00606                                    DIREG_DRV,
00607                                    NULL,
00608                                    NULL);
00609     if (hKey == NULL)
00610     {
00611         goto done;
00612     }
00613 
00614     dwSize = sizeof(BYTE);
00615     lError = RegQueryValueExW(hKey,
00616                               L"PortSubClass",
00617                               NULL,
00618                               &dwType,
00619                               &bData,
00620                               &dwSize);
00621 
00622     TRACE("lError: %ld\n", lError);
00623     TRACE("dwSize: %lu\n", dwSize);
00624     TRACE("dwType: %lu\n", dwType);
00625 
00626     if (lError == ERROR_SUCCESS &&
00627         dwSize == sizeof(BYTE) &&
00628         dwType == REG_BINARY)
00629     {
00630         if (bData == 0)
00631             PortType = ParallelPort;
00632         else
00633             PortType = SerialPort;
00634     }
00635 
00636 done:;
00637     if (hKey != NULL)
00638         RegCloseKey(hKey);
00639 
00640     TRACE("GetPortType() returns %u \n", PortType);
00641 
00642     return PortType;
00643 }
00644 
00645 
00646 static DWORD
00647 InstallPort(IN HDEVINFO DeviceInfoSet,
00648             IN PSP_DEVINFO_DATA DeviceInfoData)
00649 {
00650     PORT_TYPE PortType;
00651 
00652     InstallDeviceData(DeviceInfoSet, DeviceInfoData);
00653 
00654     PortType = GetPortType(DeviceInfoSet, DeviceInfoData);
00655     switch (PortType)
00656     {
00657         case ParallelPort:
00658             return InstallParallelPort(DeviceInfoSet, DeviceInfoData);
00659 
00660         case SerialPort:
00661             return InstallSerialPort(DeviceInfoSet, DeviceInfoData);
00662 
00663         default:
00664             return ERROR_DI_DO_DEFAULT;
00665     }
00666 }
00667 
00668 
00669 static DWORD
00670 RemovePort(IN HDEVINFO DeviceInfoSet,
00671            IN PSP_DEVINFO_DATA DeviceInfoData)
00672 {
00673     PORT_TYPE PortType;
00674     HCOMDB hComDB = HCOMDB_INVALID_HANDLE_VALUE;
00675     HKEY hKey;
00676     LONG lError;
00677     DWORD dwPortNumber;
00678     DWORD dwPortNameSize;
00679     WCHAR szPortName[8];
00680 
00681     /* If we are removing a serial port ... */
00682     PortType = GetPortType(DeviceInfoSet, DeviceInfoData);
00683     if (PortType == SerialPort)
00684     {
00685         /* Open the port database */
00686         if (ComDBOpen(&hComDB) == ERROR_SUCCESS)
00687         {
00688             /* Open the device key */
00689             hKey = SetupDiOpenDevRegKey(DeviceInfoSet,
00690                                         DeviceInfoData,
00691                                         DICS_FLAG_GLOBAL,
00692                                         0,
00693                                         DIREG_DEV,
00694                                         KEY_READ);
00695             if (hKey != INVALID_HANDLE_VALUE)
00696             {
00697                 /* Query the port name */
00698                 dwPortNameSize = sizeof(szPortName);
00699                 lError = RegQueryValueEx(hKey,
00700                                          L"PortName",
00701                                          NULL,
00702                                          NULL,
00703                                          (PBYTE)szPortName,
00704                                          &dwPortNameSize);
00705 
00706                 /* Close the device key */
00707                 RegCloseKey(hKey);
00708 
00709                 /* If we got a valid port name ...*/
00710                 if (lError == ERROR_SUCCESS)
00711                 {
00712                     /* Get the port number */
00713                     dwPortNumber = _wtoi(szPortName + wcslen(pszCom));
00714 
00715                     /* Release the port */
00716                     ComDBReleasePort(hComDB, dwPortNumber);
00717                 }
00718             }
00719 
00720             /* Close the port database */
00721             ComDBClose(hComDB);
00722         }
00723     }
00724 
00725     /* Remove the device */
00726     if (!SetupDiRemoveDevice(DeviceInfoSet, DeviceInfoData))
00727         return GetLastError();
00728 
00729     return ERROR_SUCCESS;
00730 }
00731 
00732 
00733 DWORD
00734 WINAPI
00735 PortsClassInstaller(IN DI_FUNCTION InstallFunction,
00736                     IN HDEVINFO DeviceInfoSet,
00737                     IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
00738 {
00739     TRACE("PortsClassInstaller(%lu, %p, %p)\n",
00740           InstallFunction, DeviceInfoSet, DeviceInfoData);
00741 
00742     switch (InstallFunction)
00743     {
00744         case DIF_INSTALLDEVICE:
00745             return InstallPort(DeviceInfoSet, DeviceInfoData);
00746 
00747         case DIF_REMOVE:
00748             return RemovePort(DeviceInfoSet, DeviceInfoData);
00749 
00750         default:
00751             TRACE("Install function %u ignored\n", InstallFunction);
00752             return ERROR_DI_DO_DEFAULT;
00753     }
00754 }
00755 
00756 /* EOF */

Generated on Sun May 27 2012 04:20:52 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.