Link to home
Start Free TrialLog in
Avatar of dd2
dd2

asked on

MFC Dialog in DLL

I have a DLL which is an extension to Lotus Notes and uses the Notes API. From this DLL i try to pop up a dialog when a certain callback from Notes arrives.
I have made an MFC Extension DLL with the appwizard in VC5(sp3) and created a dialog which I call SetPwdDialog.
When I create an instance of the dialog and do DoModal() I get an assertion error that the resource can not be found.  I understand that this is because NT looks for the resource in the app (Notes) instead of my DLL so i made the code:

int
dialogGetPwd(char *buf, int len)
{
    HINSTANCE mod = LoadLibrary("ssonotes.dll");
    if (mod == NULL)
        return 1;

    AfxSetResourceHandle(mod);
    SetPwdDialog pwd;
    pwd.DoModal();
    return 0;
}

Now it passas the resource assertion but instead traps on the assertion:
_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetInstanceHandle()
      { ASSERT(afxCurrentInstanceHandle != NULL);
            return afxCurrentInstanceHandle; }

What do I need to do to pop up my dialog from within the DLL??
My function dialogGetPwd is called from a function which is exported form the DLL.

Regards,
Tomas
Avatar of Answers2000
Answers2000

Can you give the line of the assertion please
ASKER CERTIFIED SOLUTION
Avatar of Tommy Hui
Tommy Hui

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try to use

      AFX_MANAGE_STATE(AfxGetStaticModuleState());

This will help.
AFX_MANAGE_STATE(AfxGetStaticModuleState());

You have to use above line if your function exported from DLL
uses MFC. This line have to be first line of your function.

(I ma sorry for bad english.)


AFX_MANAGE_STATE(AfxGetStaticModuleState());

You have to use above line if your function exported from DLL
uses MFC. This line have to be first line of your function.

(I ma sorry for bad english.)


Avatar of dd2

ASKER

Thanks for the help. When creating a regular dll with MFC dynamically linked, everything works fine. The AFX_MANAGE_STATE is probably needed but the origninal problem was that I had made an MFC extension DLL instead of a normal one.