EnumProcessModulesEx 无法返回错误代码 299 (ERROR_PARTIAL_COPY)

Dan*_*pez 1 c++ 64-bit winapi getlasterror windows-7

我正在调用该函数EnumProcessModulesEx,但它失败了。我在 64 位机器上运行。这是下面的代码:

wchar_t* dest = new wchar_t[100];
int index = SendMessage(processes, LB_GETCURSEL, 0, 0);
SendMessage(processes, LB_GETTEXT, index, (LPARAM)dest);
HMODULE module;
unsigned long cbneeded;
EnableTokenPrivilege(hWnd, SE_DEBUG_NAME);
HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, _wtoi(dest));
int errorcode = GetLastError();
BOOL ret = EnumProcessModulesEx(h, &module, sizeof module, &cbneeded, LIST_MODULES_ALL);
int err = GetLastError();
wchar_t* name = new wchar_t[MAX_PATH];
GetModuleBaseName(h, module, name, sizeof name);
MessageBox(hWnd, name, L"Process Name", 0);
delete dest;
delete name;
Run Code Online (Sandbox Code Playgroud)

And*_*rey 5

很可能您正在尝试从 64 位应用程序打开 32 位进程,反之亦然。您只能使用相同类型的流程。