VC++ prevent all symbol name decorations
Asked Answered
A

1

8

I'm working on a DLL which will be used from another language (so no import libs and including the dll's headers) using the _stdcall calling convetion. The problem is that VC++ seems to always do some name decoration on its exported symbols. All the references ive seen say use extern "C" but this still seems to leave me with a leading underscore, and a @ plus a number after the exported name.

The worst bit is the automated means of loading extension dll's in the target language essentially does "func_name = GetProcAddress(dll, "func_name")" so using an undecorated name GetProcAddress fails, and using the decorated name it complains of an illegal variable name (@ is not allowed) :(

How can I make VC++ export somthing with no name decorations at all?

extern "C" __declspec(dllexport) int __stdcall test(int x, const char *str);

dumpbin.exe

00011366 _test@8 = @ILT+865(_test@8)

Ancilin answered 11/7, 2011 at 11:42 Comment(3)
is there a reason of using stdcall instead of cdecl?Audient
Which language are you targeting ? Why does GetProcAddress fail, it returns the address of the function not the name and I don't know any programming languages that forbid the use of a '@' in stringsDisaster
see https://mcmap.net/q/697458/-stdcall-name-mangling-using-extern-c-and-dllexport-vs-module-definitions-msvc/11343Audient
C
6

You can use a .def file. It will let you export the functions without the decorations.

Read: Exporting from a DLL Using DEF Files

Crandell answered 11/7, 2011 at 11:47 Comment(1)
This seems to do what I want and I guess is what other dll's do rather than using __declspec. Would be nice if it could be done with __declspec, but since I'm having to maintain a list for the auto-importing later having one in a .def is not that much extra work.Ancilin

© 2022 - 2024 — McMap. All rights reserved.