Article View: borland.public.cppbuilder.nativeapi
Article #17234Dynamically loaded DLL problem
From: Chris Buys
Date: Mon, 31 Mar 2003 06:39
Date: Mon, 31 Mar 2003 06:39
102 lines
3769 bytes
3769 bytes
Hi everyone.
I'm have problems unloading dynamically loaded DLLs. I get memory read
errors in Win2000.
I'm using BCB5 Enterprise Edition.
My application reads an INI file and builds a menu system from the contents
of the INI file. The INI
file holds references to DLLs. Each menu-item is thus "linked" to a DLL.
When the user clicks on a
menu-item, that DLL is loaded and the user uses it. After the user exits
the form in the DLL, I
try to unload it. It seems that the unloading process succeeds, but when
the Menu OnClick-event
exits, I receive 4 to 5 read errors, all memory related.
This is the OnClick Event of the Menu-Item:
typedef void *MYPROC(TADOConnection *, String);
// MYPROC is the typedef name, pointer
HINSTANCE Library_Handle;
MYPROC *Procedure;
BOOL fFreeResult, fRunTimeLinkSuccess, result;
Procedure = NULL;
String file =
GetCurrentDir()+"\\"+MenuData(Data_Array[ClickedItem->Tag])->DLL;
try
{ Library_Handle = LoadLibrary(file.c_str()); }
catch (Exception& e)
{ ShowMessage(e.Message+" frmMain::ActivateReport()"); }
if (Library_Handle == NULL)
{
try
{ Library_Handle = LoadLibrary(file.c_str()); }
catch (Exception& e)
{
ShowMessage(e.Message+" frmMain::ActivateReport() - Loading of
DLL");
return;
}
}
if (Library_Handle != NULL)
{
try
{
Procedure = (MYPROC *) GetProcAddress(Library_Handle,
MenuData(Data_Array[ClickedItem->Tag])->ExportedCallingFunction.c_str()); //
create pointer to that procedure
if (Procedure != NULL)
{
Procedure(frmConnection->ADOConnection,"");
}
else
{ ShowMessage("Couldn't hook procedure:
"+MenuData(Data_Array[ClickedItem->Tag])->ExportedCallingFunction); }
}
catch (Exception& e)
{ ShowMessage(e.Message+" frmMain::ActivateReport() - Activating of
DLL"); }
}
// close the Library
try
{
if (Library_Handle != NULL)
{
Procedure = NULL;
FreeLibrary(Library_Handle);
Library_Handle = NULL;
}
}
catch (Exception& e)
{
ShowMessage(e.Message+" frmMain::ActivateReport() freeing of DLL");
}
Library_Handle = NULL;
}
The function code called in the DLL is this:
{
frmStockPriceList = new TfrmStockPriceList(NULL,Conn);
frmStockPriceList->ShowModal();
delete frmStockPriceList;
}
This is just a VCL form with ADOQueries and a QuickReport-componet.
I am sure that the closing code of the form is called correctly.
Any ideas?
Thanks in advance
Chris
--------------------------------------
Chris Buys
Development
HAS Software (Pty) Ltd
Web: www.h-a-s.co.za
Technical Details
Message-ID:
<3e87e2cc@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,d653ffb3af0a87ec,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-03-30 22:42:44 PST From: "Chris Buys" <chris@h-a-s.co.za> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Dynamically loaded DLL problem Date: Mon, 31 Mar 2003 08:39:46 +0200 Lines: 105 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 NNTP-Posting-Host: 168.209.28.202 Message-ID: <3e87e2cc@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1049092812 168.209.28.202 (30 Mar 2003 22:40:12 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail