本文介绍了为什么不从入口点函数调用FreeLibrary?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个DLL,需要动态调用一个单独的DLL多次。我想保持被调用程序加载,然后只是卸载它,当我的DLL卸载。但根据微软,这是一个。

I'm writing a DLL that needs to call a separate DLL dynamically multiple times. I would like to keep the callee loaded and then just unload it when my DLL is unloaded. But according to Microsoft, that's a bad idea.

这里是令人讨厌的代码。可以有人解释为什么我不应该从我的DLL的入口点调用LoadLibrary和FreeLibrary?

Here's the offending code. Can somebody explain why I shouldn't call LoadLibrary and FreeLibrary from my DLL's entry point?

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
switch (ul_reason_for_call) {
    case DLL_PROCESS_DETACH :
            if (hLogLib != NULL) FreeLibrary(hLogLib);
            break;
    }
    return TRUE;
}


推荐答案

这篇关于为什么不从入口点函数调用FreeLibrary?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:53