title: WriteProcessMemory() Error 998
body: <p>I'm getting <code>error 998 (access denied)</code> with writeprocessmemory in <code>C++</code>.
  I don't know what I'm doing wrong.</p>
  
  <p>Here's some of my code:</p>
  
  <pre><code>DWORD ProcessId;
          GetWindowThreadProcessId(WindowHandle, &amp;ProcessId); //pID
          if (ProcessId) {}
          else {
              cout &lt;&lt; "ERROR! Process ID Could not be received." &lt;&lt; endl;
              return 0;
          }
  
          //Get the Process Handle
          HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, false, ProcessId);
          if (ProcessId) {}
          else {
              cout &lt;&lt; "ERROR! Process Handle could not be received." &lt;&lt; endl;
              return 0;
          }
  
          //Get it done with.
          bool MemWritten = WriteProcessMemory(ProcessHandle, Address, &amp;NewValue, sizeof(NewValue), NULL);
  
          //Close the process handle to prevent memory leak.
          CloseHandle(ProcessHandle);
  </code></pre>