title: Window messages across dll boundary
body: <p>I have a GUI that uses a DLL for real-time comms. In order that the DLL can pass unsolicited information to the GUI, a pointer to a notification object is passed to the DLL on initialisation. This works fine, except now I need this notification object to trigger a GUI update in the main thread (the notification pointer can be used from several threads spawned by the DLL). I'm attempting this by having the notification object signal the GUI thread via SendNotifyMessage(). All seems fine except that the message never seems to arrive in the GUI thread ...</p>
  
  <p>Apologies for not having the actual code available (I'm not currently on the same PC), but to illustrate:</p>
  
  <pre><code>//Main GUI thread:
  pNotifier-&gt;hWnd = this-&gt;GetSafeHwnd();
  InitDll(pNotifier);
  
  //DLL (in a locally spawned thread):
  pNotifier-&gt;TriggerGUIEvent(x);
  
  //Back in GUI code (but now in a different thread):
  void notifier::TriggerGUIEvent(int x)
  {
    //This returns non-zero (success).
    ::SendNotifyMessage(hWnd, WM_MY_MESSAGE, x, NULL);
  }
  
  //Back in the main GUI thread:
  ON_MESSAGE(WM_MY_MESSAGE, OnMyMessage)
  
  LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam)
  {
    //Break point here never gets hit???
  }
  </code></pre>
  
  <p>This is C++/MFC by the way. The DLL itself is C++ only.</p>
  
  <p>I've done bits and bobs of Windows programming but it's not really my forte. Does anyone know what I'm missing here? Does the fact that the call to SendNotifyMessage() originates from another thread created on the other side of the DLL boundary somehow invalidate the message or window handle?</p>
  
  <p>Thanks.</p>