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

__stdcall compile error?

1,665 views
Skip to first unread message

George

unread,
Sep 30, 2008, 7:08:00 AM9/30/08
to
Hello everyone,


I want to export a function in DLL, and using extern C and __stdcall
together to resolve name decoration issue -- so I need
dllexport/stdcall/extern C together to define a function.

But I have played a while there is always compile error? Why? Here is my
code and related compile error.

[Code]
extern "C" __declspec(dllexport) __stdcall BOOL WINAPI StoreData(DWORD dw)

1>d:\visual studio 2008\projects\testdll\testdll\dllmain.cpp(78) : error
C2143: syntax error : missing ';' before '__stdcall'
1>d:\visual studio 2008\projects\testdll\testdll\dllmain.cpp(78) : warning
C4229: anachronism used : modifiers on data are ignored
1>d:\visual studio 2008\projects\testdll\testdll\dllmain.cpp(78) : error
C4430: missing type specifier - int assumed. Note: C++ does not support
default-int
1>d:\visual studio 2008\projects\testdll\testdll\dllmain.cpp(78) : error
C2377: 'BOOL' : redefinition; typedef cannot be overloaded with any other
symbol
1> c:\program files\microsoft
sdks\windows\v6.0a\include\windef.h(153) : see declaration of 'BOOL'
1>d:\visual studio 2008\projects\testdll\testdll\dllmain.cpp(79) : error
C4430: missing type specifier - int assumed. Note: C++ does not support
default-int
1>d:\visual studio 2008\projects\testdll\testdll\dllmain.cpp(105) : error
C2143: syntax error : missing ';' before '__stdcall'
1>d:\visual studio 2008\projects\testdll\testdll\dllmain.cpp(105) : error
C4430: missing type specifier - int assumed. Note: C++ does not support
default-int
1>d:\visual studio 2008\projects\testdll\testdll\dllmain.cpp(106) : error
C4430: missing type specifier - int assumed. Note: C++ does not support
default-int
[/Code]


regards,
George

Giovanni Dicanio

unread,
Sep 30, 2008, 7:24:02 AM9/30/08
to

"George" <Geo...@discussions.microsoft.com> ha scritto nel messaggio
news:EEF7AFEF-2C6F-4B4E...@microsoft.com...

> I want to export a function in DLL, and using extern C and __stdcall
> together to resolve name decoration issue

__stdcall is not for name decoration issues, __stdcall does decorate
exported identifiers.
__stdcall is for stack management issues (especially with old VB6 clients).

If you don't want name decorations, you should use .def files.

> But I have played a while there is always compile error? Why? Here is my
> code and related compile error.
>
> [Code]
> extern "C" __declspec(dllexport) __stdcall BOOL WINAPI StoreData(DWORD dw)

Try:

extern "C" BOOL __stdcall StoreData( DWORD dw );

and use a .def file.

I think that WINAPI is a macro that expands to __stdcall (which is the
calling convention used by Win32 API functions).
So you should not duplicate __stdcall and WINAPI on the same declaration.

Moreoever, __stdcall must be put between <return-type> and <function-name>,
as you can read from __stdcall documentation on MSDN:

http://msdn.microsoft.com/en-us/library/zxk0tw93.aspx

Giovanni

George

unread,
Sep 30, 2008, 7:46:01 AM9/30/08
to
Thanks Giovanni,


You are correct and I have tried your solution could compile.

A further question, I am confused about the MSDN page content "The __stdcall
calling convention is used to call Win32 API functions. The callee cleans the
stack, so the compiler makes vararg functions __cdecl." -- does it mean for
__stdcall caller cleans the stack, but for __cdecl call callee cleans the
stack?


regards,
George

Cholo Lennon

unread,
Sep 30, 2008, 8:48:32 AM9/30/08
to

Take a look to:
http://en.wikipedia.org/wiki/X86_calling_conventions

Regards

--
Cholo Lennon
Bs.As.
ARG

Giovanni Dicanio

unread,
Sep 30, 2008, 9:36:31 AM9/30/08
to

"George" <Geo...@discussions.microsoft.com> ha scritto nel messaggio
news:2176054E-4481-45A3...@microsoft.com...

> Thanks Giovanni,

You are welcome.

> A further question, I am confused about the MSDN page content "The
> __stdcall
> calling convention is used to call Win32 API functions. The callee cleans
> the
> stack, so the compiler makes vararg functions __cdecl." -- does it mean
> for
> __stdcall caller cleans the stack, but for __cdecl call callee cleans the
> stack?

I encourage you to go and read __cdecl description on MSDN, and to compare
"Stack-maintenance responsibility" entry in the summary table for both
__stdcall and __cdecl:

__stdcall
http://msdn.microsoft.com/en-us/library/zxk0tw93.aspx

__cdecl
http://msdn.microsoft.com/en-us/library/zkwh89ks.aspx

Stack-maintenance responsibility
__stdcall: Called function pops its own arguments from the stack.
__cdecl: Calling function pops the arguments from the stack

Giovanni

George

unread,
Oct 1, 2008, 4:01:01 AM10/1/08
to
Thanks Giovanni!


Question answered.


regards,
George

George

unread,
Oct 1, 2008, 4:02:01 AM10/1/08
to
Thanks for sharing, Cholo!


regards,
George

Tim Roberts

unread,
Oct 2, 2008, 2:26:48 AM10/2/08
to
George <Geo...@discussions.microsoft.com> wrote:
>
>I want to export a function in DLL, and using extern C and __stdcall
>together to resolve name decoration issue -- so I need
>dllexport/stdcall/extern C together to define a function.
>
>But I have played a while there is always compile error? Why? Here is my
>code and related compile error.
>
>[Code]
>extern "C" __declspec(dllexport) __stdcall BOOL WINAPI StoreData(DWORD dw)
>
>1>d:\visual studio 2008\projects\testdll\testdll\dllmain.cpp(78) : error
>C2143: syntax error : missing ';' before '__stdcall'

A quick search through the include files would show you that WINAPI is
defined like this:

#define WINAPI __stdcall

So, you have __stdcall in there twice. If you remove the first one, you'll
find that it compiles correctly.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

George

unread,
Oct 3, 2008, 7:44:01 AM10/3/08
to
Thanks Tim,


You are correct!


regards,
George

0 new messages