5

This is how I have my export function declared at the moment:

extern "C" __declspec(dllexport)
Iexport_class* __stdcall GetExported_Class();

When VS2008 compiled the source for this, the dll produced contains this under its export table:

_GetExported_Class@0

For compatibility with other compilers I need the above decoration to look like this instead:

GetExported_Class

Changing the calling convention to __cdecl will decorate it to the way I want but the convention would be wrong so I can't use that. I need it to be decorated the way __cdecl looks but uses __stdcall instead.

Is there anyway to do this without using a .def file? Is there a switch or an option I can pass to the link.exe linker that can make it decorate the export name to the way I want?

Thanks

greatwolf
  • 18,899
  • 13
  • 64
  • 102

3 Answers3

3

No. All __stdcall names are decorated this way. I'm amazed that you have some other compiler that won't expect __stdcall exports to be decorated like this. Overriding the linker with .def is pretty much all you can do- unless you want to alter the PE file after production.

Puppy
  • 138,897
  • 33
  • 232
  • 446
  • thanks, guess I'll just have to do it the hardway. The 'other' compilers that aren't following the convention happens to be MinGW gcc 4.5.1 and Borland 5.93(C++ Builder 2007). Both of them just spit out the function name as is undecorated -- at least when I cracked it open with a pe viewer to check the export tables. – greatwolf Dec 21 '10 at 11:12
2

I don't understand why you don't want to use a .def file, but this is your only option.

The linker supports an export switch, but it cannot be used with functions that are __stdcall annotated:

http://msdn.microsoft.com/en-US/library/7k30y2k5.aspx

The def file way is pretty much the only solution.

Paulo Pinto
  • 587
  • 4
  • 10
  • mainly because it's extra maintenance work. Trying to see if there was an easier way to streamline this. – greatwolf Dec 21 '10 at 12:34
0

Yes:

You can add /EXPORT to the lib.exe command-line, or add a #pragma to your source file:

#pragma comment(linker, "/EXPORT:SomeFunction=_SomeFunction@@@23mangledstuff#@@@@")

Or even easier: Inside the body of the function use

#pragma comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)

Source: https://stackoverflow.com/a/2805560/280534

Community
  • 1
  • 1
Kevin Smyth
  • 1,747
  • 17
  • 19