Solved

MFC Extension DLL

Posted on 1998-02-08
8
247 Views
Last Modified: 2013-11-19
My Application loads a number of Dll's during runtime using
AfxLoadLibrary.
Each Dll has an exported function called InitDll.
If a dll allocated memory, the program chrashes everywhere.
I think that the Dll destroys somthing in my app.
What can i Do now?
0
Comment
Question by:MartinD
8 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1315770
If you run the program in the debugger, do you get a stack trace that may indicate what might be the problem?

One possibility is to ensure that all the DLLs allocate memory and free the memory themselves. You should not pass memory from the DLL and expect the EXE to free it and vice versa.

0
 

Author Comment

by:MartinD
ID: 1315771
I've reduced the program that all dll's do nothing.
It still chrashes.
The loop in my main program look like this:
<outer loop>
 HKEY root;
 HINSTANCE h;
 h=AfxLoadLibrary("<dllname>");
 if(h){
  InitDll* fcn=GetProcAddress(h,"InitDll");
  if(fcn){
   (*fcn)(root,h);
  }
 }
<end loop>

Code in the DLL:
extern "C" void APIENTRY
InitDll(HKEY root,HINSTANCE hinst){
      // Insert this DLL into the resource chain
      new CDynLinkLibrary(ParameterInspectorDLL);

      CMultiDocTemplate* pParTemplate;
      pParTemplate = new CSmartMultiDocTemplate(
            IDR_PARTYPE,
            RUNTIME_CLASS(CParameterInspectorDoc),
            RUNTIME_CLASS(CParameterInspectorFrame),
            RUNTIME_CLASS(CParameterInspectorCtrlView));
}

I've tried the same function without any code in the InitDll function. Doesn't work.

But:
In my main application:
//   (*fcn)(root,h);
no chrash;
0
 

Author Comment

by:MartinD
ID: 1315772
It is generally possible to load an extension DLL with AfxLoadLibrary().

The HuskDll example links the .lib files to the application.
0
 

Expert Comment

by:dr_funfrock
ID: 1315773
Were you actually able to trace into the dll code?
If The return value from loadlibrary is < 32 there was an error.

I see you are only checking for NULL
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:MartinD
ID: 1315774
Yes, I am able to trace into the dll code.

The first three dll's work perfect.
If I try to load another, the program chrashs.
This does not depend on the order, the dlls are loaded.

0
 

Expert Comment

by:asker
ID: 1315775
Take a look at AFX_MANAGE_STATE and the related stuff.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1315776
Please provide a stack trace for the crash you experience.  Please also indicate which version of MFC you're using.

Please show the declaration you're using for your pointer to function in the calling program.

.B ekiM


0
 
LVL 2

Accepted Solution

by:
AlFa earned 100 total points
ID: 1315777
Try your program without loading the do nothing's dll perhaps it still crash and problem is elsewhere
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

18 Experts available now in Live!

Get 1:1 Help Now