For Programmers: Free Programming Magazines  


Home > Archive > VC Language > January 2006 > Turning off name-decoration









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Turning off name-decoration
TheBlasphemer

2006-01-27, 7:05 pm

Hi,

I've got a DLL file that I want to access from my code. To achieve this I
used:
dumpbin <filename> /exports
then made a .def file and ran
lib /def:deffile
which gives me a nice library file.
Next in the header file I tried to add a function:
HRESULT __stdcall Initialize(GUID *guid, DWORD IDCRLVersion /* should be 1
*/, DWORD dwFlags /*should be 0xF*/);

But that fails with the message:

1>main.obj : error LNK2019: unresolved external symbol "long __stdcall
Initialize(struct _GUID *,unsigned long,unsigned long)"
(?Initialize@@YGJPAU_GUID@@KK@Z) referenced in function _main

I also tried adding extern "C" to it, but even that resulted in:

1>main.obj : error LNK2019: unresolved external symbol _Initialize@12
referenced in function _main



Is there a way to turn off name mangling completely? or is there another way
to get this to link properly?



Thank you,

F Hardijzer


Victor Bazarov

2006-01-27, 7:05 pm

TheBlasphemer wrote:
> I've got a DLL file that I want to access from my code. To achieve this I
> used:
> dumpbin <filename> /exports
> then made a .def file and ran
> lib /def:deffile
> which gives me a nice library file.
> Next in the header file I tried to add a function:
> HRESULT __stdcall Initialize(GUID *guid, DWORD IDCRLVersion /* should be 1
> */, DWORD dwFlags /*should be 0xF*/);
>
> But that fails with the message:
>
> 1>main.obj : error LNK2019: unresolved external symbol "long __stdcall
> Initialize(struct _GUID *,unsigned long,unsigned long)"
> (?Initialize@@YGJPAU_GUID@@KK@Z) referenced in function _main
>
> I also tried adding extern "C" to it, but even that resulted in:
>
> 1>main.obj : error LNK2019: unresolved external symbol _Initialize@12
> referenced in function _main
>
>
>
> Is there a way to turn off name mangling completely? or is there another way
> to get this to link properly?


When you do 'dumpbin /exports', what's the actual name of the symbol
that corresponds to the 'Initialize' function?

V
--
Please remove capital As from my address when replying by mail
Sorry, I do not respond to top-posted replies, please don't ask
TheBlasphemer

2006-01-27, 7:05 pm

Just "Initialize"...

"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:uG1$Pb3IGHA.2912@tk2msftngp13.phx.gbl...
> TheBlasphemer wrote:
>
> When you do 'dumpbin /exports', what's the actual name of the symbol
> that corresponds to the 'Initialize' function?
>
> V
> --
> Please remove capital As from my address when replying by mail
> Sorry, I do not respond to top-posted replies, please don't ask



Joe

2006-01-27, 9:58 pm

The first decorated name with the "_Initialize @ YGJPAU_GUID" stuff is C++
name-mangling. This allows C++ to have the same function-name with
different parameter lists (function overloading).

The second decorated name "_Initialize @ 12 " IS extern "C", but for
__declspec(__stdcall). This allows C to detect calling-convention mismatches
between __stdcall, __cdecl, and __fastcall.

The name in your DLL is "Initialize", which is __declspec(dllexport). This
allows applications to use GetProcAddress() with a name like "Initalize"
instead of with all the decoration, but it disables the ability for C to
detect calling-convention mismatches and C++ to provide function overloading

It seems that the compiler is not seeing the same declaration for
Initialize() when it comples the DLL and the APP. It is kind of tricky,
because the header file for the DLL must specify "__declspec(dllexport)",
but the same header file for the APP must specify "__declspec(dllimport").
The VisualStudio Wizard way is to, in the header file, do this:

#if defined <yourdllname>_EXPORTS
#define <yourddlname>_API __declspec(dllexport)
#else
#define <yourddlname>_API __declspec(dllimport)
#endif

When you compile the DLL you define <yourdllname>_EXPORTS, which declares
the exported functions as __declspec(dllexport).

When you compile the APP you do NOT define <yourdllname>_EXPORTS, which
declares the exported functions as __declspec(dllimport).

You do not need to turn off name-decoration to get this to work. You only
need to turn off name-decoration if you expect your exported functions to be
found via GetProcAddress() using "Initialize", instead of "_Initialize @ 12"
etc.

You just need to make sure that the .H file that declares the exported
function be consistent with the DLL and the APP.


"TheBlasphemer" <theblasp@gmail.com> wrote in message
news:eicU9W3IGHA.3936@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> I've got a DLL file that I want to access from my code. To achieve this I
> used:
> dumpbin <filename> /exports
> then made a .def file and ran
> lib /def:deffile
> which gives me a nice library file.
> Next in the header file I tried to add a function:
> HRESULT __stdcall Initialize(GUID *guid, DWORD IDCRLVersion /* should be 1
> */, DWORD dwFlags /*should be 0xF*/);
>
> But that fails with the message:
>
> 1>main.obj : error LNK2019: unresolved external symbol "long __stdcall
> Initialize(struct _GUID *,unsigned long,unsigned long)"
> (?Initialize@@YGJPAU_GUID@@KK@Z) referenced in function _main
>
> I also tried adding extern "C" to it, but even that resulted in:
>
> 1>main.obj : error LNK2019: unresolved external symbol _Initialize@12
> referenced in function _main
>
>
>
> Is there a way to turn off name mangling completely? or is there another

way
> to get this to link properly?
>
>
>
> Thank you,
>
> F Hardijzer
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com