Subject: Re: mingw32: .exe -> .a import libs for DLLs?
From: [email-masked] (Colin Peters)

20 Jan 1998 13:30:48 -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: "Peter Dalgaard BSA" <[email-masked]>
Cc: "GNU-Win32" <[email-masked]>

You almost have it. The problem is that the symbols baz and zip are
actually pointers to thunk functions in the DLL (and similarly the symbol
bar is a pointer to a thunk in the executable). The thunk functions simply
look up the appropriate pointer in the jump table for the DLL and call
that function. Obviously this won't work for variables. What you have to
do in that case is something like

extern int* __imp__zip;
#define zip    (*__imp__zip)

in your DLL code (but not in the executable). This only works because we
know that dlltool names each of the entries in the jump table
__imp_<symbol> (and the actual symbol for zip is _zip, but anyway). This
may change in the future (especially since MS's standard is something like
_imp___zip IIRC), but for now it will work.

On the other hand I'm sure you know that global variables are evil. :)

Good luck,
Colin.

PS. I think MS does this basically the same way, except the compiler knows
how to handle it all internally based on the __dllexport (or some such)
keyword.

-- 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".