none
How to process Windows Message in Managed C++? RRS feed

  • Question

  • Hi,

    I'm trying to process the WM_DEVICECHANGE message in a managed C++ DLL. I need to convert the windows notification into a .NET event.

    My problem is that when try to compile a program that uses the DefWindowProc function it doesn't link on that function.

    First I'm trying to do that in a simple managed C++ console application not using MFC or ATL.

    I tryed to create the same project non CLR and it compiles properly.

    Maybe this is not the proper way to process a windows message in a .NET application. Some help would be appreciated on that topic.

    Thks
    Olivier

    Software Architect, Advanced IT Tokens Team - Gemalto
    Wednesday, June 11, 2008 5:45 AM

Answers

  • A console application is not exactly the greatest exe model for doing this.  Use a Windows Forms app.  You can override the form's OnWndProc() method to see the messages.  For example:

        protected override void SetVisibleCore(bool value) {  
          // Prevent window from getting visible  
          value = false;  
          base.SetVisibleCore(value);  
        }  
        protected override void WndProc(ref Message m) {  
          if (m.Msg == 0x219) {  
            // WM_DEVICECHANGE, do your stuff  
          }  
          base.WndProc(ref m);  
        }  
     

    Hans Passant.
    • Marked as answer by Bruno Yu Monday, June 16, 2008 3:14 AM
    Wednesday, June 11, 2008 4:21 PM
    Moderator
    • Marked as answer by Bruno Yu Monday, June 16, 2008 3:14 AM
    Wednesday, June 11, 2008 6:05 PM

All replies

  • A console application is not exactly the greatest exe model for doing this.  Use a Windows Forms app.  You can override the form's OnWndProc() method to see the messages.  For example:

        protected override void SetVisibleCore(bool value) {  
          // Prevent window from getting visible  
          value = false;  
          base.SetVisibleCore(value);  
        }  
        protected override void WndProc(ref Message m) {  
          if (m.Msg == 0x219) {  
            // WM_DEVICECHANGE, do your stuff  
          }  
          base.WndProc(ref m);  
        }  
     

    Hans Passant.
    • Marked as answer by Bruno Yu Monday, June 16, 2008 3:14 AM
    Wednesday, June 11, 2008 4:21 PM
    Moderator
    • Marked as answer by Bruno Yu Monday, June 16, 2008 3:14 AM
    Wednesday, June 11, 2008 6:05 PM