title: Trying to read/write memory in C++
body: <p>I'm a programmer novice, I want to write some code to change the values in the store function in the windows calculator.
  I used Cheat engine to grab the address of the value store. I found this code online and copied it, but it won't write to the address.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  
  using namespace std;
  int main()
  {
  int newValue = 500;  //value to be written
  
  HWND hWnd = FindWindow(0, "Calculator");
  
  if (hWnd == 0){
      cerr &lt;&lt; "Cannot find window." &lt;&lt; endl;
  }
  else {
      DWORD pId;
      GetWindowThreadProcessId(hWnd, &amp;pId);
      HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pId);
  
      if (!hProc) {
          cerr &lt;&lt; "Cannot open process." &lt;&lt; endl;
      }
      else {
          int isSucessful = WriteProcessMemory(hProc, (LPVOID)0xD2FD6EAD0C, &amp;newValue, (DWORD)sizeof(newValue), NULL);
  
          if (isSucessful &gt; 0) {
              clog &lt;&lt; "Process memory written" &lt;&lt; endl;
          }
          else {
              cerr &lt;&lt; "Cannot write process memory" &lt;&lt; endl;
          }
  
          CloseHandle(hProc);
      }
  }
  return 0;
  }
  </code></pre>
  
  <p>When I execute it I get reply "cannot write process memory"
  is this any particular flaws in this code? I wrote it exactly as I read it from the dude who executed it in this video:<a href="https://www.youtube.com/watch?v=I0zPwg4iUDk" rel="nofollow">https://www.youtube.com/watch?v=I0zPwg4iUDk</a>.</p>