Using C++ and native Win32 functions, I am attempting to get the class/interface GUID of a connected device such as a TV or projector. I am using the function RegisterDeviceNotification() to give me the GUID when a TV is connected.

My Problem: When the TV is connected I can successfully be notified but when I go to access the GUID of the device(by inspecting the lParam structure) I get an access violation or error.

I cant figure out whats going wrong? Whenever I go to access or use the GUID my program fails, note my program doesn't crash but the output window writes something like First-chance exception at 0x001c1a9d in myProgram.exe... and I cant figure out whats going wrong?

MSDN says that lParam is 0 when wParam is DBT_DEVNODES_CHANGED (which IMHO, you should really assert on anyway). So your code behaves as expected -- undefined behaviour.

It appears you have copied the GUID passed to RegisterDeviceNotification from the MSDN example code. I don't know much about Windows' device handling but I have a strong suspicion that this GUID is not the one you should be using.

Have you tried adding DEVICE_NOTIFY_ALL_INTERFACE_CLASSES to the flags in your call to RegisterDeviceNotification()? In this case the GUID is ignored and you get messages for all devices. This may give you a better indication of what's really happening and help you detect your TV.

Just out of curiosity, are you attempting to detect your telly to automatically enable some kind of out-of-band debug console for a game? That would be cool

I'll try adding DEVICE_NOTIFY_ALL_INTERFACE_CLASSES and see what messages I receive.

Just out of curiosity, are you attempting to detect your telly to automatically enable some kind of out-of-band debug console for a game? That would be cool

Nah, the ultimate goal is so when I connect my laptop to the TV it will open my folder that contains all my TV shows and start playing the video file I was playing when I last disconnected from the TV(maybe even at the same position/time in the file). I'm moving into a new unit and I'm too cheap to pay for Foxtel(cable TV) so I want this application to let me play tv shows off my laptop

The code above is the first step:

- Detect a device arrival - get the class/interface GUID of the device

- Determine if the connect device is a TV (I have no idea how I'll do this but I suspect using a SetupDi..() function which is why I need the GUID)

- If the device is a TV:

- Open the tv show folder

- Start playing the video file I was playing when I last disconnected from the TV