https://blog.csdn.net/chenlycly/article/details/124272585
将10多年C++开发实践中常用的功能,以高质量的代码显现出来。这些常用的高质量规范代码,可以直接拿到项目中使用,能有效地办理软件开发过程中遇到的问题。 专栏5:
C++ 软件开发从入门到精通(专栏文章,持续更新中...)
ReactOS是一款基于 Windows NT 架构的类似于Windows XP体系的免费开源操作体系,旨在实现和Windows操作体系二进制下的完全应用程序和驱动装备的兼容性,通过使用类似构架和提供完全公共接口。ReactOS不停在持续维护中,可以到reactos官网上找到ReactOS源码的下载地址,使用svn将ReactOS源码下载下来。 ReactOS开源代码对于我们Windows软件开发职员来说非常有效,我们可以去检察API函数的内部实现,可以去检察体系exe的内部实现,可以去检察ReactOS体系内部恣意模块的实当代码。ReactOS是比较接近Windows体系的,可以通过检察ReactOS的代码去大概地了解Windows体系的内部实现,对我们排查Windows软件的问题是很有好处的!
6.2、使用Source Insight打开ReactOS源码,找到regsvr32.exe程序的代码
为了搞清楚LOAD_WITH_ALTERED_SEARCH_PATH参数的寄义,我们到微软MSDN上检察LoadLibraryEx API函数的说明页面,找到了LOAD_WITH_ALTERED_SEARCH_PATH参数的说明: LOAD_WITH_ALTERED_SEARCH_PATH:(0x00000008)
If this value is used and lpFileName specifies an absolute path, the system uses the alternate file search strategy discussed in the Remarks section to find associated executable modules that the specified module causes to be loaded. If this value is used and lpFileName specifies a relative path, the behavior is undefined.
If this value is not used, or if lpFileName does not specify a path, the system uses the standard search strategy discussed in the Remarks section to find associated executable modules that the specified module causes to be loaded.
This value cannot be combined with any LOAD_LIBRARY_SEARCH flag.
从上述描述文字得知,如果设置了LOAD_WITH_ALTERED_SEARCH_PATH参数,则体系会使用the alternate file search strategy搜索策略,那这个搜索策略到底是什么样的呢?
在LoadLibraryEx函数的说明页面继续向下看,看到了"Dynamic-Link Library Search Order"超链接,这是动态毗连库加载顺序的详细说明页面。从页面中我们看到了,如果没设置LOAD_WITH_ALTERED_SEARCH_PATH参数,则使用Standard Search Order for Desktop Applications标准搜索顺序:
1、The directory from which the application loaded.
2、The system directory. Use the GetSystemDirectory function to get the path of this directory.
3、The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
4、The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
5、The current directory.
6、The directories that are listed in the PATH environment variable. Note that this does not include the per-application path specified by the App Paths registry key. The App Paths key is not used when computing the DLL search path. 如果设置了LOAD_WITH_ALTERED_SEARCH_PATH参数,则体系会使用Alternate Search Order for Desktop Applications搜索顺序:
1、The directory specified by lpFileName.
2、The system directory. Use the GetSystemDirectory function to get the path of this directory.
3、The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
4、The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
5、The current directory.
6、The directories that are listed in the PATH environment variable. Note that this does not include the per-application path specified by the App Paths registry key. The App Paths key is not used when computing the DLL search path.
以是我们终极找到了答案,当我们设置LOAD_WITH_ALTERED_SEARCH_PATH参数时,就会使用Alternate Search Order for Desktop Applications,会优先使用设置下来的完整路径去加载dll库。
8、dll动态库加载失败的其他缘故原由