简体   繁体   English

MFC无法从DLL加载Dlg

[英]MFC Fail to Load Dlg from DLL

I have installed in my PC VS2008 and Windows Mobile 6 SDK. 我已经在我的PC VS2008和Windows Mobile 6 SDK中安装了它。

I have made a SmartDevice MFC application and a Regular DLL MFC, both uses shared MFC DLL. 我制作了一个SmartDevice MFC应用程序和一个Regular DLL MFC,它们都使用共享的MFC DLL。

But when I called DoModal() of the DLL the application hangs, show a "Debug Assertion Failed" message and freeze my device. 但是,当我调用DLL的DoModal()时,应用程序挂起,显示“ Debug Assertion Failed”消息,并冻结了我的设备。

Can you help me? 你能帮助我吗?

Codes: 代码:

The EXE code: 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
}

The DLL Code: DLL代码:

I remove default CTesteDllApp class and put this: 我删除默认的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

    return FALSE;
}

The DLL Dlg code: 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
}

The def File in DLL ; DLL中的def文件; TesteDll.def : Declares the module parameters for the DLL. TesteDll.def:声明DLL的模块参数。

LIBRARY      "TesteDll"

EXPORTS
    ; Explicit exports can go here
    _Load           @1
    _Unload         @2
    _Run            @3

In a similar problem, I had to use AFX_MANAGE_STATE macro in the OnInitDialog, OnKillActive and OnSize methods of the DLL dialog. 在类似的问题中,我必须在DLL对话框的OnInitDialog,OnKillActive和OnSize方法中使用AFX_MANAGE_STATE宏。 I had to add OnKillActive and OnSize methods just to call the mentioned macro, they do nothing but to call the macro, then base implementation, and return. 我只需要添加OnKillActive和OnSize方法就可以调用所提到的宏,除了调用宏然后执行基本操作并返回外,它们什么都不做。 Maybe it would work for your case. 也许它将适合您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM