当前位置: 首页>>代码示例>>C++>>正文


C++ SetupDiGetDeviceRegistryProperty函数代码示例

本文整理汇总了C++中SetupDiGetDeviceRegistryProperty函数的典型用法代码示例。如果您正苦于以下问题:C++ SetupDiGetDeviceRegistryProperty函数的具体用法?C++ SetupDiGetDeviceRegistryProperty怎么用?C++ SetupDiGetDeviceRegistryProperty使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SetupDiGetDeviceRegistryProperty函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getDeviceProperty

bool getDeviceProperty(HDEVINFO devices, SP_DEVINFO_DATA& device_info, DWORD property, std::wstring& value)
{
	DWORD size = 8192;

	try
	{
		DWORD data_type;
		DWORD requested_size;
		LPTSTR buffer = new TCHAR[(size / sizeof(TCHAR)) + 1];
		memset(buffer, 0x00, (size / sizeof(TCHAR)) + 1);

		if (buffer)
		{
			bool success = true;

			while (!SetupDiGetDeviceRegistryProperty(devices, &device_info, property, &data_type, reinterpret_cast<LPBYTE>(buffer), size, &requested_size))
			{
				if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
				{
					success = false;
					break;
				}

				if (data_type != REG_SZ)
				{
					success = false;
					break;
				}

				size = requested_size;
				delete[] buffer;
				buffer = new TCHAR[(size / sizeof(TCHAR)) + 1];
				memset(buffer, 0x00, (size / sizeof(TCHAR)) + 1);

				if (!buffer)
				{
					success = false;
					break;
				}
			}

			if (success)
			{
				value = std::wstring(buffer);
			}

			delete[] buffer;

			return true;
		}
	}
	catch (...)
	{
		std::wcerr << "Allocation error. This is serious !" << std::endl;
	}

	return false;
}
开发者ID:0ver6tm,项目名称:freelan-all,代码行数:58,代码来源:tap_setup.cpp

示例2: vm_sys_info_get_vga_card

void vm_sys_info_get_vga_card(vm_char *vga_card)
{
    SP_DEVINFO_DATA sp_dev_info;
    HDEVINFO DeviceInfoSet;
    vm_char string1[] = VM_STRING("Display");
    Ipp32u dwIndex = 0;
    vm_char data[_MAX_LEN] = {0,};

    /* check error(s) */
    if (NULL == vga_card)
        return;

    ZeroMemory(&sp_dev_info, sizeof(SP_DEVINFO_DATA));
    ZeroMemory(&DeviceInfoSet, sizeof(HDEVINFO));

    DeviceInfoSet = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
    sp_dev_info.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
    while (SetupDiEnumDeviceInfo(DeviceInfoSet, dwIndex, &sp_dev_info))
    {
        SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
                                         &sp_dev_info,
                                         SPDRP_CLASS,
                                         NULL,
                                         (Ipp8u *) data,
                                         _MAX_LEN,
                                         NULL);
        if (!vm_string_strcmp((vm_char*)data, string1))
        {
            SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
                                             &sp_dev_info,
                                             SPDRP_DEVICEDESC,
                                             NULL,
                                             (PBYTE) vga_card,
                                             _MAX_LEN,
                                             NULL);
            break;
        }
        dwIndex++;
    }
    SetupDiDestroyDeviceInfoList(DeviceInfoSet);

} /* void vm_sys_info_get_vga_card(vm_char *vga_card) */
开发者ID:metamediatechnologies,项目名称:libvm,代码行数:42,代码来源:vm_sys_info_win32.c

示例3: warning

BOOL ComPortDiscovery::QueryDeviceDescription(HDEVINFO hDevInfoSet, SP_DEVINFO_DATA& devInfo, ATL::CHeapPtr<BYTE>& byFriendlyName)
{
	DWORD dwType = 0;
	DWORD dwSize = 0;
	//Query initially to get the buffer size required
	if (!SetupDiGetDeviceRegistryProperty(hDevInfoSet, &devInfo, SPDRP_DEVICEDESC, &dwType, NULL, 0, &dwSize))
	{
		if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
			return FALSE;
	}

#pragma warning(suppress: 6102)
	if (!byFriendlyName.Allocate(dwSize))
	{
		SetLastError(ERROR_OUTOFMEMORY);
		return FALSE;
	}

	return SetupDiGetDeviceRegistryProperty(hDevInfoSet, &devInfo, SPDRP_DEVICEDESC, &dwType, byFriendlyName.m_pData, dwSize, &dwSize) && (dwType == REG_SZ);
}
开发者ID:viaphonepayments,项目名称:ArduinoSerialCom,代码行数:20,代码来源:com_discovery.cpp

示例4: GetDeviceRegistryProperty

static BOOL GetDeviceRegistryProperty( HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDeviceInfoData, DWORD dwProperty, CString& strProperty )
{
    BOOL bRet = TRUE;
    DWORD dwDataType = 0;
    LPTSTR pszBuf = NULL;
    DWORD dwBuffersize = 0;

    while ( !SetupDiGetDeviceRegistryProperty( hDevInfo, pDeviceInfoData, dwProperty, &dwDataType, ( PBYTE )pszBuf, dwBuffersize, &dwBuffersize ) )
    {
        if ( ERROR_INVALID_DATA == GetLastError() )
        {
            // 不存在 Device desc
            bRet = FALSE;
            break;
        }
        else if ( ERROR_INSUFFICIENT_BUFFER == GetLastError() )
        {
            // buffer size 不对
            if ( NULL != pszBuf )
            {
                LocalFree( LocalHandle( pszBuf ) );
                pszBuf = NULL;
            }

            pszBuf = ( LPTSTR )LocalAlloc( LPTR, dwBuffersize );
            if ( NULL == pszBuf )
            {
                bRet = FALSE;
                break;
            }
        }
        else
        {
            // 未知错误
            bRet = FALSE;
            break;
        }
    }

    if ( bRet )
    {
        strProperty = pszBuf;
    }

    if ( NULL != pszBuf )
    {
        LocalFree( LocalHandle( pszBuf ) );
        pszBuf = NULL;
    }

    return bRet;
}
开发者ID:fre2003,项目名称:l3220,代码行数:52,代码来源:AdapterIpV4V6Info_20.cpp

示例5: GetDeviceConfigFlags

DWORD
GetDeviceConfigFlags(
    _In_ HDEVINFO         DeviceInfoSet,
    _In_ PSP_DEVINFO_DATA DeviceInfoData
    )
    
/*++

Routine Description:

    This routine retrieves the ConfigFlags registry property for the specified
    device info element, or zero if the property cannot be retrieved (e.g.,
    because ConfigFlags haven't yet been set by Found New Hardware process).

Arguments:

    DeviceInfoSet - Supplies a handle to the device information set containing
        the device of interest.
        
    DeviceInfoData - Supplies context of a device info element for which
        ConfigFlags is to be retrieved.

Return Value:

    If device's REG_DWORD ConfigFlags property can be retrieved, it is returned.
    Otherwise, zero is returned.

--*/

{
    DWORD ConfigFlags, RegDataType;
    
    if(!SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
                                         DeviceInfoData,
                                         SPDRP_CONFIGFLAGS,
                                         &RegDataType,
                                         (PBYTE)&ConfigFlags,
                                         sizeof(ConfigFlags),
                                         NULL)
       || (RegDataType != REG_DWORD))
    {
        //
        // It's possible that this property isn't there, although we should
        // never enounter other problems like wrong datatype or data length
        // longer than sizeof(DWORD).  In any event, just return zero.
        //
        ConfigFlags = 0;
    }
    
    return ConfigFlags;
}
开发者ID:0xhack,项目名称:Windows-driver-samples,代码行数:51,代码来源:util.c

示例6: GetDevRegProperty

BOOL CDeviceSetup::GetDevRegProperty(DWORD property, DWORD *ret)
{

	BOOL status=SetupDiGetDeviceRegistryProperty(m_hDevList,
												&m_devInfoData,
												property,
												0,
												(UCHAR *) ret,
												sizeof(DWORD),
												0);

	return status;
	
}
开发者ID:jmullins,项目名称:efficacy,代码行数:14,代码来源:devicesetup.cpp

示例7: USBHIDFindUSBHIDDevice

// 用于查找HID设备
USBHIDDLL_API bool __stdcall USBHIDFindUSBHIDDevice()
{
    GUID Guid;
    HidD_GetHidGuid(&Guid);

    void* info;
    info=SetupDiGetClassDevs(&Guid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
    if (info!=INVALID_HANDLE_VALUE) 
    {
        DWORD devIndex;
        SP_INTERFACE_DEVICE_DATA ifData;
        ifData.cbSize=sizeof(ifData);

        for (devIndex=0;SetupDiEnumDeviceInterfaces(info, NULL, &Guid, devIndex, &ifData);++devIndex)
        {
            DWORD needed;

            SetupDiGetDeviceInterfaceDetail(info, &ifData, NULL, 0, &needed, NULL);

            PSP_INTERFACE_DEVICE_DETAIL_DATA detail=(PSP_INTERFACE_DEVICE_DETAIL_DATA)new BYTE[needed];
            detail->cbSize=sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
            SP_DEVINFO_DATA did={sizeof(SP_DEVINFO_DATA)};

            if (SetupDiGetDeviceInterfaceDetail(info, &ifData, detail, needed, NULL, &did))
            {
                // 查找特定设备 查到后则返回。
                if(strstr(detail->DevicePath, "vid_0483") != NULL)
                {
                    memset(GlobalUSBHIDDevicePath, '\0', sizeof(GlobalUSBHIDDevicePath));                 
                   memcpy(GlobalUSBHIDDevicePath, detail->DevicePath, strlen(detail->DevicePath));

                   if (!SetupDiGetDeviceRegistryProperty(info, &did, SPDRP_DEVICEDESC, NULL, 
                       (PBYTE)GlobalUSBHIDDeviceName, sizeof(GlobalUSBHIDDeviceName), NULL))
                   {
                       memset(GlobalUSBHIDDeviceName, '\0', sizeof(GlobalUSBHIDDeviceName));
                       char* hint = "(Unnamed HID device)";
                       memcpy(GlobalUSBHIDDeviceName,  hint, strlen(hint));
                   }

                   delete[] (PBYTE)detail;
                   SetupDiDestroyDeviceInfoList(info);    
                   return true;
                }
            }
            delete[] (PBYTE)detail; 
        }
        SetupDiDestroyDeviceInfoList(info);
    }
    return false;
}
开发者ID:GACLove,项目名称:USB-HID-Demonstrator,代码行数:51,代码来源:UsbHidDll.cpp

示例8: EnumerateDiskDrives

VOID EnumerateDiskDrives(
    _In_ PPH_DISK_ENUM_CALLBACK DiskEnumCallback,
    _In_opt_ PVOID Context
)
{
    HDEVINFO deviceInfoHandle;
    SP_DEVICE_INTERFACE_DATA deviceInterfaceData = { sizeof(SP_DEVICE_INTERFACE_DATA) };
    SP_DEVINFO_DATA deviceInfoData = { sizeof(SP_DEVINFO_DATA) };
    PSP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetail = NULL;
    ULONG deviceInfoLength = 0;
    HANDLE ret_handle = NULL;

    if ((deviceInfoHandle = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)) == INVALID_HANDLE_VALUE)
        return;

    for (ULONG i = 0; i < 1000; i++)
    {
        if (!SetupDiEnumDeviceInterfaces(deviceInfoHandle, 0, &GUID_DEVINTERFACE_DISK, i, &deviceInterfaceData))
            break;

        if (SetupDiGetDeviceInterfaceDetail(deviceInfoHandle, &deviceInterfaceData, 0, 0, &deviceInfoLength, &deviceInfoData) || GetLastError() != ERROR_INSUFFICIENT_BUFFER)
            continue;

        deviceInterfaceDetail = PhAllocate(deviceInfoLength);
        deviceInterfaceDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);

        if (SetupDiGetDeviceInterfaceDetail(deviceInfoHandle, &deviceInterfaceData, deviceInterfaceDetail, deviceInfoLength, &deviceInfoLength, &deviceInfoData))
        {
            WCHAR diskFriendlyName[MAX_PATH] = L"";

            SetupDiGetDeviceRegistryProperty(
                deviceInfoHandle,
                &deviceInfoData,
                SPDRP_FRIENDLYNAME,
                NULL,
                (PBYTE)diskFriendlyName,
                ARRAYSIZE(diskFriendlyName),
                NULL
            );

            DiskEnumCallback(deviceInterfaceDetail->DevicePath, diskFriendlyName, Context);
        }

        PhFree(deviceInterfaceDetail);
        deviceInterfaceDetail = NULL;
    }

    SetupDiDestroyDeviceInfoList(deviceInfoHandle);
}
开发者ID:phplugins,项目名称:plugins-extra,代码行数:49,代码来源:disks.c

示例9: ti_is_us

/* XXX */
static int ti_is_us(struct tip_cygwin *priv, HDEVINFO *hdi,
		    SP_DEVINFO_DATA *did)
{
	char buf[256];
	DWORD len = sizeof(buf), dt;

	if (priv) {} /* XXX unused */

	if (!SetupDiGetDeviceRegistryProperty(*hdi, did, SPDRP_DEVICEDESC, &dt,
					      (unsigned char*)buf, len, &len))
		return 0;

	if (dt != REG_SZ)
		return 0;

	return strstr(buf, "TAP-Win32") != NULL;
}
开发者ID:0x0d,项目名称:lrc,代码行数:18,代码来源:cygwin_tap.c

示例10: get_str_property

LPTSTR get_str_property(HDEVINFO hDevInfo, SP_DEVINFO_DATA* DeviceInfoData, DWORD prop)
{
        DWORD DataT;
        LPTSTR buffer = NULL;
        DWORD buffersize = 0;
        
        //
        // Call function with null to begin with, 
        // then use the returned buffer size (doubled)
        // to Alloc the buffer. Keep calling until
        // success or an unknown failure.
        //
        //  Double the returned buffersize to correct
        //  for underlying legacy CM functions that 
        //  return an incorrect buffersize value on 
        //  DBCS/MBCS systems.
        // 
        while (!SetupDiGetDeviceRegistryProperty(hDevInfo, DeviceInfoData,
            prop, &DataT,
            (PBYTE)buffer,
            buffersize,
            &buffersize))
        {
            if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
            {
                // Change the buffer size.
                if (buffer) LocalFree(buffer);
                // Double the size to avoid problems on 
                // W2k MBCS systems per KB 888609. 
                buffer = LocalAlloc(LPTR,buffersize * 2);

		if (!buffer)
		    return NULL;
            }
            else
            {
                // Insert error handling here.
		win32perror("SetupDiGetDeviceRegistryProperty()");
                if (buffer) LocalFree(buffer);
		return NULL;
            }
        }

	return buffer;
}
开发者ID:Kerd,项目名称:tests,代码行数:45,代码来源:test1.c

示例11: while

bool WinNetCard::GetRegistryProperty(HDEVINFO DeviceInfoSet,   
	PSP_DEVINFO_DATA DeviceInfoData, 
	ULONG Property, 
	PVOID Buffer,
	PULONG Length)   
{   
	while (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet,   
		DeviceInfoData, Property, NULL, (BYTE *)*(TCHAR **)Buffer, *Length, Length))   
	{   
		if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)   
		{   
			if (*(LPTSTR *)Buffer) LocalFree(Buffer);   
			*(PCHAR *)Buffer = (PCHAR)LocalAlloc(LPTR,*Length);   
		}   
		else return false;   
	}   
	return (*(LPTSTR *)Buffer)[0];
}
开发者ID:5loyd,项目名称:Oh-My-Lovely-Toy,代码行数:18,代码来源:WinNetCard.cpp

示例12: get_registry_property

static LPTSTR
get_registry_property(HDEVINFO hDevInfo, DWORD index, DWORD property, BOOL *iterate) {
    /* Get a the property specified by `property` from the registry for the
     * device enumerated by `index` in the collection `hDevInfo`. `iterate`
     * will be set to `FALSE` if `index` points outside `hDevInfo`.
     * :return: A string allocated on the heap containing the property or
     *          `NULL` if an error occurred.
     */
    SP_DEVINFO_DATA DeviceInfoData;
    DWORD DataT;
    LPTSTR buffer = NULL;
    DWORD buffersize = 0;
    DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

    if (!SetupDiEnumDeviceInfo(hDevInfo, index, &DeviceInfoData)) {
        *iterate = FALSE;
        return NULL;
    }

    while(!SetupDiGetDeviceRegistryProperty(
            hDevInfo,
            &DeviceInfoData,
            property,
            &DataT,
            (PBYTE)buffer,
            buffersize,
            &buffersize)) {
            if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
                buffer = (LPTSTR)PyMem_Malloc(2*buffersize); // Twice for bug in Win2k
            } else {
            	PyMem_Free(buffer);
            	PyErr_SetFromWindowsErr(0);
                buffer = NULL;
                break;
            }
    } //while

    return buffer;
}
开发者ID:Eksmo,项目名称:calibre,代码行数:39,代码来源:winutil.c

示例13: GetDiPropStr

static wxString GetDiPropStr(HDEVINFO h, SP_DEVINFO_DATA *data, const wxString& key)
{
    wxString val;

    WCHAR buf[4096];
    DWORD size = sizeof(buf);
    DWORD proptype;
    if (SetupDiGetDeviceRegistryProperty(h, data, SPDRP_DRIVER, &proptype, (PBYTE)&buf[0], size, &size))
    {
        wxRegKey k(wxString("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Class\\") + buf);
        if (!QueryValue(k, key, val))
        {
            Debug.AddLine("SSAG failed to get " + key + " driver property value");
        }
    }
    else
    {
        Debug.AddLine("SSAG failed to get SDRP_DRIVER registry property for SSAG");
    }

    return val;
}
开发者ID:Saharac,项目名称:open-phd-guiding,代码行数:22,代码来源:cam_SSAG.cpp

示例14: LOG_INFO


//.........这里部分代码省略.........
        /* get product name */
        char product_buf[256];
        CFIndex product_buflen = 256;
        CFTypeRef product_name_ref = NULL;

        product_name_ref = IORegistryEntrySearchCFProperty(usbCurrentObj,
                                kIOServicePlane, CFSTR("USB Product Name"),
                                kCFAllocatorDefault, 0);
        if(product_name_ref != NULL) {
            CFStringGetCString((CFStringRef)product_name_ref, product_buf, product_buflen,
                               kCFStringEncodingUTF8);
            name += QString::fromUtf8(product_buf);
            CFRelease(product_name_ref);
        }
        else {
            name += QObject::tr("(unknown product name)");
        }

        if(id) {
            usbids.insertMulti(id, name);
            LOG_INFO() << "USB:" << QString("0x%1").arg(id, 8, 16) << name;
        }

    }
    IOObjectRelease(usb_iterator);
#endif

#if defined(Q_OS_WIN32)
    HDEVINFO deviceInfo;
    SP_DEVINFO_DATA infoData;
    DWORD i;

    // Iterate over all devices
    // by doing it this way it's unneccessary to use GUIDs which might be not
    // present in current MinGW. It also seemed to be more reliably than using
    // a GUID.
    // See KB259695 for an example.
    deviceInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);

    infoData.cbSize = sizeof(SP_DEVINFO_DATA);

    for(i = 0; SetupDiEnumDeviceInfo(deviceInfo, i, &infoData); i++) {
        DWORD data;
        LPTSTR buffer = NULL;
        DWORD buffersize = 0;
        QString description;

        // get device descriptor first
        // for some reason not doing so results in bad things (tm)
        while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
            SPDRP_DEVICEDESC, &data, (PBYTE)buffer, buffersize, &buffersize)) {
            if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
                if(buffer) free(buffer);
                // double buffer size to avoid problems as per KB888609
                buffer = (LPTSTR)malloc(buffersize * 2);
            }
            else {
                break;
            }
        }
        if(!buffer) {
            LOG_WARNING() << "Got no device description"
                          << "(SetupDiGetDeviceRegistryProperty), item" << i;
            continue;
        }
        description = QString::fromWCharArray(buffer);

        // now get the hardware id, which contains PID and VID.
        while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
            SPDRP_HARDWAREID, &data, (PBYTE)buffer, buffersize, &buffersize)) {
            if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
                if(buffer) free(buffer);
                // double buffer size to avoid problems as per KB888609
                buffer = (LPTSTR)malloc(buffersize * 2);
            }
            else {
                break;
            }
        }

        if(buffer) {
            // convert buffer text to upper case to avoid depending on the case of
            // the keys (W7 uses different casing than XP at least), in addition
            // XP may use "Vid_" and "Pid_".
            QString data = QString::fromWCharArray(buffer).toUpper();
            QRegExp rex("USB\\\\VID_([0-9A-F]{4})&PID_([0-9A-F]{4}).*");
            if(rex.indexIn(data) >= 0) {
                uint32_t id;
                id = rex.cap(1).toUInt(0, 16) << 16 | rex.cap(2).toUInt(0, 16);
                usbids.insert(id, description);
                LOG_INFO() << "USB:" << QString("0x%1").arg(id, 8, 16);
            }
            free(buffer);
        }
    }
    SetupDiDestroyDeviceInfoList(deviceInfo);

#endif
    return usbids;
}
开发者ID:zfhrp6,项目名称:rockbox,代码行数:101,代码来源:system.cpp

示例15: EnumSerialPortsWindows

void EnumSerialPortsWindows(std::vector<SerialPortInfo> &serialports)
{
	// Create a device information set that will be the container for 
	// the device interfaces.
	GUID *guidDev = (GUID*)&GUID_CLASS_COMPORT;

	HDEVINFO hDevInfo = INVALID_HANDLE_VALUE;
	SP_DEVICE_INTERFACE_DETAIL_DATA *pDetData = NULL;

	try {
		hDevInfo = SetupDiGetClassDevs(guidDev,
			NULL,
			NULL,
			DIGCF_PRESENT | DIGCF_DEVICEINTERFACE
			);

		if (hDevInfo == INVALID_HANDLE_VALUE)
		{
			return;
		}

		// Enumerate the serial ports
		BOOL bOk = TRUE;
		SP_DEVICE_INTERFACE_DATA ifcData;
		DWORD dwDetDataSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) + 256;
		pDetData = (SP_DEVICE_INTERFACE_DETAIL_DATA*) new char[dwDetDataSize];
		// This is required, according to the documentation. Yes,
		// it's weird.
		ifcData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
		pDetData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
		for (DWORD ii = 0; bOk; ii++) {
			bOk = SetupDiEnumDeviceInterfaces(hDevInfo,
				NULL, guidDev, ii, &ifcData);
			if (bOk) {
				// Got a device. Get the details.
				SP_DEVINFO_DATA devdata = { sizeof(SP_DEVINFO_DATA) };
				bOk = SetupDiGetDeviceInterfaceDetail(hDevInfo,
					&ifcData, pDetData, dwDetDataSize, NULL, &devdata);
				if (bOk) {
					std::string strDevPath(pDetData->DevicePath);
					// Got a path to the device. Try to get some more info.
					TCHAR fname[256];
					TCHAR desc[256];
					BOOL bSuccess = SetupDiGetDeviceRegistryProperty(
						hDevInfo, &devdata, SPDRP_FRIENDLYNAME, NULL,
						(PBYTE)fname, sizeof(fname), NULL);
					bSuccess = bSuccess && SetupDiGetDeviceRegistryProperty(
						hDevInfo, &devdata, SPDRP_DEVICEDESC, NULL,
						(PBYTE)desc, sizeof(desc), NULL);
					BOOL bUsbDevice = FALSE;
					TCHAR locinfo[256];
					if (SetupDiGetDeviceRegistryProperty(
						hDevInfo, &devdata, SPDRP_LOCATION_INFORMATION, NULL,
						(PBYTE)locinfo, sizeof(locinfo), NULL))
					{
						// Just check the first three characters to determine
						// if the port is connected to the USB bus. This isn't
						// an infallible method; it would be better to use the
						// BUS GUID. Currently, Windows doesn't let you query
						// that though (SPDRP_BUSTYPEGUID seems to exist in
						// documentation only).
						bUsbDevice = (strncmp(locinfo, "USB", 3) == 0);
					}
					// Open device parameters reg key - Added after fact from post on CodeGuru - credit to Peter Wurmsdobler
					HKEY hKey = SetupDiOpenDevRegKey
						(hDevInfo, &devdata, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ);

					TCHAR szPortName[MAX_PATH];
					if (hKey)
					{
						DWORD dwType = REG_SZ;
						DWORD dwReqSize = sizeof(szPortName);

						// Query for portname
						long lRet = RegQueryValueEx
							(hKey, "PortName", 0, &dwType, (LPBYTE)&szPortName, &dwReqSize);
						if (lRet == ERROR_SUCCESS)
							bSuccess &= TRUE;
						else
							bSuccess &= FALSE;
					}
					else
						bSuccess &= FALSE;

					if (bSuccess) {
						// Add an entry to the array
						SerialPortInfo si;
						si.szDevPath = strDevPath;
						si.szFriendlyName = fname;
						si.szPortName = szPortName;
						si.szPortDesc = desc;
						si.bUsbDevice = (bUsbDevice==TRUE);
						serialports.push_back(si);
					}

				}
				else {
					return;
				}
			}
//.........这里部分代码省略.........
开发者ID:CondormanFr,项目名称:domoticz,代码行数:101,代码来源:WindowsHelper.cpp


注:本文中的SetupDiGetDeviceRegistryProperty函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。