MartinD
asked on
MFC Extension DLL
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?
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?
ASKER
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,"Init Dll");
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(ParameterI nspectorDL L);
CMultiDocTemplate* pParTemplate;
pParTemplate = new CSmartMultiDocTemplate(
IDR_PARTYPE,
RUNTIME_CLASS(CParameterIn spectorDoc ),
RUNTIME_CLASS(CParameterIn spectorFra me),
RUNTIME_CLASS(CParameterIn spectorCtr lView));
}
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;
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,"Init
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(ParameterI
CMultiDocTemplate* pParTemplate;
pParTemplate = new CSmartMultiDocTemplate(
IDR_PARTYPE,
RUNTIME_CLASS(CParameterIn
RUNTIME_CLASS(CParameterIn
RUNTIME_CLASS(CParameterIn
}
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;
ASKER
It is generally possible to load an extension DLL with AfxLoadLibrary().
The HuskDll example links the .lib files to the application.
The HuskDll example links the .lib files to the application.
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
If The return value from loadlibrary is < 32 there was an error.
I see you are only checking for NULL
ASKER
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.
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.
Take a look at AFX_MANAGE_STATE and the related stuff.
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
Please show the declaration you're using for your pointer to function in the calling program.
.B ekiM
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.