网站首页  词典首页

请输入您要查询的函数:

 

术语 getmodulehandle
释义 GetModuleHandle
语法:
C++
HMODULE WINAPI GetModuleHandle(
__in_opt LPCTSTR lpModuleName
);
GetModuleHandle函数
检索模块句柄指定的模块。该模块必须是加载调用进程。
为了避免在比赛中的备注一节所述的条件,使用GetModuleHandleEx功能。
参数
lpModuleName [中,可选]
加载的模块的名称(或者一个。dll或。exe文件)。如果文件扩展名被省略,默认的库扩展的。dll追加。该文件名字符串可以包含一个尾随点字符(。)表明,模块的名称没有扩展名。该字符串没有指定路径。当指定的路径,一定要使用反斜杠(\\),而不是正斜杠(/)。这个名字是比较(下独立),以目前的模块将调用进程的地址空间映射名称。
如果该参数为NULL,GetModuleHandle返回的句柄用于创建调用进程(。exe文件)的文件。
该GetModuleHandle函数不检索处理该被装用LOAD_LIBRARY_AS_DATAFILE标志模块。有关更多信息,请参阅LoadLibraryEx。
返回值
如果函数成功,返回值是一个句柄指定的模块。
如果函数失败,返回值为NULL。为了获得更多错误信息,调用GetLastError。
备注
返回的句柄不是全球或继承。它不能被复制或由另一个进程使用。
如果lpModuleName不包括道路,有多个具有相同的基本名称和扩展加载的模块,您无法预测的模块句柄将返回。若要解决此问题,您可以指定一个路径,请使用侧的并行程序集,或者使用GetModuleHandleEx指定内存位置,而不是DLL名称。
该GetModuleHandle函数返回一个未经处理的引用计数递增到映射模块。因此,请务必小心路过时的句柄FreeLibrary函数,因为这样做可能导致DLL模块被映射过早。
此函数必须小心使用,在多线程应用程序。没有任何保证模块句柄仍然有效,这之间的时间函数返回的句柄和它的使用时间。例如,一个线程检索模块句柄,但在它使用的处理,第二个线程释放模块。如果系统负载另一个模块,它可以重复使用的模块句柄最近获释。因此,第一个线程将有一个模块句柄一个比预期的不同。
实例
有关示例,请参阅使用画笔。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode和ANSI namesGetModuleHandleW(Unicode)和GetModuleHandleA(ANSI)的
参见
动态链接库函数
FreeLibrary
GetModuleFileName
GetModuleHandleEx
调用LoadLibrary
LoadLibraryEx
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==GetModuleHandle Function
Retrieves a module handle for the specified module. The module must have been loaded by the calling process.
To avoid the race conditions described in the Remarks section, use the GetModuleHandleEx function.
Syntax
C++
HMODULE WINAPI GetModuleHandle(
__in_opt LPCTSTR lpModuleName
);
Parameters
lpModuleName [in, optional]
The name of the loaded module (either a .dll or .exe file). If the file name extension is omitted, the default library extension .dll is appended. The file name string can include a trailing point character (.) to indicate that the module name has no extension. The string does not have to specify a path. When specifying a path, be sure to use backslashes (\\), not forward slashes (/). The name is compared (case independently) to the names of modules currently mapped into the address space of the calling process.
If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process (.exe file).
The GetModuleHandle function does not retrieve handles for modules that were loaded using the LOAD_LIBRARY_AS_DATAFILE flag. For more information, see LoadLibraryEx .
Return Value
If the function succeeds, the return value is a handle to the specified module.
If the function fails, the return value is NULL. To get extended error information, call GetLastError .
Remarks
The returned handle is not global or inheritable. It cannot be duplicated or used by another process.
If lpModuleName does not include a path and there is more than one loaded module with the same base name and extension, you cannot predict which module handle will be returned. To work around this problem, you could specify a path, use side-by-side assemblies , or use GetModuleHandleEx to specify a memory location rather than a DLL name.
The GetModuleHandle function returns a handle to a mapped module without incrementing its reference count. Therefore, use care when passing the handle to the FreeLibrary function, because doing so can cause a DLL module to be unmapped prematurely.
This function must be used carefully in a multithreaded application. There is no guarantee that the module handle remains valid between the time this function returns the handle and the time it is used. For example, a thread retrieves a module handle, but before it uses the handle, a second thread frees the module. If the system loads another module, it could reuse the module handle that was recently freed. Therefore, first thread would have a handle to a module different than the one intended.
Examples
For an example, see Using Brushes .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode and ANSI namesGetModuleHandleW (Unicode) and GetModuleHandleA (ANSI)
See Also
Dynamic-Link Library Functions
FreeLibrary
GetModuleFileName
GetModuleHandleEx
LoadLibrary
LoadLibraryEx
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms683199(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 11:30:57