Ah hello.
I recently built a DLL that needed to be used via GetProcAddress. I discovered that due to name mangling, this function call was failing, so began to create a .DEF file that would declare my function to be exported. However, I realised that I had seen this done via the
#pragma comment(linker, "/EXPORT"
I have the following code:
// stdafx.h
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
// ExportedFunction.cpp
#include "StdAfx.h"
#pragma comment(linker, "/EXPORT:ExportedFunction2=_ExportedFunction@4")
typedef int MSIHANDLE;
extern "C" UINT __stdcall ExportedFunction( UINT )
{
return 0;
}
// stdafx.cpp
<Empty>
I build to a Win32 DLL.
My question is about the arguments to the #pragma comment code. Obviously the first part "ExportedFunction" is what I want my function to be accessed via using GetProcAddresss. Indeed, when I load my DLL in dependency viewer, I see one entry: ExportedFunction2.
The second part is confusing. The code as-is will compile and link. If I remove the _ from the second part, it fails with
unresolved external symbol ExportedFunction@4 MYDLL_.exp
If I change @4 to another number, it fails with the same error. If I remove the parameter from the function, leaving everything else as-is, it also fails with this error.
Can someone please tell me What is going on here, and if there is any documentation I can read so I can learn about what these arguments mean?
PS I know I can also achieve this via __declspec etc, but I would like to learn how to export in this manner too.
TIA