How do I use .def files?


So I'm using VC++2010 and the automatically generated sample code for a DLL project (which I named "TestDLL") has this for an example function called "fnTestDLL".

In TestDLL.h there is this code pertaining to the function.
1
2
#define TESTDLL_API __declspec(dllexport)
extern "C" TESTDLL_API int fnTestDLL(void);


In TestDLL.cpp there is this code pertaining to the function.
1
2
3
4
TESTDLL_API int fnTestDLL(void)
{
	return 42;
}


Furthermore, I have set the compiler option to compile the function with STDCALL calling convention so that it will be fully compatible with Visual Basic.

I believe that all of this put together is equivalent to this standalone cpp file code for the function.

1
2
3
4
extern "c" __declspec(dllexport) __stdcall int fnTestDLL(void)
{
	return 42;
}


The problem is this is not an undecorated function that gets exported. While using extern "c" does help cutdown on the decoration, the only way to completely undecorate it is to have it use the CDECL calling convention, which is NOT compatible with Visual Basic

So the STDCALL function I'm left with is one who's name is "fnTestDLL" as seen in the VC++2010 IDE, but who's name is seen as "_fnTestDLL@0" by everything that tries to access the function in the DLL.

I need to use a DEF file to tell the compiler and/or linker to export this function name "fnTestDLL" in place of this function name "_fnTestDLL@0".

Can somebody show me how to write a DEF file that maps the old name "_fnTestDLL@0" to the new name "fnTestDLL"? And what folder to I place it in? The project's base folder? The Bin folder that will contain the compiled DLL file? Where do I place it? And how do I tell VC++2010 to even look for this DEF file? Does it automatically look for a DEF file every time it compiles, and simply normally continues without this DEF file if it doesn't find one, using default settings instead?
Last edited on
Topic archived. No new replies allowed.