Subject: Re: how to import dll ?
From: [email-masked] (Colin Peters)

9 Dec 1997 17:53:30 -0800
Message-ID: <[email-masked]>
Reply-To: "Colin Peters" <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain;
	charset="US-ASCII"
Content-Transfer-Encoding: 7bit
To: <[email-masked]>
Cc: "GNU-Win32" <[email-masked]>

From: Ivica Ceraj <[email-masked]>
Date: Wednesday, December 10, 1997 8:44 AM
>I have one question I have not found in FAQs, and may be interesting and
>for other people, is there any way to import dll, and build library
>wrapping it ?
>[like implib.exe in Borland C]

The program impdef.exe from my homepage (add /gcc-extra.html to either URL
in my signature and scroll down near the bottom of the page) can be used
to generate a .def file from a DLL. However: It does not work with PASCAL
or STDCALL functions, because there is no way to determine the correct @xx
value to attach to the end of a function name; and it doesn't seem to work
quite right on some DLLs produced with newer versions of MSVC.

Do this:

 impdef foo.dll >foo.def
 dlltool --def foo.def --output-lib libfoo.a

Then link your program which uses functions in foo.dll with the library
libfoo.a, e.g.:

 gcc -o bar.exe bar.o -lfoo

Hope this helps,
Colin.

P.S. Before you (or anyone else) asks, trying to use C++ DLLs from Borland
or MSVC with GCC compiled code is unlikely to work for lots of good
reasons. Stick to C DLLs or C++ done with the same compiler (and even that
can be pretty tricky).

P.P.S. Functions with STDCALL or PASCAL calling convention need the number
of bytes in their argument list added as @xx (where xx is the number of
bytes) to the function name in the .def file (unless the DLL exports the
name with @xx attached, which does happen sometimes), and you need to add
the -k option to the dlltool command line above.

-- Colin Peters -- colin at fu.is.saga-u.ac.jp
-- Saga University Dept. of Information Science
-- http://www.fu.is.saga-u.ac.jp/~colin
-- http://www.geocities.com/Tokyo/Towers/6162

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".