🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: how to link a procedure from DLL into EXE code?

#15616
From: Felice Sciosciammocca
Date: Mon, 23 Jun 2003 13:12
68 lines
2714 bytes
Nitisara wrote:

> Is there a way to link a procedure from DLL into EXE code?
> How this can be done?

the process is the following (see example below):

a) put the prototype of the function into the header (unit1.h)
b) use LoadLibrary() to load the DLL (in the form constructor)
c) use GetProcAddress() to get a pointer to the function into the DLL
d) call that pointer every time you need that function
e) use FreeLibrary() to unload the DLL at the end of your program (in
the form destructor)

The following Win32 APIs:

LoadLibrary, GetProcAddress, FreeLibrary

are described into Win32.hlp and are easy to use. Or you can find info
at MSN on the Internet.

Regards. Alvise.

EXAMPLE:

----------- PUT THIS INTO THE HEADER:

// handle to the DLL
   HINSTANCE FFLibDllHandle;

// prototype of the required function
int ( __stdcall *pfnFFGCR121StartComm )( int );


----------- PUT THIS INTO THE FORM CONSTRUCTOR:

// load the DLL
   FFLibDllHandle = 0;
   FFLibDllHandle = LoadLibrary ( "FFLIB.DLL" );
   if ( FFLibDllHandle == 0 )
      {
        MessageBox ( NULL, "LoadLibrary:\nFFLIB.DLL not found.",
                           "Errore FS 001", MB_SYSTEMMODAL );
        break;
      }

// load function address FFGCR121StartComm
   pfnFFGCR121StartComm = ( int ( __stdcall *)( int ) )
      GetProcAddress ( FFLibDllHandle, "FFGCR121StartComm" );
   if ( pfnFFGCR121StartComm == NULL )

     {
        MessageBox ( NULL, "GetProcAddress:\nFFGCR121StartComm not
found.",
        break;
     }


----------- PUT THIS INTO THE FORM DESTRUCTOR:

// unload the DLL
   if ( FFLibDllHandle != 0 ) FreeLibrary ( FFLibDllHandle );


----------- HOW TO CALL THE FUNCTION:

int rc;
rc = pfnFFGCR121StartComm ( 2 );
Technical Details
Message-ID: <3EF6FCB8.F4C03A7E@sciosciammocca.na>
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: <3ef6eee3$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,c25cc947ab95860c
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-06-23 06:18:42 PST
Message-ID: <3EF6FCB8.F4C03A7E@sciosciammocca.na>
Date: Mon, 23 Jun 2003 15:12:24 +0200
From: Felice Sciosciammocca <felice@sciosciammocca.na>
X-Mailer: Mozilla 4.8 [en] (Win95; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: how to link a procedure from DLL into EXE code?
References: <3ef6eee3$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 195.110.148.66
X-Trace: newsgroups.borland.com 1056374119 195.110.148.66 (23 Jun 2003 06:15:19 -0700)
Lines: 78
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