-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.cpp
More file actions
59 lines (45 loc) · 1.19 KB
/
utils.cpp
File metadata and controls
59 lines (45 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <Windows.h>
#include <TlHelp32.h>
#include "utils.h"
typedef BOOL (*START_LISTEN)(DWORD pid, int port);
typedef BOOL(*STOP_LISTEN)(DWORD pid);
DWORD ProcessNameFindPID(LPCSTR ProcessName)
{
HANDLE ProcessAll = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS ,NULL);
PROCESSENTRY32 ProcessEntry = {0};
ProcessEntry.dwSize = sizeof(PROCESSENTRY32);
do
{
if (strcmp((char *)ProcessEntry.szExeFile, ProcessName) == 0)
{
return ProcessEntry.th32ProcessID;
}
} while (Process32Next(ProcessAll, &ProcessEntry));
MessageBox(NULL, "未找到进程", "错误", 0);
return 0;
}
BOOL StartListen(DWORD PID , int port)
{
HMODULE hDLL = LoadLibrary(DLLNAME);
if (hDLL == NULL)
{
MessageBox(NULL, "未找到DLL", "错误", 0);
return FALSE;
}
START_LISTEN pStartListen = (START_LISTEN)GetProcAddress(hDLL, "start_listen"); // 获取函数指针
pStartListen(PID, port);
FreeLibrary(hDLL); // 使用完后释放。
return TRUE;
}
BOOL StopListen(DWORD PID)
{
HMODULE hDLL = LoadLibrary(DLLNAME);
if (hDLL == NULL)
{
return FALSE;
}
STOP_LISTEN pStopListen = (STOP_LISTEN)GetProcAddress(hDLL, "stop_listen"); // 获取函数指针
pStopListen(PID);
FreeLibrary(hDLL); // 使用完后释放。
return TRUE;
}