tags:

views:

43

answers:

1

Hi,

We are working on a USB device program. Following code snippet is my UsbComponent class. It works fine under windows XP or even windows 64 32bit. But under windows 7 64bit, PreFilterMessage never gets entered whenever I plugin/remove our USB device. Did I miss anything to make following code working under windows 7 64bit?

using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;

public partial class UsbComponent : Component, IMessageFilter {
      private const int WM_DEVICECHANGE = 0x219;

      public UsbComponent() {
        InitializeComponent();
        Application.AddMessageFilter( this );
      }

      public UsbComponent( IContainer container ) {
        container.Add( this );
        InitializeComponent();
        Application.AddMessageFilter( this );
      }

      bool IMessageFilter.PreFilterMessage( ref Message m ) {
        if( m.Msg == WM_DEVICECHANGE ) {
          MessageBox.Show("device changed");
          return true;
        }
        return false;
      }
}
A: 

It is the responsibility of the device driver to broadcast WM_DEVICECHANGE. Make sure you have the updated drivers for that device and verify that the device supports Windows 7

SwDevMan81
I changed code to use form's WndProc to get WM_DEVICECHANGE, and it just work fine, but not when using IMessageFilter in component. I guess device driver did broadcast WM_DEVICECHANGE under windows 7 64bit.
Allex