c++ builder and export dll function name chaos

Hello Guys,

I have a Problem, i have this example Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// dllmain.cpp : Defines the entry point for the DLL application.
#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
 
BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}
 
extern "C"
{
  __declspec(dllexport) void __stdcall RVExtension(char *output, int outputSize, const char *function); 
};
 
void __stdcall RVExtension(char *output, int outputSize, const char *function)
{
  outputSize -= 1;
  strncpy(output,function,outputSize);
}


When i Compile this with me XE10 C++ Builder, then i have the exported function "RVExtension" via depwalker.

But my Problem is, the Program, thats load this DLL, require the name as "_RVExtension@12"

With Delphi goes this with:

1
2
exports
  RVExtension name '_RVExtension@12';


now, we can i change in C++ Builder the Exportname from the DLL to "_RVExtension@12" ? my defination file in the project is ignored :(

Thanks :)
Last edited on
It's because you're declaring the calling convention as '__stdcall'. Take a look here: " https://msdn.microsoft.com/en-us/library/zxk0tw93.aspx " ctrl + F for "Name-decoration convention". Make sense?
See:

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

Your export name should have this decoration.
Thanks for this Info, this was my Problem the Name decoration conversion between C++ Borland and VC++

Now, i compile my DLL in Borland, and the VC++ Application loads this as Plugin.

Now i am confused, how must i change my code?

The Same Code is compiled in Borland and exports the Name as "RVExtension"
The same Code in VC++ exports the Name as "_RVExtension@12"...

How we must change my Code, to export my Borland C++ DLL Name-Convention to the Named Convention from VC++ ala "_RVExtension@12" ?

Thanks :)
Change the calling convention to '__cdecl' and leave the extern 'C' modifier: https://msdn.microsoft.com/en-us/library/zkwh89ks.aspx
1
2
3
4
5
6
7
__declspec(dllexport) __cdecl RVExtension(char *output, int outputSize, const char *function);

RVExtension(char *output, int outputSize, const char *function)
{
	outputSize -= 1;
	strncpy(output,function,outputSize);
}


this Code Exports the Name as "@RVExtension$qpcipxc"
Did you leave, as in maintain, the "extern 'C'" bracket in your code?
Topic archived. No new replies allowed.