This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Linking Windows dll with GCC application on cygwin.
- From: "Joseph D. Wagner" <wagnerjd at prodigy dot net>
- To: "'Bansidhar Deshpande'" <dbansidhar at hotmail dot com>,<gcc-help-help at gcc dot gnu dot org>,<gcc-help at gcc dot gnu dot org>
- Date: Sat, 7 Dec 2002 10:08:55 -0600
- Subject: RE: Linking Windows dll with GCC application on cygwin.
LINKING AN EXECUTABLE TO A DLL
An executable file links to (or loads) a DLL in one of two ways:
*Implicit linking
*Explicit linking
Note Implicit linking is sometimes referred to as static load or load-time
dynamic linking. Explicit linking is sometimes referred to as dynamic load
or run-time dynamic linking.
With implicit linking, the executable using the DLL links to an import
library (.LIB file) provided by the maker of the DLL. The operating system
loads the DLL when the executable using it is loaded. The client executable
calls the DLL's exported functions just as if the functions were contained
within the executable.
With explicit linking, the executable using the DLL must make function calls
to explicitly load and unload the DLL, and to access the DLL's exported
functions. The client executable must call the exported functions through a
function pointer.
An executable can use the same DLL with either linking method. Furthermore,
these mechanisms are not mutually exclusive, as one executable can
implicitly link to a DLL and another can attach to it explicitly.
LINKING EXPLICITLY
With explicit linking, applications must make a function call to explicitly
load the DLL at run time. To explicitly link to a DLL, an application must:
*Call LoadLibrary (or a similar function) to load the DLL and obtain a
module handle.
*Call GetProcAddress to obtain a function pointer to each exported function
that the application wants to call. Because applications are calling the
DLL's functions through a pointer, the compiler does not generate external
references, so there is no need to link with an import library.
*Call FreeLibrary when done with the DLL.
For example:
typedef UINT (CALLBACK* LPFNDLLFUNC1)(DWORD,UINT);
...
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
DWORD dwParam1;
UINT uParam2, uReturnVal;
hDLL = LoadLibrary("MyDLL");
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
"DLLFunc1");
if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL);
return SOME_ERROR_CODE;
}
else
{
// call the function
uReturnVal = lpfnDllFunc1(dwParam1, uParam2);
}
}
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Bansidhar Deshpande
Sent: Saturday, December 07, 2002 9:26 AM
To: gcc-help-help@gcc.gnu.org; gcc-help@gcc.gnu.org
Subject: Linking Windows dll with GCC application on cygwin.
Hi,
I have a dll(dont have source code) written in VC++ 6.0 on Windows NT
platform. How can I link this dll with the application written in GCC on
cygwin-1.3.10 .
Regards
Bansidhar
_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963