I have some low level library code that I would like to be able to broadcast a few custom windows messages.
In the library code, the following is defined:
static UINT WM_MOTOR_WARNING_MESSAGE = 0;
extern "C" int _libmain(unsigned long reason)
{
WM_MOTOR_WARNING_MESSAGE = RegisterWindowMessage("MOTOR_WARNING_MESSAGE");
....
and the library is sending the message like this:
//Send windows message
int ret = PostMessage(HWND_BROADCAST, WM_MOTOR_WARNING_MESSAGE, 0, 0);
if(!ret)
{
Log(lError) << "Post message failed..";
}
The VCL Main form defines
UINT WM_MOTOR_WARNING_MESSAGE = RegisterWindowMessage(L"MOTOR_WARNING_MESSAGE");
and an over ridden WndProc function:
void __fastcall TMain::WndProc(TMessage& Message)
{
if (Message.Msg == WM_MOTOR_WARNING_MESSAGE)
{
MessageDlg("Turn off motor", mtInformation, TMsgDlgButtons() << mbOK, 0);
}
else
{
TForm::WndProc(Message);
}
}
The current problem seem to be that the library code, residing in a DLL, is loaded by the main application, causing the RegisterWindowMessage function to return 0 in the library. It seems you cannot have two RegisterWindowMessage calls for the same message within a single application.
So question is how to deal with this scenario? Although the Main application is using this DLL, there are other applications that could handle the library message.