?
Solved

MFC Extension DLL

Posted on 1998-02-08
8
Medium Priority
?
295 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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit 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 200 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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