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

GetModuleInformation

鎖定
GetModuleInformation是計算機函數
中文名
GetModuleInformation函數 [1] 
外文名
GetModuleInformation
類    別
計算機函數名
功    能
獲取模塊信息並儲存在MODULEINFO [2] 
返回值
如果函數成功,將返回非零數值
hProcess
指向包含模塊的進程的句柄
lpmodinfo
指向 MODULEINFO 結構的指針

GetModuleInformation語法 Syntax

BOOL WINAPI GetModuleInformation
__in HANDLE hProcess,
__in HMODULE hModule,
__out LPMODULEINFO lpmodinfo,
__in DWORD cb

GetModuleInformation參數説明 Parameters

hProcess
指向包含模塊的進程的句柄。這個句柄一定要有 PROCESS_QUERY_INFORMATION 和 PROCESS_VM_READ 權限。參考 Process Security and Access Rights [3] 
hModule
指向模塊的句柄。
lpmodinfo
指向 MODULEINFO 結構的指針,該結構將會儲存關於模塊的信息。
cb
結構 MODULEINFO [2]  的大小(以字節計算)。

GetModuleInformation返回值 Return Value

如果函數成功,將返回非零數值
如果函數失敗,將會返回 0 。調用 GetLastError [4]  可得進一步信息。

GetModuleInformation附註 Remarks

要得到調用進程(即當前進程)的信息,可把 GetCurrentProcess [5]  返回值傳給 hProcess。
對於加載時被設置 LOAD_LIBRARY_AS_DATAFILE 標誌的模塊,該函數不會返回信息。更多信息參考 LoadLibraryEx [6] 
從 Window7 和 Windows Server 2008 R2 開始,Psapi.h 為 PSAPI 函數建立版本號。版本號會影響調用函數的名字和程序要加載的庫。(原文:Starting with Windows 7 and Windows Server 2008 R2, Psapi.h establishes version numbers for the PSAPI functions. The PSAPI version number affects the name used to call the function and the library that a program must load.)
如果 PSAPI_VERSION 是 2 或者更高,該函數將會在 Psapi.h 定義為 K32GetModuleInformation 並且由 Kernel32.lib 和 Kernel32.dll 導出。如果 PSAPI_VERSION 是 1,該函數被定義為 GetModuleInformation 並且由 Psapi.lib 和 Psapi.dll 封裝處理來調用 K32GetModuleInformation。(原文:If PSAPI_VERSION is 2 or greater, this function is defined as K32GetModuleInformation in Psapi.h and exported in Kernel32.lib and Kernel32.dll. If PSAPI_VERSION is 1, this function is defined as GetModuleInformation in Psapi.h and exported in Psapi.lib and Psapi.dll as a wrapper that calls K32GetModuleInformation.)
那些要運行在所有 Windows 版本的程序應該始終用 GetModuleInformation 名字來調用。為了確保名字正確,添加 Psapi.lib 到 TARGETLIBS macro(我不太清楚這東西,應該是説要引用 Psapi.lib)和用 –DPSAPI_VERSION=1 來編譯程序。要動態加載動態鏈接庫的要加載 Psapi.dll。(原文:Programs that must run on earlier versions of Windows as well as Windows 7 and later versions should always call this function as GetModuleInformation. To ensure correct resolution of symbols, add Psapi.lib to the TARGETLIBS macro and compile the program with –DPSAPI_VERSION=1. To use run-time dynamic linking, load Psapi.dll.)

GetModuleInformation要求 Requirements

客户端最低版本
Windows 2000 專業版/Windows 2000 Professional
服務器最低版本
Windows 2000 Server
頭文件
Psapi.h
庫/Library
Window 7 和 Windows Server 2008 R2 下:Kernel32.lib 和 Psapi.lib(如果 PSAPI_VERSION=1 )
Windows Server 2008,Windows Vista,Windows Server 2003 和 Windows XP/2000 下:Psapi.lib
動態鏈接庫/DLL
Window 7 和 Windows Server 2008 R2 下:Kernel32.dll 和 Psapi.dll(如果 PSAPI_VERSION=1 )
Windows Server 2008,Windows Vista,Windows Server 2003 和 Windows XP/2000 下:Psapi.dll
參考資料