程序编译链接都通过了,执行时在AFXWIN2.INL文件中第58行发生运行时断言错误, 小弟搞不懂该如何处理,望各位不吝赐教。谢谢。
以下是第58行的代码:
_AFXWIN_INLINE BOOL CWnd::SetMenu(CMenu* pMenu)
{ ASSERT(::IsWindow(m_hWnd)); return ::SetMenu(m_hWnd, pMenu->GetSafeHmenu()); }
以下是第58行的代码:
_AFXWIN_INLINE BOOL CWnd::SetMenu(CMenu* pMenu)
{ ASSERT(::IsWindow(m_hWnd)); return ::SetMenu(m_hWnd, pMenu->GetSafeHmenu()); }
CTest_resdllApp::CTest_resdllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}/////////////////////////////////////////////////////////////////////////////
// The one and only CTest_resdllApp objectCTest_resdllApp theApp;/////////////////////////////////////////////////////////////////////////////
// CTest_resdllApp initializationBOOL CTest_resdllApp::InitInstance()
{
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif CTest_resdllDlg dlg;
m_pMainWnd = &dlg;
CString dllname;
dllname="resdll.dll";
Dll_handler=AfxLoadLibrary(dllname); if (Dll_handler==NULL)
{
MessageBox(NULL,"载入动态连接库错误","警告",MB_OK);
return 0;
} pmenu= new CMenu;
pmenu->LoadMenu(MAKEINTRESOURCE("IDR_MENU_NEW"));
dlg.SetMenu(pmenu);
//SetMenu(pmenu); //->LoadMenu("IDR_MENU_NEW");
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
} // Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump. return FALSE;}
麻烦大家给看看!问题解决马上给分!
方法一:
CTestDlg *pdlg;
pdlg = new CTestDlg();
pdlg->Create(IDD_DIALOG1);
pdlg->ShowWindow(SW_SHOW);
m_pMainWnd = pdlg;
CMenu *pMenu;
pMenu = new CMenu;
pMenu->LoadMenu(IDR_MENU1);
pdlg->SetMenu(pMenu);方法二BOOL CTest_resdllDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CMenu *pMenu;
pMenu = new CMenu;
pMenu->LoadMenu(IDR_MENU1);
SetMenu(pMenu); return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
在使用程序自己的资源的时候,是没有问题的,但是在使用资源DLL中的资源的时候,就有资源ID没有定义的错误,我在其中增加了资源ID后,编译链接倒是通过了,但是程序就不能执行了,点执行按钮就没有反应了!是什么原因呀?恭听高论!
HICON LoadIcon(HINSTANCE hInstance,LPCTSTR lpIconName)
HMENU LoadMenu(HINSTANCE hInstance,LPCTSTR lpMenuName)
int LoadString(HINSTANCE hInstance,UINT uID,LPTSTR lpBuffer,int BufferMax)
int DialogBoxParam(
HINSTANCE hInstance, // handle to application instance
LPCTSTR lpTemplateName, // identifies dialog box template
HWND hWndParent, // handle to owner window
DLGPROC lpDialogFunc, // pointer to dialog box procedure
LPARAM dwInitParam // initialization value
); HWND CreateDialogParam(
HINSTANCE hInstance, // handle to application instance
LPCTSTR lpTemplateName, // identifies dialog box template
HWND hWndParent, // handle to owner window
DLGPROC lpDialogFunc, // pointer to dialog box procedure
LPARAM dwInitParam // initialization value
);这些都是常用的读取资源的函数,它们都有一个共同点:第一个参数需要的是要读取的包含资源的程序的模块句柄,那么,关键就在这个句柄,因为我们在读取本身程序资源的时候,肯定是提供用GetModuleHandle函数获得的句柄,这个句柄就是当前程序的实例句柄,如果要读取DLL中的资源,很显然的,我们需要提供DLL的句柄.使用LoadLibrary函数时,返回的值就是读取的DLL的句柄.