Re: how to export "DllCanUnloadNow" (prototypied in objbase.h) without .DEF file
Ben,
"Ben Voigt [C++ MVP]" <rbv@nospam.nospam> schrieb im Newsbeitrag
news:OLt6fjUhIHA.5208@TK2MSFTNGP04.phx.gbl...
#pragma comment(linker, "/EXPORT:DllCanUnloadNow")
#pragma comment(linker, "/EXPORT:_DllCanUnloadNow@0")
But now the name is wrong, when COM looks for "DllCanUnloadNow" with
GetProcAddress, it won't find it.
But
a) extern "C" __stdcall functions are always mangeled (decorated) by VC++
and the function is prototyped this way.
b) what whould be the correct way to export?
c) when i ignore the prototype in the windows header file and change it to
extern "C" __declspec(dllexport) unsigned long __stdcall DllCanUnloadNow()
/* use unsigned long instead of HRESULT so i do not need to include
windows.h */
and implement this function, then i have 2 binaries based on 2 different
sources:
=== dll1.cpp ===
#include <windows.h>
STDAPI DllCanUnloadNow()
{ return 0; }
//#pragma comment(linker, "/EXPORT:DllCanUnloadNow") // this will give a
linker error since __stdcall functions are decorated.
#pragma comment(linker, "/EXPORT:_DllCanUnloadNow@0")
=================
===== dll2.cpp =======
extern "C" __declspec(dllexport) unsigned long __stdcall DllCanUnloadNow()
/* use unsigned long instead of HRESULT so i do not need to include
windows.h */
{
return 0;
}
==================
and dumpbin /Exports dll.dll
(for both dlls)
gives exactly the same result!
1 0 00001005 _DllCanUnloadNow@0 = @ILT+0(_DllCanUnloadNow@0)
So, the question is : how to implement DllCanUnloadNow with VC++ (without
..DEF file)
thx,
mario.