Solved

MFC Dialog in DLL

Posted on 1998-12-18
6
451 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:dd2
6 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1326382
Can you give the line of the assertion please
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 total points
ID: 1326383
The problem is that you are using an MFC extension DLL. MFC extension DLLs are designed to be used by MFC applications. More than likely, it seems Notes is not an MFC application.

So to get around this problem, create a Regular DLL with MFC either static or dynamically linked in when you're using the wizard.

0
 

Expert Comment

by:george_777
ID: 1326384
Try to use

      AFX_MANAGE_STATE(AfxGetStaticModuleState());

This will help.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Expert Comment

by:george_777
ID: 1326385
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.)


0
 

Expert Comment

by:george_777
ID: 1326386
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.)


0
 

Author Comment

by:dd2
ID: 1326387
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.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Expand LInux Boot partition remotly 3 78
Adapt this command to show who installed 29 102
Fibonacci challenge 11 82
wordmultiple challenge 12 89
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now