Re: How to inform application (attach/detach device)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Robin Holenweger (holi_at_nospam.com)
Date: 07/27/04


Date: Tue, 27 Jul 2004 14:07:25 +0200

Bill McKenzie wrote:
> You can register for PnP notifications. See RegisterDeviceNotification in
> the Platform SDK documentation.

Thanks, that helps already a lot.

When reading and implementing, I found out something weird: for
RegisterDeviceNotification() I should fill a structure depending on what
device I want to register for. All structures have an equal "header
part" (DEV_BROADCAST_HDR), followed by type specific stuff.

As I need to get informed about a logical COM port, I chose the type
DBT_DEVTYP_PORT.

structure:
typedef struct _DEV_BROADCAST_PORT {
   DWORD dbcp_size;
   DWORD dbcp_devicetype;
   DWORD dbcp_reserved;
   TCHAR dbcp_name[1];
} DEV_BROADCAST_PORT *PDEV_BROADCAST_PORT;

description:
dbcp_name
Pointer to a null-terminated string specifying the friendly name of the
port or the device connected to the port. Friendly names are intended to
help the user quickly and accurately identify the device—for example,
"COM1" and "Standard 28800 bps Modem" are considered friendly names.

Resulting question: how the heck shall I store such a described
"friendly name" in a TCHAR array of size 1??? Is there a trick? As far
as I understand, dbcp_name is a 8-bit value, whereas I would need a
32-bit value (TCHAR*) to store a pointer to such a "friendly name".

Many thanks

Robin



Relevant Pages