How to get com port properties in windows using the Win32 API

Get com port

In the previous article, I have described how we can find the Com Port Id of a USB Serial device (Arduino) with the help of VID and PID. If you have not seen this article you can read it, how to get Com Port Id of a USB Serial device.

In this article, I will describe how we can get com port properties using the win32 API. In windows, all Com Port properties (Baud rate, stop bit etc) is stored in the window registry. So to get the com properties you just need to read the windows registry.

I have already written an article, how we can read and write the Windows registry using the win32 API. If you are new and don’t know how to access the window registry using the win32 API. You can see this article, Access windows registry using the win32 API.

If you want to learn more about the Windows Internals or another technology, here 10 Free days trial for you.

So let us come on the topic and see example code. In this example, I am reading the com port setting (baud rate, stop bit ..etc) using the win32 API.

For better indentation double click on the code,

 

See the below image if you will run the above code, you will get the all the setting.

get port setting using win32 api

 

After running the code,

get port setting using win32 api

 

get port setting using win32 api

After running the code,

Get port setting win32 api



Leave a Reply