Click here to Skip to main content
15,889,849 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I get more information about the device when my Form Application receives the WM_DEVICECHANGE message with wParam set to DBT_DEVNODES_CHANGED and lParam set to zero? I just know MSDN says Applications that require more information should register for device notification using the RegisterDeviceNotification function.How can I work out this problem by using registerDeviceNotification or some other way.Can you give me some codes or tips.Thanks advancely.


Here are some code.


protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_DEVICECHANGE)
{
if (m.WParam.ToInt32() == DBT_DEVNODECHANGE)
{
if (test != null && test.IsAlive)
{
return;
}

Thread.Sleep(1000);
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
test = new Thread(new ThreadStart(this.startTest));
test.Start();
adbBtn.Enabled = false;
UartDebugBtn.Enabled = false;
SN.Text = "";
}
}
}
Posted
Updated 21-Jan-15 19:12pm
v2

1 solution

As the documentation clearly states, you need to implement https://msdn.microsoft.com/en-us/library/windows/desktop/aa363431(v=vs.85).aspx[^].
 
Share this answer
 
Comments
Member 11175072 21-Jan-15 21:28pm    
I had read this article,it is written in C++ which is new to me,what's more,I can only receive the WM_DEVICECHANGE message with wParam set to DBT_DEVNODES_CHANGED and lParam set to zero,Can I get more infomation about the device by using DEV_BROADCAST_HDR structure and checking its dbch_devicetype member?.I want to be notified when the device was plugged out the PC.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900