This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: DLL's



ReSent-Date: Sat, 15 Apr 2000 23:50:38 -0400 (EDT)
ReSent-From: Jeffrey Juliano <juliano@email.unc.edu>
ReSent-To: Jeffrey Juliano <juliano@email.unc.edu>
ReSent-Subject: Re: DLL's
ReSent-Message-ID: <Pine.GSO.4.21L1.0004152350380.21889@swift.cs.unc.edu>


This has nothing to do with ordinals.
The @4 means the function is "__stdcall" and takes four bytes of parameters.

I really ought to write something better once and for all on this...

Usually, __cdecl functions are named
Foo or _Foo

__stdcall are named
Foo@n or _Foo@n where n is a decimal number, possibly multiple digits,
describing the number of bytes of parameteres

__fastcall I think are named
@Foo

Now, there are actually two names for each function you must be aware of,
apart from the name in C/C++ source.
1) the name the compiler outputs a call to and the linker look to resolve,
in an import library
2) the name the loader looks for when your program is run

These names are usually the same. A common way they differ is when __stdcall
functions are exported "unmangled". For example, dumpbin /exports
%windir%\system32\kernel32.dll. All the names are "plain": CreateFileA,
GetFileAttributesW, etc. Now open kernel32.lib (or libkernel32.a) in a
binary editor or view it with od or whatever. You will see strings like
CreateFileA@24 (not sure of the number) and GetFileAttributesW@4.

kernel32 does not have the names equal, and perhaps it isn't so uncommon a
situation.

So, how do you build kernel32.dll? Or, better yet, how does one build the
kernel32.lib that results from how one might build kernel32.dll?

Well, one would think that __declspec(dllexport) and a .def file serve the
same purpose and wouldn't be used at the same time. I'd agree, but
apparently this is not the case. The way you get this situation is by doing
so:
build your code with __declspec(dllexport) and use a .def file with "plain"
names.

Now, "build your code", you can just build stubs.
-- foo.c --
__declspec(dllexport) void __stdcall Foo(int n) { }
-- foo.def --
EXPORTS
 Foo
;there is a space before Foo and EXPORTS is case sensitive

cl -LD foo.c -link -def:foo.def

builds a .dll with "plain" exports but an import .lib with "mangled"
internal linker names.
Write such a foo.c and foo.def. The functions in the .c file don't have to
do anything, but they do need to take the correct number of parameters.
Delete the .dll and link against the .lib.

What do the headers look like you are #including?
What does dumpbin /exports foo.dll print?

>surprising since within the DLL the function is known as
>'Function_time4'!

What that a typo? Did you mean 'Function_time'? If it is actually
'Function_time4' then you have the "base" function name in the first place.
That 4 has nothing to do with __cdecl or __stdcall, the function is actually
'Function_time4' not 'Function_time'.

 - Jay

-----Original Message-----
From: Joan M. Moss <jmm9001@nyp.org>
To: cygwin@sourceware.cygnus.com <cygwin@sourceware.cygnus.com>
Cc: jmm9001@nyp.org <jmm9001@nyp.org>
Date: Friday, March 17, 2000 2:07 PM
Subject: Re: DLL's


[]
>Against DLL's).  However, I've run into a snag.  When I try to compile,
>some of the functions cannot be found.  I get an error message saying
>"undefined reference to 'Function_time@4'.  The function exists in the
>DLL but it is named 'Function_time'.  To get the program to compile I
>changed the .def file so that 'Function_time@4' was in the list instead
>of 'Function_time' and then recreated the .a file.  When I did this the
>program compiled and linked.  Unfortunately when I tried to run it I got
>a message saying it was unable to find 'Function_time@4'.  This is not
>surprising since within the DLL the function is known as
>'Function_time4'!
>
>My .def file looks like:
>
>EXPORTS
>Function_time@4
>Function_name
>
>Does this problem have something to do with the ordinals.  Should I be
>providing them as well as the name?
>
>If any one has any ideas or insights they'd be willing to share with me
>I'd be most grateful.
>
>Thanks in advance for your help.
>--
>J. Maurine Moss
>First consulting Group Management Services
>333 East 38th Street
>New York, New York  10016
>Tel:  (212) 297-3081
>Fax:  (212) 297-4231
>E-mail:  jmm9001@nyp.org
>



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]