I have done this with C++ but the messages and parameters can be handled similar with C#.
There will be specific messages for serial and parallel ports:
- Check that
LPARAM
is not NULL - Cast the
LPARAM
to PDEV_BROADCAST_PORT
- Check if the
dbcp_devicetype
member is DBT_DEVTYP_PORT
- Check the
dbcp_name
member if it begins with 'COM'. It contains the serial port name as COMx.
The above messages are send with
DBT_DEVICEARRIVAL
and
DBT_DEVICEREMOVECOMPLETE
upon insertion / removal.
Use the detected serial port name to retrieve additional information about the serial port.