我尝试使用 Wisual Studio 2012、c++ 控制台应用程序打开进程并得到 87 错误:
#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#define EXTERN_DLL_EXPORT extern "C" __declspec(dllexport)
EXTERN_DLL_EXPORT int setLastObject(LPCWSTR wname) {
LPCWSTR str = _TEXT("Name of window");
HWND wnd = FindWindow(NULL,wname);
LPDWORD cpid = 0;
DWORD pid = GetWindowThreadProcessId(wnd,cpid);
HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS,false,pid);
int err = GetLastError();
return err;
}
PS我得到正确的pid