问题描述
我已将dll静态链接到mfc.
在dll中是对话框类.
我从主程序调用导出的函数.
I have got dll staticly linked to mfc.
In the dll is dialog class located.
I call exported function from main program.
void __stdcall ShowMMInfo(DWORD id, HWND parent)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CMainDialog dlg(CWnd::FromHandle(parent));
dlg.DoModal();
}
在DoModal中,在行中发生未处理的异常
In DoModal occures an unhandled exception in the line
if (CreateDlgIndirect(lpDialogTemplate,
CWnd::FromHandle(hWndParent), hInst))
有什么问题吗?
更新:
我已经用mfc控件替换了我们库中的Skin控件.该程序开始运作良好后.
但是我需要在该对话框中使用皮肤控件.
在主程序中,皮肤控件运行良好.
我该怎么做才能使皮肤控制良好地加载?
我只是添加了lib文件来链接并包含头文件.
我看了一下hdependency walker:有皮肤控制类.
但是当我用CSCScaleDialog替换例如CDialog时,出现了异常.
我试图静态地和动态地链接到主程序,但是没有区别.
What can be wrong?
Update:
I have replaced Skin Controls from our library with mfc controls. After that program begun work well.
But i need Skin controls in that dialog.
In main program skin controls work well.
What should i do to make skin controls to load well?
I just added lib file to link and include header files.
I took a look with hdependency walker: there are skin controls classes.
But when i replace for example CDialog with CSCScaleDialog i got an exception.
I tryed to link staticly and dinamicly to main program, but there is no difference.
推荐答案
class CMyApp : public CWinApp
{
public:
CMyApp();
~CMyApp();
// Overrides
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
static HINSTANCE GetInstance();
DECLARE_MESSAGE_MAP()
};
// In the body
HINSTANCE hMyInst = 0;
// The one and only CMyApp object
CMyApp theApp;
BOOL CMyApp::InitInstance()
{
CWinApp::InitInstance();
hMyInst = AfxGetInstanceHandle();
return TRUE;
}
int CMyApp::ExitInstance()
{
return CWinApp::ExitInstance();
}
HINSTANCE CMyApp::GetInstance()
{
return hMyInst;
}
您的代码变为:
The your code becomes:
if (CreateDlgIndirect(lpDialogTemplate,
CWnd::FromHandle(hWndParent), CMyApp::GetInstance()))
这篇关于从Dll显示对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!