主题
枚举进程 - EnumProcess
函数简介
根据指定进程名,枚举系统中符合条件的进程PID,按进程启动顺序排序。
接口名称
EnumProcessDLL调用
long EnumProcess(long ola, string name);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| name | 字符串 | 进程名,支持模糊匹配。为空字符串则枚举所有进程。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
std::string result = ola.EnumProcess("value");csharp
using OLAPlug;
var ola = new OLAPlugServer();
string result = ola.EnumProcess("value");python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
result = ola.EnumProcess("value")java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
String result = ola.EnumProcess("value");cpp
var ola = com("OlaPlug.OlaSoft")
var result = ola.EnumProcess("value")vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
result = ola.EnumProcess("value")text
.局部变量 ola, OLAPlug
ola.创建 ()
result = ola.EnumProcess(“value”)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var result = ola.EnumProcess("value");text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
文本型 result = ola.EnumProcess("value")cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
std::string result = ola.EnumProcess("value");原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long ptr = EnumProcess(instance, "value");
if (ptr != 0) {
char buffer[512] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}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 EnumProcess(long ola, string name);
long instance = CreateCOLAPlugInterFace();
long ptr = EnumProcess(instance, "value");
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
instance = ola.CreateCOLAPlugInterFace()
ptr = ola.EnumProcess(instance, "value")
if ptr:
buf = create_string_buffer(512)
ola.GetStringFromPtr(ptr, buf, 512)
ola.FreeStringPtr(ptr)
result = buf.value.decode("utf-8")返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 字符串指针地址,包含所有匹配的进程PID,格式为 "pid1,pid2,pid3"。未找到返回空字符串。 |
注意事项
| 项目 | 说明 |
|---|---|
| 释放内存 | DLL调用返回字符串指针地址,需要调用 FreeStringPtr 接口释放内存。 |
| 进程ID列表按启动时间排序 | 进程ID列表按启动时间排序,越早启动的进程排在越前面。 |
