Question

From inside my COM addin I create a dialog, and I then send messages to it from an external process. I use HWND_BROADCAST and RegisterWindowMessage.

But those messages are never received by the dialog proc of the COM addin. I know this because I log all the messages received by the dialog proc, and also the value returned by RegisterWindowMessage.

From the external process:

static UINT nCloseMessage = 0;
if (!nCloseMessage)
    nCloseMessage = RegisterWindowMessage(_T("MyCloseMessage"));    
PostMessage(HWND_BROADCAST, nCloseMessage, 0, 0);

From the COM add-in:

INT_PTR CALLBACK ProgressDialogProc(__in  HWND hwndDlg,__in  UINT uMsg,__in  WPARAM wParam,__in  LPARAM lParam)
{
    static UINT nCloseMessage = 0;
    if (!nCloseMessage)
        nCloseMessage = RegisterWindowMessage(_T("MyCloseMessage"));    
    if (uMsg == nCloseMessage)
        MessageBox(0,_T("Caught"),0,0);

    return FALSE;
}
Was it helpful?

Solution

I found why I get this error, HWND_BROADCAST doesn't work when the dialog has a parent window.

Passing NULL to CreateDialog for the parent fixed the error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top