0

enter image description here

how to get the serial port name by my red pen. Not COM5.COM5 can be gotten by windows-API. If you know it, please let me know. I'll appreciate it!

enter image description here Now, I can get both serial ports full name and COMX. But which is true? I know how to find true one by manual manipulation instead of my coding program. But how to find true one by my coding program.

enter code here
 GUID classGuids = {0x4D36E978L, 0xE325, 0x11CE, 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18};   //GetClassGUIDs("ports");   //&GUID_DEVCLASS_PORTS

HDEVINFO hDevInfo = SetupDiGetClassDevs((LPGUID)&classGuids, NULL, NULL, 0);
if(hDevInfo)
{
    SP_DEVINFO_DATA SpDevInfo={sizeof(SP_DEVINFO_DATA)};
    for(DWORD iDevIndex=0; SetupDiEnumDeviceInfo(hDevInfo, iDevIndex, &SpDevInfo); iDevIndex++)
    {      
        TCHAR szName[512] = {0};
        if(SetupDiGetDeviceRegistryProperty(hDevInfo, &SpDevInfo, SPDRP_FRIENDLYNAME, 
            NULL, (PBYTE)szName, sizeof(szName), NULL))
        {
            _tprintf(_T("........%s\n"), szName);
        }
    }

    SetupDiDestroyDeviceInfoList(hDevInfo);
roy
  • 1
  • 3
  • call [CM_Get_DevNode_PropertyW](https://msdn.microsoft.com/en-us/library/windows/hardware/hh780220(v=vs.85).aspx) with [DEVPKEY_NAME](https://learn.microsoft.com/en-us/windows-hardware/drivers/install/devpkey-name--device-interface-) – RbMm Oct 18 '17 at 08:53
  • sorry! I can't find CM_Get_DevNode_Property in my vc6++, even if I have written "include Cfgmgr32.h" in my code. And then Cfgmgr32.h can't be found in vc6++. Do you have any way of solving it? Any windows-API? Could get both of them(serial port name description and COMX)? – roy Oct 18 '17 at 09:25
  • `CM_Get_DevNode_Property` exist not in visual studio but in windows, begin from vista. and it defined `#if (WINVER >= _WIN32_WINNT_LONGHORN)` you or wrong define version or use 15+ years old sdk headers – RbMm Oct 18 '17 at 09:48
  • https://stackoverflow.com/a/2937588/17034 – Hans Passant Oct 18 '17 at 11:22
  • yeah, thank your comment and website link. I make improvement in my c++ program and update a snapshot on my question. Here it is. so how to find a true one by program instead of manual manipulation? – roy Oct 19 '17 at 03:00
  • done! Thanks a lot. – roy Oct 20 '17 at 01:41

0 Answers0