网站首页  词典首页

请输入您要查询的函数:

 

术语 loadlibrary
释义 LoadLibrary
语法:
C++
HMODULE WINAPI LoadLibrary(
__in LPCTSTR lpFileName
);
LoadLibrary函数
加载到调用进程的地址空间指定的模块。指定的模块可能导致其他模块被加载。
如需加载选项,使用LoadLibraryEx函数。
参数
lpFileName [in]
该模块的名称。这可以是一个库模块(。dll文件)或可执行模块(。exe文件)。指定的名称是该模块的文件名都没有关系,名称储存库中的模块本身,如在模块定义关键字指定库(。def)文件。
如果该字符串指定完整的路径,该函数只搜索的模块路径。
如果该字符串指定的路径没有一个相对路径或模块的名称,该函数使用标准的检索策略,来寻找模块,获得更多信息,请参见备注。
If the function cannot find the module, the function fails.当指定的路径,一定要使用反斜杠(\\),而不是正斜杠(/)。欲了解更多有关路径的信息,请参见命名文件或目录。
如果该字符串指定的路径没有一个模块的名称和文件扩展名被省略,函数附加默认库推广的。dll的模块名称。为了防止附加功能。dll文件的模块名称,包括一个尾随(。)模块中的名称字符串点字符。
返回值
如果函数成功,返回值是一个句柄模块。
如果函数失败,返回值为NULL。为了获得更多错误信息,调用GetLastError。
备注
要启用或禁用错误DLL加载过程中加载显示的消息,请使用SetErrorMode功能。
调用LoadLibrary可以用来加载到进程地址空间的一个库模块和返回的句柄调用GetProcAddress可用于获取一个DLL函数的地址。调用LoadLibrary也可以用来加载其他可执行模块。例如,函数可以指定一个。exe文件来获取句柄,可以在FindResource和LoadResource使用。但是,不要使用LoadLibrary来运行。exe文件。相反,使用CreateProcess函数。
如果指定的模块是不是已经为调用过程中加载DLL时,系统调用的价值与DLL_PROCESS_ATTACH DLL的DllMain函数。如果DllMain中返回TRUE,LoadLibrary返回的句柄模块。如果DllMain中返回FALSE,系统卸载的进程地址空间和LoadLibrary返回空的DLL。这是不安全的调用DllMain中调用LoadLibrary。有关详细信息,请参阅在DllMain备注部分。
模块处理不是全球或继承。由一个进程调用调用LoadLibrary不会产生一个句柄,另一个进程可以使用-例如,在调用GetProcAddress要求。其他进程必须作出自己的模块调用调用LoadLibrary调用GetProcAddress之前调用。
如果lpFileName不包括道路,有多个具有相同的基本名称和扩展加载的模块,该函数返回的句柄这是先加载模块。
如果没有文件扩展名是在lpFileName参数指定默认的库扩展的。dll追加。但是,文件名字符串可以包含一个尾随点字符(。)表明,模块的名称没有扩展名。如果没有指定路径,加载模块的搜索功能,其基本名称相匹配的模块基地的名称被加载。如果名称匹配,加载成功。否则,该文件的搜索功能。
第一目录搜索是目录包含图像用于创建调用进程(文件的更多信息,请参阅CreateProcess函数)。这样做允许私人动态链接库(DLL)文件与进程相关的不加入进程的安装目录到PATH环境变量中。如果一个相对路径指定,整个相对路径追加到每个DLL的搜索路径列表标记。要加载的相对路径没有任何其他路径搜索模块,使用GetFullPathName获得nonrelative的道路,并要求与nonrelative路径调用LoadLibrary。欲了解更多有关DLL的搜索顺序信息,请参见动态链接库搜索顺序。
搜索路径可以改变使用SetDllDirectory功能。这个解决方案是建议,而不是使用SetCurrentDirectory或硬编码的完整路径的DLL。
如果指定的路径有一个应用程序重定向的文件,这在应用程序的目录检索的功能模块。如果模块在应用程序的目录中,调用LoadLibrary忽略指定的路径和负载从应用程序的目录模块。如果模块中不存在应用程序的目录,调用LoadLibrary加载从指定的目录模块。有关更多信息,请参见动态链接库重定向。
如果您调用的程序集名称调用LoadLibrary没有路径规范和大会在系统兼容清单中列出的通话会被自动重定向到边并排组装。
该系统保持在所有加载的模块每个进程的引用计数。调用LoadLibrary递增引用计数。调用FreeLibrary函数递减或FreeLibraryAndExitThread引用计数。该系统卸载模块时,它的引用计数到达零或当进程终止(无论引用计数)。
Windows Server 2003和Windows XP中:的Visual C + +编译器支持的语法,使您可以声明线程局部变量:_declspec(线程)。如果您使用的DLL此语法,您将无法加载DLL明确使用的Windows版本调用LoadLibrary之前到Windows Vista。如果您的DLL会被载入明确,您必须使用线程,而不是_declspec(线程本地存储功能)。有关示例,请参阅使用的动态链接库线程本地存储。
安全备注
不要使用SearchPath函数来检索随后调用LoadLibrary路径到DLL。该SearchPath函数使用一个不同的搜寻比调用LoadLibrary秩序,它不使用安全搜索模式的过程,这是明确的,除非通过调用BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE SetSearchPathMode启用。因此,SearchPath可能是第一次搜索用户的当前工作目录指定的DLL。如果一个攻击者复制到当前的工作目录中的恶意DLL的版本,由SearchPath检索路径将指向恶意DLL,它LoadLibrary将然后加载。
不要对一个调用LoadLibrary为基础的作业系统版本的假设搜索一个DLL。如果应用程序是在一个环境中运行该DLL在合法不存在,而是恶意的DLL版本的搜索路径,DLL的恶意版本可能会加载。相反,使用获取系统版本所描述的推荐技术。
实例
有关示例,请参阅使用运行时动态链接。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode和ANSI namesLoadLibraryW(Unicode)和LoadLibraryA(ANSI)的
参见
的DllMain
动态链接库函数
FindResource
FreeLibrary
调用GetProcAddress
GetSystemDirectory
GetWindowsDirectory
LoadLibraryEx
LoadResource
运行时动态链接
SetDllDirectory
SetErrorMode
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==LoadLibrary Function
Loads the specified module into the address space of the calling process. The specified module may cause other modules to be loaded.
For additional load options, use the LoadLibraryEx function.
Syntax
C++
HMODULE WINAPI LoadLibrary(
__in LPCTSTR lpFileName
);
Parameters
lpFileName [in]
The name of the module. This can be either a library module (a .dll file) or an executable module (an .exe file). The name specified is the file name of the module and is not related to the name stored in the library module itself, as specified by the LIBRARY keyword in the module-definition (.def) file.
If the string specifies a full path, the function searches only that path for the module.
If the string specifies a relative path or a module name without a path, the function uses a standard search strategy to find the module; for more information, see the Remarks.
If the function cannot find the module, the function fails. When specifying a path, be sure to use backslashes (\\), not forward slashes (/). For more information about paths, see Naming a File or Directory .
If the string specifies a module name without a path and the file name extension is omitted, the function appends the default library extension .dll to the module name. To prevent the function from appending .dll to the module name, include a trailing point character (.) in the module name string.
Return Value
If the function succeeds, the return value is a handle to the module.
If the function fails, the return value is NULL. To get extended error information, call GetLastError .
Remarks
To enable or disable error messages displayed by the loader during DLL loads, use the SetErrorMode function.
LoadLibrary can be used to load a library module into the address space of the process and return a handle that can be used in GetProcAddress to get the address of a DLL function. LoadLibrary can also be used to load other executable modules. For example, the function can specify an .exe file to get a handle that can be used in FindResource or LoadResource . However, do not use LoadLibrary to run an .exe file. Instead, use the CreateProcess function.
If the specified module is a DLL that is not already loaded for the calling process, the system calls the DLL's DllMain function with the DLL_PROCESS_ATTACH value. If DllMain returns TRUE, LoadLibrary returns a handle to the module. If DllMain returns FALSE, the system unloads the DLL from the process address space and LoadLibrary returns NULL. It is not safe to call LoadLibrary from DllMain. For more information, see the Remarks section in DllMain.
Module handles are not global or inheritable. A call to LoadLibrary by one process does not produce a handle that another process can use — for example, in calling GetProcAddress. The other process must make its own call to LoadLibrary for the module before calling GetProcAddress.
If lpFileName does not include a path and there is more than one loaded module with the same base name and extension, the function returns a handle to the module that was loaded first.
If no file name extension is specified in the lpFileName parameter, the default library extension .dll is appended. However, the file name string can include a trailing point character (.) to indicate that the module name has no extension. When no path is specified, the function searches for loaded modules whose base name matches the base name of the module to be loaded. If the name matches, the load succeeds. Otherwise, the function searches for the file.
The first directory searched is the directory containing the image file used to create the calling process (for more information, see the CreateProcess function). Doing this allows private dynamic-link library (DLL) files associated with a process to be found without adding the process's installed directory to the PATH environment variable. If a relative path is specified, the entire relative path is appended to every token in the DLL search path list. To load a module from a relative path without searching any other path, use GetFullPathName to get a nonrelative path and call LoadLibrary with the nonrelative path. For more information on the DLL search order, see Dynamic-Link Library Search Order .
The search path can be altered using the SetDllDirectory function. This solution is recommended instead of using SetCurrentDirectory or hard-coding the full path to the DLL.
If a path is specified and there is a redirection file for the application, the function searches for the module in the application's directory. If the module exists in the application's directory, LoadLibrary ignores the specified path and loads the module from the application's directory. If the module does not exist in the application's directory, LoadLibrary loads the module from the specified directory. For more information, see Dynamic Link Library Redirection .
If you call LoadLibrary with the name of an assembly without a path specification and the assembly is listed in the system compatible manifest, the call is automatically redirected to the side-by-side assembly.
The system maintains a per-process reference count on all loaded modules. Calling LoadLibrary increments the reference count. Calling the FreeLibrary or FreeLibraryAndExitThread function decrements the reference count. The system unloads a module when its reference count reaches zero or when the process terminates (regardless of the reference count).
Windows Server 2003 and Windows XP: The Visual C++ compiler supports a syntax that enables you to declare thread-local variables: _declspec(thread). If you use this syntax in a DLL, you will not be able to load the DLL explicitly using LoadLibrary on versions of Windows prior to Windows Vista. If your DLL will be loaded explicitly, you must use the thread local storage functions instead of _declspec(thread). For an example, see Using Thread Local Storage in a Dynamic Link Library .
Security Remarks
Do not use the SearchPath function to retrieve a path to a DLL for a subsequent LoadLibrary call. The SearchPath function uses a different search order than LoadLibrary and it does not use safe process search mode unless this is explicitly enabled by calling SetSearchPathMode with BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE. Therefore, SearchPath is likely to first search the user’s current working directory for the specified DLL. If an attacker has copied a malicious version of a DLL into the current working directory, the path retrieved by SearchPath will point to the malicious DLL, which LoadLibrary will then load.
Do not make assumptions about the operating system version based on a LoadLibrary call that searches for a DLL. If the application is running in an environment where the DLL is legitimately not present but a malicious version of the DLL is in the search path, the malicious version of the DLL may be loaded. Instead, use the recommended techniques described in Getting the System Version .
Examples
For an example, see Using Run-Time Dynamic Linking .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode and ANSI namesLoadLibraryW (Unicode) and LoadLibraryA (ANSI)
See Also
DllMain
Dynamic-Link Library Functions
FindResource
FreeLibrary
GetProcAddress
GetSystemDirectory
GetWindowsDirectory
LoadLibraryEx
LoadResource
Run-Time Dynamic Linking
SetDllDirectory
SetErrorMode
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:25:14