Solved

MFC Extension DLL

Posted on 1998-02-08
8
273 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 147
string initialization in java 11 115
difference between String.subString() and String.subSequence() 6 241
How to convert MFC::CString to UTF8 wchar_t* 10 292
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

830 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