使用GetModuleInformation函数 [英] Use GetModuleInformation Function
本文介绍了使用GetModuleInformation函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用GetModuleInformation,但是每次使用它时,应用程序都会崩溃.
我的代码:
I have tryed to use the GetModuleInformation, but every time I used it, the application crash.
My code:
#include <windows.h>
#include <tlhelp32.h>
#include <psapi.h>
using namespace std;
HMODULE GetRemoteModuleHandle(DWORD lpProcessId, LPCSTR lpModule);
int main() {
HWND hWnd = FindWindow(0, "Counter-Strike Source");
if(hWnd == 0){
MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
}
else {
DWORD proccess_ID;
GetWindowThreadProcessId(hWnd, &proccess_ID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccess_ID);
HMODULE hModule = GetRemoteModuleHandle(proccess_ID, "engine.dll");
MODULEINFO mi;
GetModuleInformation(hProcess, hModule, &mi, sizeof(mi));
}
return 0;
}
HMODULE GetRemoteModuleHandle(DWORD lpProcessId, LPCSTR lpModule)
{
HMODULE hResult = NULL;
HANDLE hSnapshot;
MODULEENTRY32 me32;
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, lpProcessId);
if (hSnapshot != INVALID_HANDLE_VALUE)
{
me32.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnapshot, &me32))
{
do
{
if (!stricmp(me32.szModule, lpModule))
{
hResult = me32.hModule;
break;
}
}
while (Module32Next(hSnapshot, &me32));
}
CloseHandle(hSnapshot);
}
return hResult;
}
模块的句柄不是NULL,所以我认为它已创建! :O
我希望您能为我提供帮助:)
The Handle to the Module isn''t NULL so I think it is created! :O
I hope you can help me :)
推荐答案
我建议您在调试器下运行它,并在调用该函数的行上放置一个断点.
I suggest that you run it under the debugger, and put a break-point on the line where you call that function.
这篇关于使用GetModuleInformation函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文