🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #17181

Re: Dynamically loaded DLL problem

#17181
From: Greg Brewer
Date: Wed, 02 Apr 2003 03:23
121 lines
4586 bytes
1 suggestion --  try creating a dll that does nothing when called.  This
will tell you if it is something you are doing in the dll.  I don't see
anything that should cause errors.  You might try simplifying the code.  I
don't think the try/catch's are doing anything for you because the Windows
API doesn't throw exceptions.  For right now, don't worry about all the
error cases.  Assume all the parts will work.  Your goal is to get it to
work; not to handle everything that could go wrong.

Greg Brewer


"Chris Buys" <chris@h-a-s.co.za> wrote in message
news:3e87e2cc@newsgroups.borland.com...
> 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: <3e8a582a@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3e87e2cc@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,d653ffb3af0a87ec
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-04-01 19:35:29 PST
From: "Greg Brewer" <Greg@Brewer.net>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3e87e2cc@newsgroups.borland.com>
Subject: Re: Dynamically loaded DLL problem
Date: Tue, 1 Apr 2003 21:23:40 -0600
Lines: 123
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 206.180.152.142
Message-ID: <3e8a582a@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1049253930 206.180.152.142 (1 Apr 2003 19:25:30 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail