Hi,
I'd like to ask if it is possible to auto detect usb stick insertion and removal in c++? This is possible in c#, but I'd like to make it portable so creating it in c++ maybe a good choice.
If it is possible, how can I do that can you give me a clue?
void CSampleWM_MessageDlg::Main_OnDeviceChange (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam;
switch(wParam)
{
case DBT_DEVICEARRIVAL:
// See if a CD-ROM or DVD was inserted into a drive.
m_eRecieveMsgs.SetWindowText("Inserted\r\n");
break;
case DBT_DEVICEREMOVECOMPLETE:
// See if a CD-ROM was removed from a drive.
m_eRecieveMsgs.SetWindowText("Removed\r\n");
break;
default:
m_eRecieveMsgs.SetWindowText("Default\r\n"); //IT FALLS ALWAYS HERE.
}
}
The problem is when I inserted the cd/dvd the textbox(m_eRecieveMsgs) always print the Default message in the default case. It will not go inside the first case statement of the switch. This happens also when removing the cd/dvd always go through the default case.
The wParam always return a zero value even if it is an insert or remove process, this is why it always falls to the default.
Why is that? Is there something wrong with my code?
Hope you can help me on this.