Skip to content

获取指定窗口所在进程的模块列表 - GetModuleInfoList

函数简介

获取指定窗口所在进程的模块列表。失败或没有模块时返回空字符串。

接口名称

GetModuleInfoList

DLL调用

c
OLA_STRING_RETURN OLA_CALL_TYPE GetModuleInfoList(int64_t instance, int64_t hwnd);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
hwnd长整数型窗口句柄或者进程ID。默认是窗口句柄。如果要指定为进程ID,需要调用 SetMemoryHwndAsProcessId

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
std::string result = ola.GetModuleInfoList(hwnd);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
string result = ola.GetModuleInfoList(hwnd);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
result = ola.GetModuleInfoList(hwnd)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
String result = ola.GetModuleInfoList(hwnd);
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
result := ola.GetModuleInfoList(hwnd)
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let result = ola.get_module_info_list(&hwnd);
cpp
var ola = com("OlaPlug.OlaSoft")
var result = ola.GetModuleInfoList(hwnd)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
result = ola.GetModuleInfoList(hwnd)
text
.局部变量 ola, OLAPlug
ola.创建 ()
result = ola.GetModuleInfoList(hwnd)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var result = ola.GetModuleInfoList(hwnd);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
文本型 result = ola.GetModuleInfoList(hwnd)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
std::string result = ola.GetModuleInfoList(hwnd);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long ptr = GetModuleInfoList(instance, hwnd);
if (ptr != 0) {
    int size = GetStringSize(ptr) + 1;
    char* buffer = new char[size];
    GetStringFromPtr(ptr, buffer, size);
    FreeStringPtr(ptr);
    delete[] buffer;
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long GetModuleInfoList(long ola, long hwnd);

long instance = CreateCOLAPlugInterFace();
long ptr = GetModuleInfoList(instance, hwnd);
if (ptr != 0) {
    StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
    GetStringFromPtr(ptr, sb, sb.Capacity);
    FreeStringPtr(ptr);
    string result = sb.ToString();
}
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.GetModuleInfoList.restype = c_int64
ola.GetStringSize.restype = c_int
instance = ola.CreateCOLAPlugInterFace()
ptr = ola.GetModuleInfoList(instance, hwnd)
if ptr:
    size = ola.GetStringSize(ptr) + 1
    buf = create_string_buffer(size)
    ola.GetStringFromPtr(ptr, buf, size)
    ola.FreeStringPtr(ptr)
    result = buf.value.decode("utf-8")

返回值

返回值说明
非空字符串模块列表。每条记录格式为 "name,base,size,path",多条记录用 "|" 分隔。
空字符串失败或没有模块。

示例:

ntdll.dll,140737488355328,2048000,C:\Windows\System32\ntdll.dll|kernel32.dll,...

解析时先按 "|" 分割记录,再按前三个逗号分割字段(路径中可能含逗号)。等价于按逗号最多拆成 4 段:

python
for rec in result.split("|"):
    name, base, size, path = rec.split(",", 3)

SDK 直接返回字符串;原生 DLL 返回字符串指针,需调用 FreeStringPtr 释放内存。模块列表可能较长,原生调用请用 GetStringSize 分配缓冲区。

注意事项

项目说明
释放内存DLL 调用返回字符串指针地址,需要调用 FreeStringPtr 接口释放内存。
hwnd 语义默认按窗口句柄;调用 SetMemoryHwndAsProcessId 后按进程 ID。
路径字段路径中可能含逗号,不可按逗号无限拆分,只拆前三个逗号。
单模块信息已知模块名时可用 GetModuleBaseAddrGetModuleSize

相关接口