用程序说明,谢谢!

解决方案 »

  1.   

    // 原理:USB2.0的主机控制器类型是EHCI,PCI设备ID是PCI\CC_0C0320,因此只要找到这个设备ID就可以认为主板支持USB2.0#include <windows.h>
    #include <setupapi.h>
    #include <stdio.h>#pragma comment(lib, "setupapi.lib")int main(int argc, char* argv[])
    {
        HDEVINFO DeviceInfoSet;
        SP_DEVINFO_DATA DeviceInfoData;
        DWORD i,err; BOOL bFind = FALSE;// char* CompatibleID = argv[1];
    char* CompatibleID = "PCI\\CC_0C0320";    DeviceInfoSet = SetupDiGetClassDevs(NULL, // All Classes
            0,
            0, 
            DIGCF_ALLCLASSES | DIGCF_PRESENT ); // All devices present on system    if (DeviceInfoSet == INVALID_HANDLE_VALUE) {
    printf("GetClassDevs(All Present Devices fail");
            return 1;
        } DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);    for (i=0;SetupDiEnumDeviceInfo(DeviceInfoSet,i,&DeviceInfoData);i++) {
            DWORD DataT;
            LPTSTR p,buffer = NULL;
            DWORD buffersize = 0;
            
            while (!SetupDiGetDeviceRegistryProperty(
                DeviceInfoSet,
                &DeviceInfoData,
                SPDRP_COMPATIBLEIDS,
                &DataT,
                (PBYTE)buffer,
                buffersize,
                &buffersize))
            {
                if (GetLastError() == ERROR_INVALID_DATA) {
                    break;
                }
                else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
                    if (buffer) 
                        LocalFree(buffer); buffersize *= 2;
                    buffer = LocalAlloc(LPTR,buffersize);
                }
                else {
                    printf("GetDeviceRegistryProperty fail");
                    goto cleanup_DeviceInfo;
                }            
            }        if (GetLastError() == ERROR_INVALID_DATA) 
                continue;
            
           for (p=buffer;*p&&(p<&buffer[buffersize]);p+=lstrlen(p)+sizeof(TCHAR))
            {
    //            printf(TEXT("Compare device ID: [%s]\n"),p);            if (!stricmp(CompatibleID,p))
                {
                   printf(TEXT("Found! [%s]\n"),p);    bFind = TRUE;               break;
                }
            }        if (buffer) LocalFree(buffer); if (bFind) {
    break;
    }
        }    if ((GetLastError()!=NO_ERROR)&&(GetLastError()!=ERROR_NO_MORE_ITEMS))
        {
            printf("EnumDeviceInfo fail");
        }
        
        //
        //  Cleanup.
        //    
    cleanup_DeviceInfo:
        err = GetLastError();
    SetupDiDeleteDeviceInfo(DeviceInfoSet, &DeviceInfoData); return err;
    }