它不得调用LoadLibrary或LoadLibraryEx函数 (或调用这些函数的函数), 因为这可能会以DLL加载顺序创建依赖关系循环. 这可能会导致在系统执行其初始化代码之前使用DLL. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order. This can result in a DLL being used before the system has executed its initialization code.我试图从DllMain调用LoadLibrary,但没有任何反应. I tried to call LoadLibrary from DllMain and nothing happened. 我看到的唯一问题是,加载的DLL将在其余DllMain执行之前使用DLL中的函数.The only issue that I see is that loaded DLL will use functions in my DLL before rest of my DllMain executes. 为什么不能在DllMain中调用LoadLibrary? 好的,我意识到我不能在DllMain中调用LoadLibrary仅仅是因为我必须像其他信徒那样相信MSDN(我在那看到了一些错误的事情,但我也应该忘记他们).而且由于新版本的Windows可能会发生某些事情(尽管最近十年没有任何变化).OK, I realized that I must not call LoadLibrary in DllMain just because I must believe MSDN as other believers do (I saw some wrong things there, but I should forget them too).And because something may happen in newer versions of Windows (although there nothing was changed for last ten years).但是任何人都可以显示一个代码,该代码将重现在DllMain中调用LoadLibrary时发生的不良情况吗?在任何现有的Windows操作系统中?不仅是在另一个内部调用一个单例初始化函数,还是在DllMain中调用LoadLibrary?But can anyone show a code which will reproduce something bad what happens when LoadLibrary is called in DllMain? In any existing Windows OS?Not just a call of one singleton initialization function inside another, but LoadLibrary in DllMain?推荐答案您的赞成这样做的论点似乎可以解释为:Your argument in favor of going ahead with this seems to be, to paraphrase: 微软说不要这样做,但是我的 单个测试用例似乎有效,因此我看不到为什么没人应该这样做. Microsoft says don't do this, but my single test case seems to work, therefore I fail to see why nobody should be doing this.您在一个很大的假设下进行操作:您假设Windows加载程序的基础实现永远不会改变.如果在"Windows 8"中以某种方式更改了加载程序,以致您的代码不再正常工作,该怎么办?现在, Microsoft 为此被指责,他们必须包含另一个兼容性黑客,以解决他们告诉 you not 在第一篇文章中编写的代码地方.You're operating under a big assumption: you're assuming that the underlying implementation of the Windows loader will never change. What if the loader is changed in "Windows 8" in a way such that your code no longer works properly? Now Microsoft gets blamed for it and they have to include yet another compatibility hack to work around code that they told you not to write in the first place.遵循准则.它们不只是在增加您的生活难度,还可以保证您的代码在将来的Windows上也能像现在一样正常运行.Follow the guidelines. They're not there just to make your life more difficult, they're there to guarantee that your code will work just as well on the Windows of the future as it does now. 这篇关于从DllMain调用LoadLibrary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-27 01:10