DllMain()函数的第一个参数:
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
if (!AfxInitExtensionModule(ReadScrDLL, hInstance))
return 0;
g_hInst=hInstance;//保存hInstance到全局变量
new CDynLinkLibrary(ReadScrDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
// Terminate the library before destructors are called
AfxTermExtensionModule(ReadScrDLL);
}
return 1; // ok
}