WindowsApi:DllMain
MSVC의 Dynamic library 프로젝트에 사용되는 DllMain
에 대하여 정리한다.
Startup project
헤더파일은 아래와 같다:
#include <SDKDDKVer.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#ifdef SIMPLEWIN32DLL_EXPORTS
#define SIMPLEWIN32DLL_API __declspec(dllexport)
#else
#define SIMPLEWIN32DLL_API __declspec(dllimport)
#endif
// This class is exported from the SimpleWin32Dll.dll
class SIMPLEWIN32DLL_API CSimpleWin32Dll {
public:
CSimpleWin32Dll(void);
// TODO: add your methods here.
};
extern SIMPLEWIN32DLL_API int nSimpleWin32Dll;
SIMPLEWIN32DLL_API int fnSimpleWin32Dll(void);
소스파일은 아래와 같다:
// This is an example of an exported variable
SIMPLEWIN32DLL_API int nSimpleWin32Dll=0;
// This is an example of an exported function.
SIMPLEWIN32DLL_API int fnSimpleWin32Dll(void)
{
return 42;
}
// This is the constructor of a class that has been exported.
// see SimpleWin32Dll.h for the class definition
CSimpleWin32Dll::CSimpleWin32Dll()
{
return;
}
BOOL APIENTRY DllMain( HMODULE 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;
}