5

I've been reading a lot of posts on SO about this but all of them are either in C# or MFC. I'm using the normal windows libraries and not the MFC shared libraries nor ATL.

I can easily enumerate the available COM ports but I don't know how to obtain the description as, for example, seen in the Device Manager within Windows. I've been reading through the MSDN and the closest I've come is SetupDiGetDeviceRegistryProperty() but I'd imagine there must be a quick way to do this. I've also found that Qt has QextSerialEnumerator::getPorts() but since I'm not using Qt I was hoping there would be something similar available from the WinAPI.

If someone has a snippet for doing so it would be greatly appreciated.

Yonathan
  • 1,253
  • 1
  • 17
  • 29
  • I hope this will help you http://stackoverflow.com/questions/6642633/wmi-get-usb-device-description-on-insertion – Vilva Nov 08 '11 at 15:15
  • Thank you but again, I'm not using C# or any .NET for that matter. I know C# has some really simplified and easy-to-use static classes for the port description and all other information but I can't use this because I'm not using that language. – Yonathan Nov 08 '11 at 15:59
  • The quick way is SetupDiGetDeviceRegistryProperty(), with the SPDRP_FRIENDLYNAME property. – tinman Nov 08 '11 at 16:58

2 Answers2

1

First of all, what kind of description are you really need? You can obtain different info about COM-ports by EnumPorts() & Registry-way. For example, registry-way will show virtual COM-port - this one EnumPorts can't do. The second thing - there is 9 different ways of enumerating COM-ports. The examples of their usage is here - http://www.naughter.com/enumser.html (i've used some code from here in my project). Also, note that the author use many msvc-specific features - atl containers for memory allocating and etc.

Valentin H
  • 7,240
  • 12
  • 61
  • 111
Roman Kr
  • 80
  • 2
  • I've looked at the code from enumser already but it is really MSVC specific with ATL, like you said. The description I want it the one you see when you check the properties of any device in the device manager and look at Description. For my arduino, for example, it says "Arduino UNO". – Yonathan Nov 08 '11 at 15:55
  • I've also looked in the registry but this will say //device/bla and not the description the device has. – Yonathan Nov 08 '11 at 15:56
  • ATL containers are used here, in general, only for memory allocating. I have replaced them successfuly with "new" because i don't really like to use ATL. – Roman Kr Nov 08 '11 at 16:12
  • and registry-way can obtain whole information about registry key that you can see in regedit. I don't really know how to get an arduino name, but i know exactly that in enumser output of methods reduced to COM ID. If you modify enumser a little, you will got what you want. – Roman Kr Nov 08 '11 at 16:17
  • I've obtained the name from the registry but this is not the name from the device manager. I've been looking at enumser for a while now but it is really dependent on MFC classes. – Yonathan Nov 08 '11 at 16:27
0

All i can say is don't use the setupDI WDM functions if you don't know EXACTLY what you are doing, this is way back for me but check the windows DDK samples i think the dll implementation you see in device manager is in /ports...

The issue is that serial ports are very very old, so they've been dragged through the ages and hacked together into windows 7, so for example when you make a change to a COM port then you have to write to win.ini, but win.ini doesn't exist (wtf i hear you say) that's because any "changes" get bounced back into the registry.

Any how, good luck..

Pepe
  • 405
  • 5
  • 12
  • Yeah I've been reading up on it and indeed it seems that its a bit of an issue regarding to this. But however, for what I'm trying to achieve ( a simplified serial-port communication library ) I am in need of their properties. Basically I'm trying to build a list of the com devices including description so a user can select one from a dropdown menu. – Yonathan Nov 08 '11 at 15:58