Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

(dll) __stdcall functions and GetProcAddress

521 views
Skip to first unread message

K�r�at

unread,
May 6, 2009, 5:28:54 PM5/6/09
to
Hi,

I have a very simple dll that exports a simple function "int Add (int,
int)". I use the function from an executable using LoadLibrary and
GetProcAddress. When calling convention is "cdecl" so far so good but with
"stdcall" GetProcAddress returns 0. When I look at the export list I see the
function exported as _Add@8. Well, how can I dynamically address stdcall
functions from .dll's without knowing those strange (and I think not
reliable to depend on) names? AFAIK, windows API functions generally use
stdcall calling convention and we can address those functions dynamically
(using LoadLibrary+GetProcAddress) using their straight names, what is the
trick?

Thanks in advance.


Bob Milton

unread,
May 6, 2009, 5:55:42 PM5/6/09
to
Simple - use .def files. They allow specifying the name that the
importing program sees explicitly. So an export def might be
Add=_Add@8

now you can GetProcAddress on "Add".
Most of Microsofts Dlls were built with .def files (even MFC since it
exports no names at all!)

"K�r�at" <kursat...@gmail.com> wrote in message
news:%231IeTEp...@TK2MSFTNGP05.phx.gbl...

Scot T Brennecke

unread,
May 7, 2009, 1:05:36 AM5/7/09
to
Alternatively, those names ARE reliable. They always begin with an underscore, and the numeric
value after the @ is the number of bytes in the parameter list:
http://msdn.microsoft.com/en-us/library/x7kb4e2f(VS.80).aspx

You can call GetProcAddress on _Add@8

"K�r�at" <kursat...@gmail.com> wrote in message news:%231IeTEp...@TK2MSFTNGP05.phx.gbl...

Ulrich Eckhardt

unread,
May 7, 2009, 3:35:11 AM5/7/09
to
Bob Milton wrote:
> [.def files] allow specifying the name that the

> importing program sees explicitly. So an export def might be
> Add=_Add@8
>
> now you can GetProcAddress on "Add".

Actually, that is more hassle than necessary. You can simply use this:

EXPORTS
Add

Even without the "=_Add@8" the linker will do The Right Thing(tm).

Uli

--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

Alexander Grigoriev

unread,
May 7, 2009, 9:43:33 AM5/7/09
to
Those names can be different in x64 build.

"Scot T Brennecke" <Sc...@MVPs.spamhater.org> wrote in message
news:eJxp2Ftz...@TK2MSFTNGP04.phx.gbl...

Scot T Brennecke

unread,
May 7, 2009, 10:48:44 AM5/7/09
to
Well, yes, but I thought we were talking about stdcall convention, which isn't used on x64. 64-bit
builds are always fastcall, which passes 4 parameters in the registers rcx, rdx, r8, and r9. These
days, stdcall is only really relevant on 32-bit. However, you can use the __stdcall declaration on
64-bit builds and it will be ignored, which might confuse some people.

"Alexander Grigoriev" <al...@earthlink.net> wrote in message
news:%23YQiSnx...@TK2MSFTNGP06.phx.gbl...

0 new messages