C语言 dllMain的格式

 

 

/**
名称:DllMain
功能: dll被操作是系统会自动调用
参数:HANDLE hModule dll的句柄
DWORD ul_reason_for_call 调用原因
LPVOID lpReserved 如果是动态加载则为NULL 静态加载则为非NULL
返回值:BOOL 如果为False loadLibrary会返回False
**/
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call,LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH: //当进程加载dll时调用dllMain

break;
case DLL_PROCESS_DETACH: //当进程卸载dll时调用dllMain

break;
case DLL_THREAD_ATTACH: //当线程加载dll时调用dllMain

break;
case DLL_THREAD_DETACH://当线程卸载dll时调用dllMain

break;
}
return (TRUE);  //如果返回FALSE会 报错。
}

posted @ 2021-04-04 17:05  乘舟凉  阅读(264)  评论(0编辑  收藏  举报