Re: Exported function mangaled name



See below...
On Fri, 6 Feb 2009 17:07:40 +0530, "Manish Agarwal" <manishkrishan@xxxxxxxxxxx> wrote:

Hi,

I am exporting following function:

TestFunc.h

extern "C" {
__declspec(dllexport) int __stdcall TestFunc(void);
}


TestFunc.cpp

****
Put
extern "C"
before this declaration. You have otherwise defined a function unrelated to the header
specification.

extern "C" __declspec(dllexport) int __stdcall TestFunc(void);

Note several things:
(a) you cannot declare it as __declspec(dllexport) in the header file if the clients use
that header file; it must be declared as __declspec(dllimport)
(b) You don't need to specify (void), because () works just as well and means the same
thing
(c) You have to declare the function the same way in your .cpp file as in your .h file

That is, the usual technique is to do, for your .h file

#pragma once
#ifdef _SOME_GUID_BASED_SYMBOL
#define LIBSPEC __declspec(dllexport)
#else
#define LIBSPEC __declspec(dllimport)
#endif
extern "C" {
LIBSPEC int __stdcall TestFuc();
}
#undef LIBSPEC

and in building your DLL, you write in the .cpp file:

#include "stdafx.h"
#define _SOME_GUID_BASED_SYMBOL
#include "TestFunc.h"

extern "C" __declspec(dllexport) int __stdcall TestFunc()
{
... function body
}

See my essay on The Ultimate DLL Header File on my MVP Tips site.
****
__declspec(dllexport) int __stdcall TestFunc(void)
{
return 42;
}

When I compile the above with VS2005 for Windows 32 bit, the decorated
function name is "_TestFunc@0"

and when I compile it with VS2005 for Windows 64 bit, the decorated function
name is "TestFunc"

Why there is a difference, what I am missing here. Is it documented some
where ? Even I created a simple DLL using VS wizard and copied all project
setting for Win64 from Win32 settings. Nothing I changed manually in project
setting.

Regards,
Manish K. Agarwal

PS: Sorry I have to post it again because on other group, I was uanble to
get the exact answer.

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: struct & enum & :: visibility operator
    ... I have a header file like this: ... extern "C" is a syntax error in C. Apparently this header is meant to ... *after* you declare them. ... typedef struct _S S; ...
    (comp.lang.c.moderated)
  • Re: Namespaces: Initializing variables
    ... You must declare not define the variable in the ... For declaration in the header, use extern: ... extern DWORD avar; ...
    (microsoft.public.vc.language)
  • Re: Newbie Classes & externals
    ... Venturing into the world of C# from MFC. ... I could declare the class ... > as 'extern' in the app's header, and then every other class that had the ... app's header could use the same class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Newbie Classes & externals
    ... I could declare the class ... as 'extern' in the app's header, and then every other class that had the app's header could use the same class. ... Ray K. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: static library problems
    ... Do not declare variables in header files. ... variable itself must be declared in a .cpp file. ... >If i want to use this string in other modules, i just need include the header, i need not link this static lib. ...
    (microsoft.public.vc.mfc)

Loading