複製鏈接
請複製以下鏈接發送給好友

GetModuleHandle

鎖定
GetModuleHandle是一個計算機函數,功能是獲取一個應用程序或動態鏈接庫的模塊句柄。只有在當前進程的場景中,這個句柄才會有效。
中文名
獲取模塊句柄
外文名
GetModuleHandle
性    質
API函數
返回值
HMODULE

GetModuleHandle返回值

HMODULE,如執行成功成功,則返回模塊句柄。零表示失敗。獲取錯誤信息,請調用GetLastError

GetModuleHandle參數表

lpModuleName String,指定模塊名,這通常是與模塊的文件名相同的一個名字。例如,NOTEPAD.EXE程序的模塊文件名就叫作NOTEPAD。NULL則返回調用進程本身的句柄。

GetModuleHandle注意事項

只有欲獲取的模塊已映射到調用該函數的進程內,才會正確得到模塊句柄。常用模塊映射函數:LoadLibrary

GetModuleHandle函數聲明

GetModuleHandleC++聲明

HMODULE WINAPI GetModuleHandle(
_In_opt_LPCTSTR lpModuleName
);

GetModuleHandleVB聲明

Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long

GetModuleHandleC#聲明

[DllImport("kernel32")]
public static extern int GetModuleHandle(string lpModuleName);

GetModuleHandleVC聲明

HMODULE GetModuleHandle(
LPCTSTRlpModuleName);

GetModuleHandle彙編聲明

GetModuleHandle,lpModuleName
函數的作用是返回指定模塊名的句柄,如果為NULL,則返回本模塊的句柄。
返回的句柄值存放在寄存器eax中。
lpModuleName參數是一個指向含有模塊名稱字符串的指針
使用舉例:
.686p
.xmm
.mmx
.model flat,stdcall
option casemap:none
.data
szUserDll db 'User32.dll',0
.data?
hUserDllHandle dd?
sbError
invoke ExitProcess,0
start:
invoke GetModuleHandle,offsetszUserDll
test eax,eax
je sbError
mov hUserDllHandle,eax
end start
...

GetModuleHandle易語言聲明

Ansi版本:
.版本 2
.DLL命令 GetModuleHandleA, 整數型, "kernel32.dll", "GetModuleHandleA"
.參數 lpModuleName, 文本型
Unicode版本:
.版本 2
.DLL命令 GetModuleHandleW, 整數型, "kernel32.dll", "GetModuleHandleW"
.參數 lpModuleName, 字節集