I have a .Net Windows Forms Project which forms the "UI framework" for my application by creating "docks" - basically dynamically created Statics which are positioned in the main form and used as parents for newly created dialogs.

This in turn loads a COM dll which has a worker thread in it and acts as a engine for the application.

The engine in turn loads a series of COM dll plugins.

One of the plugins has a method for creating a new dialog which is intended to be a child of the main UI.

I am achieving this by the following process:

1) GUI sends notification to ENGINE to create a new Dialog

2) ENGINE notifies plugin to create new dialog by calling myPlugin->AddNewDlg()

3) AddNewDlg() method in PLUGIN makes a "CreateNewDock(ptr)" call to ENGINE

4) ENGINE in turn notifies GUI to create a new dock - this returns a Handle to the dock by setting ptr = newdock->Handle

5) The Plugin now has a handle to the newly created dock which it can use as a parent when creating a new child dialog.

In the GUI i am setting the handle ptr from the Plugin by doing the following:

Code:
*pHandle =  m_pNewDock->Handle.ToInt64();
The code in the plugin for creating a new dialog is:

Code:
AddNewDlg()
{
      LONG nHandle = 0;
       // notify engine to Create new dock in the GUI and get a handle to new dock

      m_pEngine->AddNewPanel(&nHandle); 
      // Create a pointer to a window from the parent handle

      CWnd *pWnd = CWnd::FromHandle((HWND)nHandle);
      // Create new dialog

     m_NewDlg->Create(IDD_DLG,pWnd);
     m_NewDlg->ShowWindow(SW_MAXIMIZE);
}
This all works fine when I add a new dialog by within the main app thread - i.e. if i add I call ENGINE->AddNewDlg() in an onclick event for a button on the main GUI form.

The problem is I need to create a new dialog from the worker thread in the ENGINE, when I do this however the application wipes out.

I think it may be something to do with the way i am retrieving a handle from the GUI for a newly created dock.

Please Help