我已经在我的电脑上安装了 VS2008 和 Windows Mobile 6 SDK。
我制作了一个 SmartDevice MFC 应用程序和一个 Regular DLL MFC,两者都使用共享 MFC DLL。
但是当我调用 DLL 的 DoModal() 时,应用程序挂起,显示“调试断言失败”消息并卡住我的设备。
bạn có thể giúp tôi được không?
Mã số:
EXE代码:
typedef BOOL (CALLBACK* LPFNDLLLOAD)();
typedef BOOL (CALLBACK* LPFNDLLRUN)(HINSTANCE, HWND, LPBYTE *, LONG *);
BOOL CTesteExeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
//CModule mod;
//mod.Create(L"\\Program Files\\PMA\\Teste.dll");
//mod.Run(AfxGetInstanceHandle(), GetSafeHwnd(), 0, 0);
HMODULE m_hModule = AfxLoadLibrary(L"\\Program Files\\PMA\\TesteDll.dll");
LPFNDLLLOAD m_lpfnLoad= (LPFNDLLLOAD)GetProcAddress(m_hModule, _T("_Load"));
LPFNDLLRUN m_lpfnRun = (LPFNDLLRUN)GetProcAddress(m_hModule, _T("_Run"));
m_lpfnLoad();
m_lpfnRun(AfxGetInstanceHandle(), GetSafeHwnd(), 0, 0);
return TRUE; // return TRUE unless you set the focus to a control
}
动态链接库代码:
我删除了默认的 CTesteDllApp 类并将其放入:
#include "stdafx.h"
#include "TesteDll.h"
#include "TesteDllDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
extern "C" BOOL PASCAL EXPORT _Load()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return TRUE;
}
extern "C" BOOL PASCAL EXPORT _Unload()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return TRUE;
}
extern "C" BOOL WINAPI EXPORT _Run(HINSTANCE hInst,
HWND hwndParent,
LPBYTE *buffer,
LONG *size)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CTesteDllDlg d;
d.DoModal(); ////-------------> Error Here
trả về SAI;
}
DLL Dlg代码:
BOOL CTesteDllDlg::OnInitDialog()
{
CDialog::OnInitDialog();
AfxMessageBox(L"Oi");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
DLL中的def文件 ; TesteDll.def : 声明 DLL 的模块参数。
LIBRARY "TesteDll"
EXPORTS
; Explicit exports can go here
_Load @1
_Unload @2
_Run @3
在类似的问题中,我不得不在 DLL 对话框的 OnInitDialog、OnKillActive 和 OnSize 方法中使用 AFX_MANAGE_STATE
宏。我不得不添加 OnKillActive 和 OnSize 方法来调用提到的宏,它们除了调用宏、基实现和返回之外什么都不做。也许它适用于您的情况。
Tôi là một lập trình viên xuất sắc, rất giỏi!