在 MFC 中创建 CPaneDialog 时断言失败
Assertion failed when creating CPaneDialog In MFC
我有一个简单的 .exe MFC 项目和一个静态链接的 MFC 的 DLL 项目。它导出以下函数以创建 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);
}
我从我的主.exe应用程序类(派生自 CWinAppEx
)调用它,如下所示:
// dll is a handle to the DLL lib
ToolboxInitFunc func = (ToolboxInitFunc)GetProcAddress(dll, "init_toolbox_gui");
func(m_pMainWnd->GetSafeHwnd());
这在以下调试断言中失败,void CMFCDragFrameImpl::Init(CWnd* pDraggedWnd)
:
m_pDockManager = afxGlobalUtils.GetDockingManager(pDockSite);
ENSURE(m_pDockManager != NULL);
我可以给出该函数的完整代码,但它来自标准 MFC 库。
这是调用堆栈:
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++
可能出了什么问题?
不能"独立"使用对接功能。
这种对接的东西需要一个专门准备的CFrameWndEx类。如果 MFC 项目使用此类,则当您要使用 DLL 时,将强制使用动态链接的 MFC。
您获得的 ASSERT 只是一个指标,表明当前模块(您的 DLL)既没有框架也没有停靠管理器来支持此类可停靠窗格。
原因很简单。静态链接的 EXE 和 DLL 将只使用自己的 CObject 表示形式,因此 MFC 内部使用的所有 IsKindOf 调用都只能在模块内部工作。
相关文章:
- 尝试使用 std::vector<std::thread时出现静态断言失败错误>
- uint_not_usable_without_attribute在业力规则中使用数字生成器时静态断言失败
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- 在 CppUnit 中测试中止断言失败
- 使用扫描的调试断言失败
- 为什么我的Qt程序在断言失败后继续运行?
- 图片不显示,关闭时出错 --> 调试断言失败!表达式:is_block_type_valid(标头>_block_use)
- 访问提升:shared_ptr 主范围外崩溃,断言失败:px != 0.指针的正确用法是什么?
- C++ 调试断言失败 - 矢量下标超出视觉工作室的范围
- 错误:断言失败 (src.type() == CV_8UC1) 在阈值中
- Boost Beast 异步服务器失败,断言失败:(id_ != T::id) 在多个 aync 调用中
- 使用imwrite OpenCV时断言失败
- 调试断言失败的缓冲区!=nullptr
- 使用 ofstream 写入文本文件时断言失败
- 提升继续恢复断言失败
- 获取有关调试断言失败的错误:表达式:"(_Ptr_user &(_BIG_ALLOCATION_ALIGNMENT -1)) == 0" &&0
- OpenCV(3.4.1) 错误:断言失败(变暗 <= 2 && step[0] > 0) in cv::Mat::locateROI
- 在Win10上使用带有Qt5的OpenCV3.0,调试断言失败
- MFC GetDC() 断言失败 - "Not a window"
- OpenCV 错误:断言失败 - 矩阵减去