🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Dynamic package loading

#8799
From: Mark Guerrieri
Date: Sun, 22 Jun 2003 16:13
54 lines
2666 bytes
"Pang Fu" <pangfu@hotmail.com> wrote in message
news:3ef1bb17@newsgroups.borland.com...
>
> >    (3) Can some one convert the following Delphi code into BCB (please
> make
> > sure that BCB code does not complain about invalid type conversion at
run
> > time on LoadPackage line).
>
> type
>   TProc00 = procedure;
> var
>   PackageModule: HModule;
>   Proc00: TProc00;
> begin
>   PackageModule := LoadPackage('Package1.bpl');
>   if PackageModule <> 0 then
>   begin    @Proc00 := GetProcAddress( PackageModule, 'ProC00' );
>     if @Proc00 <> nil then
>       Proc00;
>
>     UnloadPackage(PackageModule);
>   end;
> end;
>
>
>

HMODULE PackageModule = LoadPackage("Package1.bpl");
if(PackageModule != 0)
{
  try
  {
    SomeFunctPtr myPtr = GetProcAddress(PackageModule, "Proc00");
    if(myPtr != NULL)
      myPtr();
  }
  __finally
  {
    UnloadPackage(PackageModule);
  }
}
else
  RaiseLastWin32Error();

Note that SomeFunctPtr should be a typedef of a function pointer matching
the function signature of Proc00.  If Proc00 require parameters,  don't
forget to pass them to the myPtr() call...

Also, if Proc00 creates any memory/forms, they MUST be
deleted/released/freed before you UnloadPackage.

Mark
Technical Details
Message-ID: <3ef5d62d$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3ef1b8d2@newsgroups.borland.com> <3ef1bb17@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,805caadba3d61bfd
X-Google-Attributes: gid10cc67,public
X-Google-Thread: f94dd,805caadba3d61bfd
X-Google-Attributes: gidf94dd,public
X-Google-Thread: f8e31,805caadba3d61bfd
X-Google-Attributes: gidf8e31,public
X-Google-Thread: 102541,805caadba3d61bfd
X-Google-Attributes: gid102541,public
X-Google-Thread: 10db1e,805caadba3d61bfd
X-Google-Attributes: gid10db1e,public
X-Google-ArrivalTime: 2003-06-22 09:26:34 PST
From: "Mark Guerrieri" <markg11@comcast.net>
Newsgroups: borland.public.cppbuilder.nativeapi,borland.public.cppbuilder.oodesign,borland.public.cppbuilder.students,borland.public.delphi.nativeapi,borland.public.delphi.students
References: <3ef1b8d2@newsgroups.borland.com> <3ef1bb17@newsgroups.borland.com>
Subject: Re: Dynamic package loading
Date: Sun, 22 Jun 2003 12:13:41 -0400
Lines: 56
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 68.44.202.58
Message-ID: <3ef5d62d$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1056298541 68.44.202.58 (22 Jun 2003 09:15:41 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail