views:

464

answers:

1

I have installed in my PC VS2008 and Windows Mobile 6 SDK.

I have made a SmartDevice MFC application and a Regular DLL MFC, both uses shared MFC DLL.

But when I called DoModal() of the DLL the application hangs, show a "Debug Assertion Failed" message and freeze my device.

Can you help me?

Codes:

The EXE code:

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:

I remove default CTesteDllApp class and put this:

#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:

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 ; TesteDll.def : Declares the module parameters for the DLL.

LIBRARY      "TesteDll"

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

In a similar problem, I had to use AFX_MANAGE_STATE macro in the OnInitDialog, OnKillActive and OnSize methods of the DLL dialog. 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. Maybe it would work for your case.

Ugur Turan