I am listing all the USB devices connected to the system in the GUI which in C#.
I am calling function in C++ DLL to list all the USB's.
Now If any device get removed or added to the system then I have to reflect those changes on to the GUI.
How should I get such notification and again call my ListUSB function to refresh GUI part.
But I am confusing how can I write a program which will notify any change has happened and as a result go for refreshing my GUI with currently attached USB's.
I am confusing that how we can achieve this. Please suggest the way
public partial class Form1 : Form
{
// Constant value was found in the "windows.h" header file.
privateconstint WM_DEVICECHANGE = 0x0219;
public Form1()
{
InitializeComponent();
}
protected override void WndProc(ref System.Windows.Forms.Message theMessage)
{
switch (theMessage.Msg)
{
case WM_DEVICECHANGE:
MessageBox.Show("Device changed", "WM_DEVICECHANGE");
break;
}
base.WndProc(ref theMessage);
}
}
code: c#
Instead of MessageBox.Show() you would do whatever it is you need to refresh the form.
Yes I found this solution earlier. But when I want to do this in C++ and send the notification to the
GUI that change has happened. Then what would be the solution.
I think GUI will call one callback Function which will check for any change happen, once the change is happened the GUI get notified and perform the refreshing task.
I am trying in this way but I don't know, is this solution is feasible or not.