BOOL APIENTRY DllMain( HANDLE 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;
}
// This is an example of an exported variable
TEST_API int nTest=0;
// This is an example of an exported function.
TEST_API int fnTest(void)
{
return 42;
}
// This is the constructor of a class that has been exported.
// see Test.h for the class definition
CTest::CTest()
{
return;
}
Test.cpp 包含了 fnTest 和 CTest::CTest.如果你现在编译 Test.dll, 你将会得到一
个可以被其他 VC++应用程序直接调用的 DLL.
允许其他 VC++程序调用的关键机制?( key mechanism)就包含在 Test.h 中:
// The following ifdef block is the standard way of creating macros
// which make exporting from a DLL simpler. All files within this DLL
// are compiled with the TEST_EXPORTS symbol defined on the command line.
// This symbol should not be defined on any project that uses this DLL.
// This way any other project whose source files include this file see
// TEST_API functions as being imported from a DLL, whereas this DLL
// sees symbols defined with this macro as being exported.
评论2