C++ -- OpenProcess returns error code 87
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.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论