I have a simple .exe MFC project and a DLL project with MFC statically linked. It exports the following function for creating a CPaneDialog:
extern "C" __declspec(dllexport) void init_toolbox_gui(HWND ptr) {
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CPaneDialog *_gui = new CPaneDialog;
CWnd *p = CWnd::FromHandle(ptr);
_gui->Create(_T("DialogBar"), p, TRUE, (IDD_DIALOG1),
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI,
0);
}
I call this from my main .exe app class (derived from CWinAppEx
) as follows:
// dll is a handle to the DLL lib
ToolboxInitFunc func = (ToolboxInitFunc)GetProcAddress(dll, "init_toolbox_gui");
func(m_pMainWnd->GetSafeHwnd());
This fails in the following debug assertion, in void CMFCDragFrameImpl::Init(CWnd* pDraggedWnd)
:
m_pDockManager = afxGlobalUtils.GetDockingManager(pDockSite);
ENSURE(m_pDockManager != NULL);
I can give the full code of that function but it is from standard MFC libraries.
This is the call stack:
toolbox-3d.dll!CMFCDragFrameImpl::Init(CWnd * pDraggedWnd) Line 106 C++
toolbox-3d.dll!CPane::CreateEx(unsigned long dwStyleEx, const wchar_t * lpszClassName, unsigned long dwStyle, const tagRECT & rect, CWnd * pParentWnd, unsigned int nID, unsigned long dwControlBarStyle, CCreateContext * pContext) Line 177 C++
toolbox-3d.dll!CDockablePane::CreateEx(unsigned long dwStyleEx, const wchar_t * lpszCaption, CWnd * pParentWnd, const tagRECT & rect, int bHasGripper, unsigned int nID, unsigned long dwStyle, unsigned long dwTabbedStyle, unsigned long dwControlBarStyle, CCreateContext * pContext) Line 175 C++
toolbox-3d.dll!CDockablePane::Create(const wchar_t * lpszWindowName, CWnd * pParentWnd, CSize sizeDefault, int bHasGripper, unsigned int nID, unsigned long dwStyle, unsigned long dwTabbedStyle, unsigned long dwControlBarStyle) Line 148 C++
toolbox-3d.dll!CPaneDialog::Create(const wchar_t * lpszWindowName, CWnd * pParentWnd, int bHasGripper, const wchar_t * lpszTemplateName, unsigned int nStyle, unsigned int nID, unsigned long dwTabbedStyle, unsigned long dwControlBarStyle) Line 48 C++
toolbox-3d.dll!CPaneDialog::Create(const wchar_t * lpszWindowName, CWnd * pParentWnd, int bHasGripper, unsigned int nIDTemplate, unsigned int nStyle, unsigned int nID) Line 42 C++
toolbox-3d.dll!init_toolbox_gui(HWND__ * ptr) Line 45 C++
What could be wrong?