如何使用在dll中创建的PropertyPage? Sheet 在Exe中。在Release 模式没有问题。在debug中有断言错误//附原码

eslea 2003-05-14 09:27:22
在dll中输出一个函数,定义如下:
CPropertyPage* GetPropertyPage()
{
::AFX_MANAGE_STATE(AfxGetStaticModuleState())
CTestPage *pTestpage=new CTestPage();
//CTestPage 从CPropertyPage派生

return (CPropertyPage*)pTestpage;
}

在EXE中使用:
typedef CPropertyPage* (*GetPage)(CPropertySheet *);

hInst=LoadLibrary("PageInDll.dll");
if (hInst==NULL)
return false;
GetSheet pGetPage=(GetPage)GetProcAddress(hInst,"GetPropertyPage");

if (pSetSheet==NULL)
{
FreeLibrary(hInst);
return false;
}

CPropertyPage* pPage=pGetPage((CPropertySheet*)&sht);

CPropertySheet sht;

sht.AddPage(pPage);

sht.DoMal();

return false;
////////
//断言错误:
#ifdef _DEBUG
CObject* AFX_CDECL AfxStaticDownCast(CRuntimeClass* pClass, CObject* pObject)
{
ASSERT(pObject == NULL || pObject->IsKindOf(pClass)); //报错
return pObject;
}
#endif

//在CPropertySheet的代码处
CPropertyPage* CPropertySheet::GetActivePage() const
{
ASSERT_VALID(this);

CPropertyPage* pPage;
if (m_hWnd != NULL)
pPage = STATIC_DOWNCAST(CPropertyPage,
CWnd::FromHandle((HWND)::SendMessage(m_hWnd, PSM_GETCURRENTPAGEHWND, 0, 0)));//这里报错!!!
else
pPage = GetPage(GetActiveIndex());
return pPage;
}


诸位,如何解决?





...全文
52 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
eslea 2003-05-14
  • 打赏
  • 举报
回复
在DoModal前,窗口还没有被创建出来,是不行的。
看mfc的原吗:
BOOL CWnd::UpdateData(BOOL bSaveAndValidate)
{
ASSERT(::IsWindow(m_hWnd)); // calling UpdateData before DoModal?

CDataExchange dx(this, bSaveAndValidate);

.....
}
njustcxy 2003-05-14
  • 打赏
  • 举报
回复
在 sht.DoMal();前加一句Update试试.

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧