cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 VCP: reading friendly name in c++ application

filippo
Associate II
Posted on September 16, 2014 at 16:23

I'm using a demo board (STM32F4) from STMicroelectronics, which is connected to my laptop, where my c++ application is running, with a Virtual COM Port driver (usb cable). I'm trying to read the friendlyname of the device by using the SetupAPI.

Here is the code:

DEFINE_GUID(GUID_CLASS_COMPORT, 0x86e0d1e0L, 0x8089, 0x11d0, 0x9c, 0xe4, \ 0x08, 0x00, 0x3e, 0x30, 0x1f, 0x73); ... std::string strFriendlyNames; res = FALSE; GUID* guidDev = (GUID*) &GUID_CLASS_COMPORT; HDEVINFO hDevInfo = INVALID_HANDLE_VALUE; SP_DEVICE_INTERFACE_DETAIL_DATA* pDetData = NULL; hDevInfo = SetupDiGetClassDevs(guidDev, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); 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]; ifcData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); pDetData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); while (bOk) { DWORD i = 0; bOk = SetupDiEnumDeviceInterfaces(hDevInfo, NULL, guidDev, i, &ifcData); DWORD dwError = _rOS_GetLastError(); if (bOk) { SP_DEVINFO_DATA devdata = {sizeof(SP_DEVINFO_DATA)}; bOk = SetupDiGetDeviceInterfaceDetail(hDevInfo, &ifcData, pDetData, dwDetDataSize, NULL, &devdata); if (bOk) { TCHAR fname[256]; TCHAR desc[256]; BOOL bSuccess = SetupDiGetDeviceRegistryProperty(hDevInfo, &devdata, SPDRP_FRIENDLYNAME, NULL, (PBYTE)fname, sizeof(fname), NULL); if (bSuccess) { strFriendlyNames = fname; } } } i++; }

The SetupDiEnumDeviceInterfaces function is returning 0 with the ''ERROR_NO_MORE_ITEMS'' error. Am I doing something wrong? My device is under ''COM Port'' in the Device Manager, that's why I'm using the GUID_CLASS_COMPORT device. Thank you.

0 REPLIES 0