This worked for me in both 32-bit and 64-bit builds-
BaseDll.dll -
extern "C" __declspec(dllexport) int MyAdd(int a, int b)
{
return a + b;
}
MyDll.dll -
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:czhAdd=BaseDll.MyAdd")
#else
#pragma comment(linker, "/EXPORT:_czhAdd=BaseDll.MyAdd")
#endif
Calling .exe -
extern "C" __declspec(dllimport) int czhAdd(int a, int b);
int main()
{
int x = czhAdd(40, 2);
return x;
}
Name decoration is handled differently between 64-bit and 32-bit builds. The linker map that shows the exports for BaseDll reflects the absence of the underscore prepended to the exported function name where the "C" linkage convention was requested.
32-bit exports-
64-bit exports-
I have learnt a lot. Thanks a lot for your answer. :)