 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Uri Guest
|
Posted: Tue Oct 17, 2006 5:57 pm Post subject: OnDeviceChange Problem |
|
|
Hi, when I connect OR disconnect the USB connector I reach the
breakpoint in function "OnDeviceChange", but the parameters
of 'm' are stay the same (it is not right), why?
Thanks.
public: // User declarations
__fastcall TUSBApp_form(TComponent* Owner);
// Overriding a message handle
//Messages::TMessage message;
void OnDeviceChange(Messages::TMessage );
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DEVICECHANGE , Messages::TMessage , OnDeviceChange)
END_MESSAGE_MAP(TComponent)
//---------------------------------------------------------------
void TUSBApp_form::OnDeviceChange(Messages::TMessage m)
{
//USBC->OnDeviceChange(m);
return; // Breakpoint Here
} |
|
| Back to top |
|
 |
Michel Leunen Guest
|
Posted: Tue Oct 17, 2006 7:38 pm Post subject: Re: OnDeviceChange Problem |
|
|
Uri wrote:
| Quote: | Hi, when I connect OR disconnect the USB connector I reach the
breakpoint in function "OnDeviceChange", but the parameters
of 'm' are stay the same (it is not right), why?
void TUSBApp_form::OnDeviceChange(Messages::TMessage m)
|
You have to test against m.WParam. Something like:
switch(m.WParam)
{
case DBT_DEVICEARRIVAL:
//a new device has been inserted
break;
case DBT_DEVICEREMOVECOMPLETE:
//a device has been removed
break;
}
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
http://www.leunen.com/
---------------------------------------- |
|
| Back to top |
|
 |
Uri Guest
|
Posted: Tue Oct 17, 2006 7:45 pm Post subject: Re: OnDeviceChange Problem |
|
|
I tried that, it's not working, every time when the function is
call (when I connect or remove the USB device from the PC) the
parameter 'm.WParam' stay 7 (m.WParam = 7) Why does it not chaning?
Uri.
| Quote: | You have to test against m.WParam. Something like:
switch(m.WParam)
{
case DBT_DEVICEARRIVAL:
//a new device has been inserted
break;
case DBT_DEVICEREMOVECOMPLETE:
//a device has been removed
break;
}
Michel |
|
|
| Back to top |
|
 |
Bob Gonder Guest
|
Posted: Tue Oct 17, 2006 9:08 pm Post subject: Re: OnDeviceChange Problem |
|
|
Uri wrote:
| Quote: | I tried that, it's not working, every time when the function is
call (when I connect or remove the USB device from the PC) the
parameter 'm.WParam' stay 7 (m.WParam = 7) Why does it not chaning?
|
Look in DBT.H
7 is DBT_DEVNODES_CHANGED which you should be ignoring as Michel
pointed out.
| Quote: | switch(m.WParam)
{
case DBT_DEVICEARRIVAL:
//a new device has been inserted
break;
case DBT_DEVICEREMOVECOMPLETE:
//a device has been removed
break;
}
Michel
|
Just a thought:
It could be that the mystery device you are unplugging isn't supposed
to report device arrival/removed. You might ask the manufacturer. |
|
| Back to top |
|
 |
Michel Leunen Guest
|
Posted: Tue Oct 17, 2006 9:12 pm Post subject: Re: OnDeviceChange Problem |
|
|
Uri wrote:
| Quote: | I tried that, it's not working, every time when the function is
call (when I connect or remove the USB device from the PC) the
parameter 'm.WParam' stay 7 (m.WParam = 7) Why does it not chaning?
|
That's a DBT_DEVNODES_CHANGED. According to MSDN :
"The system broadcasts the DBT_DEVNODES_CHANGED device event when a
device has been added to or removed from the system."
It seems there is no way to know if the device has been added or removed
from the system.
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
http://www.leunen.com/
---------------------------------------- |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Oct 17, 2006 10:04 pm Post subject: Re: OnDeviceChange Problem |
|
|
"Uri" <Uri (AT) MyMail (DOT) com> wrote in message
news:4534d31d$1 (AT) newsgroups (DOT) borland.com...
| Quote: | void OnDeviceChange(Messages::TMessage );
|
Just an FYI, in a message map, you need to pass TMessage by reference, not
by value, just like when overriding WndProc():
void __fastcall OnDeviceChange(Messages::TMessage &);
Gambit |
|
| Back to top |
|
 |
Uri Guest
|
Posted: Wed Oct 18, 2006 5:41 pm Post subject: Re: OnDeviceChange Problem |
|
|
No, it's not working either.... when I insert or remove my USB
device the 'WMDiskChange' function is call several times but at
each call I see in the debuger that Message.WParam = 7, when I
insert, or when I remove the USB connector of the device.
Any idea why? can it be a problem in the device itself?
Here is my last code -
void __fastcall WMDiskChange( TMessage &Message );
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER( WM_DEVICECHANGE, TMessage, WMDiskChange )
END_MESSAGE_MAP( TControl )
void __fastcall TForm1::WMDiskChange( TMessage &Message )
{
int Value;
Value = Message.WParam;
Value = Value; // I set my breakpoint here
}
| Quote: | Just an FYI, in a message map, you need to pass TMessage by reference, not
by value, just like when overriding WndProc():
void __fastcall OnDeviceChange(Messages::TMessage &);
Gambit |
|
|
| Back to top |
|
 |
Uri Guest
|
Posted: Wed Oct 18, 2006 5:48 pm Post subject: Re: OnDeviceChange Problem |
|
|
| Quote: | Just a thought:
It could be that the mystery device you are unplugging isn't supposed
to report device arrival/removed. You might ask the manufacturer.
|
How can the device send 'removed' report when I remove it?
I mean, when I remove it, I disconnect the USB cable, so the
device can't send anything becouse the cable is not connected
any more to the PC..... am I wrong?
Uri. |
|
| Back to top |
|
 |
Michel Leunen Guest
|
|
| Back to top |
|
 |
Uri Guest
|
Posted: Wed Oct 18, 2006 6:44 pm Post subject: Re: OnDeviceChange Problem |
|
|
Hi, I did not understand how to use it... from where do I call
to this function?
what is the 'GUID InterfaceClassGuid' parameter from where do I
take it?
Where exactly 'hWnd' get it's value?
Where do I find the defenition of DEV_BROADCAST_DEVICEINTERFACE ?
Which paarmeter shows me if the device was Inserted or Removed ?
Thanks. |
|
| Back to top |
|
 |
Uri Guest
|
Posted: Wed Oct 18, 2006 7:20 pm Post subject: Re: OnDeviceChange Problem |
|
|
I tried the following, 'NotificationFilter' data looks exactly
the same for 'Insert' or 'Remove'.
also, I did not know from where to take
'NotificationFilter.dbcc_classguid' data.
Thanks.
void __fastcall TForm1::WMDiskChange( TMessage &Message )
{
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
char szMsg[80];
ZeroMemory( &NotificationFilter, sizeof( NotificationFilter ) );
NotificationFilter.dbcc_size = sizeof( DEV_BROADCAST_DEVICEINTERFACE );
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
//NotificationFilter.dbcc_classguid = InterfaceClassGuid; // ? ? ? ? ?
RegisterDeviceNotification( Application->Handle, &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE );
} |
|
| Back to top |
|
 |
Michel Leunen Guest
|
|
| Back to top |
|
 |
Michel Leunen Guest
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Oct 18, 2006 9:45 pm Post subject: Re: OnDeviceChange Problem |
|
|
"Uri" <Uri (AT) nomail (DOT) com> wrote in message
news:453622af$1 (AT) newsgroups (DOT) borland.com...
| Quote: | How can the device send 'removed' report when I remove it?
I mean, when I remove it, I disconnect the USB cable, so the
device can't send anything becouse the cable is not connected
any more to the PC..... am I wrong?
|
The device itself is not the one sending the notifications. The OS is, in
response to the device driver reporting that the device is
attached/detached.
Gambit |
|
| Back to top |
|
 |
Michel Leunen Guest
|
Posted: Wed Oct 18, 2006 10:46 pm Post subject: Re: OnDeviceChange Problem |
|
|
Uri wrote:
| Quote: | Hi, I did not understand how to use it.
|
Ok, I tried with my usb key and it works.
RegisterDeviceNotification() tells the OS to send to your app the
notification messages you want. Without this as you've noted, you don't
receive the arrival or removal of your device.
First add this to your form constructor:
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter = {0};
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
NotificationFilter.dbcc_classguid = GUID_DEVCLASS_USB;
RegisterDeviceNotification(Handle,
&NotificationFilter,
DEVICE_NOTIFY_WINDOW_HANDLE);
And then in your message handler (WndProc or whatever):
if(Message.Msg == WM_DEVICECHANGE)
{
switch(Message.WParam)
{
case DBT_DEVICEARRIVAL:
Application->MessageBox("Arrival","USB",MB_OK);
break;
case DBT_DEVICEREMOVECOMPLETE:
Application->MessageBox("Removal","USB",MB_OK);
break;
}
}
Don't know if it works for any USB devices but at least it works for my
usb key.
HTH
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
http://www.leunen.com/
---------------------------------------- |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|