Solved

MFC Extension DLL

Posted on 1998-02-08
8
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

695 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