[StructLayout(LayoutKind.Explicit)]
private struct DevBroadcastDeviceInterfaceBuffer {
public DevBroadcastDeviceInterfaceBuffer(Int32 deviceType) {
dbch_size = Marshal.SizeOf(typeof(DevBroadcastDeviceInterfaceBuffer));
dbch_devicetype = deviceType;
dbch_reserved = 0;
}
[FieldOffset(0)] public Int32 dbch_size;
[FieldOffset(4)] public Int32 dbch_devicetype;
[FieldOffset(8)] public Int32 dbch_reserved;
}
Declare Function DevBroadcastDeviceInterfaceBuffer Lib "user32.dll" (TODO) As TODO
None.
Do you know one? Please contribute it!
None.
Please add some!
try {
mem = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DevBroadcastDeviceInterfaceBuffer)));
Marshal.StructureToPtr(new DevBroadcastDeviceInterfaceBuffer(5), mem, false);
RegisterDeviceNotification(YOUR_HANDLE_HERE_D00D, mem, 0);
// Sure hope you overrode your WndProc function
}
catch (Exception e) {
//Log this
}
finally {
Marshal.FreeHGlobal(mem);
}