DLL 卸载自身 [英] DLL unloading itself
问题描述
DLL 中的函数是否可以卸载 DLL?我需要这样做以确保 DLL 未被使用,然后写入 DLL 的文件.
Is it possible for a function that is inside a DLL to unload the DLL? I need to do this so I can make sure the DLL is not in use, then write to the DLL's file.
推荐答案
我认为这行不通.当代码运行在不再有效的内存位置时,从外部使用句柄调用 FreeLibrary(LoadLibrary 会从 DLL 外部的区域调用).
I don't think it will work. Calling FreeLibrary with a handle from the outside (LoadLibrary would have been called from an area outside the DLL) as the code runs in a memory location that will not be valid anymore.
即使这是可能的,它也闻起来像一个糟糕的设计.也许您想制作一些更新程序或类似内容.再解释一下你期望的结果是什么.从内部卸载 DLL 不是可行的方法.
Even if this is possible, it smells like a bad design. Maybe you want to make some updater or alike. Explain a bit more what is the result you expect. Unloading a DLL from within itself is not the way to go.
这篇关于DLL 卸载自身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!