Capturing window messages generated by an MFC application in a simple C ++ dll

First of all: is this possible?

I have a third-party dll that interacts with some hardware. It is written in MFC. I received (from dll providers) a sample Visual Studio 2010 solution in which there is only one project: an MFC application (.exe) that calls the corresponding DLL group. It works great.

When I try to use a third-party dll from my dll (which is simple C ++, without MFC, .NET), I can call its functions fine, but there is a catch: the MFC application example seems to be “canceled”, MessageProc, to capture certain messages. generated by a third party dll. And although the dll has a function called "RegisterFuncCallback" and I use it, my callback is never called.

So here is the problem: how can I capture these messages without creating an MFC application? (Is it possible?)

+5
source share
2 answers

Ok, I did it. Here's how:

  • Create a class that inherits CWnd
  • Declare a message map linking the desired messages and their handlers.
  • When creating a window, use the CreateEx function (I did this in my class constructor) and pass the HWND_MESSAGE flag in the last but one parameter. This will create a window as a "message box", that is, invisible.
  • Once I have finished initializing the window and the MFC dll, I call RunModalLoop in my hidden window in a separate thread, as it blocks. This starts the message pump and starts receiving MFC DLL messages.

. , , , API Win32. , : Algo. , .

+5

DLL Win32, . MFC, WinAPI. MFC Win32 API. Win32, Win32.

+3

All Articles