开发者

C++ -- OpenProcess returns error code 87

开发者 https://www.devze.com 2023-01-31 21:21 出处:网络
I have this problem with OpenProcess function for the win32 api. Program is intended to read an integer from a program given the program PID and address of integer through userinput.

I have this problem with OpenProcess function for the win32 api. Program is intended to read an integer from a program given the program PID and address of integer through userinput.

int main() {

 DWORD pidz;

 int buffer[1];

 int temp;

 int* ptr_i;

 std::cout << "Type the address of i in programA: ";
 std::cin >> std::hex >> temp;
 std::cout << "\n";
 ptr_i = (int*)temp;

 std::cout << "Enter PID of programA: ";
 std::cin >> pidz;
 std::cout << "\n\n";

 HANDLE handle_prgmA = OpenProcess(PROCESS_ALL_ACCESS,0,pidz);
 if (handle_prgmA==NULL) {
  std::cout &l开发者_JS百科t;< "***Could not assign handle\n";
  HRESULT apa = GetLastError();
  std::cout << apa << "\n";
 }

 if (ReadProcessMemory(handle_prgmA,ptr_i,&buffer,4,NULL)) {
  std::cout << buffer[0];
 }
 else {
  std::cout << "***Could not read memory\n";


 }

 CloseHandle(handle_prgmA);


}

OpenProcess keeps returning error code 87("invalid parameters") and I have no idea why!


OpenProcess returns ERROR_INVALID_PARAMETER when you give it a PID of zero. Check to ensure the operator>>(std::istream&, int&) call succeeded before calling OpenProcess.

0

精彩评论

暂无评论...
验证码 换一张
取 消