title: C++ ReadProcessMemory receiving 998 / 3E6 Error
body: <p>So I'm trying to read Memory out of a running exe with <code>ReadProcessMemory()</code> as you can see in the code provided below.
  The only problem I constantly run into is that I receive the Error 3E6 / 998 which seems to be <code>NOACCESS</code> but I cant find a solution to fix this.
  And yes I tried to run the exe in Admin Mode without success...</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;tlhelp32.h&gt;
  #include &lt;Psapi.h&gt;
  #include &lt;tchar.h&gt;
  
  using namespace std;
  
  int id = NULL;
  HANDLE hProcess = NULL;
  int getPID(const string name);
  bool setHandle(int id, HANDLE &amp;out);
  DWORD64 GetModule(const string name);
  
  int main()
  {
      bool success = false;
      id = getPID("sample.exe");
      string name = "SAMPLE";
      cout &lt;&lt; "Process Name: " &lt;&lt; name &lt;&lt; endl;
      cout &lt;&lt; "Process ID: " &lt;&lt; id &lt;&lt; endl;
  
      success = setHandle(id, hProcess);
      if (success)
      {
          cout &lt;&lt; "Handle set..." &lt;&lt; endl;
      }
      else if (!success) 
      {
          cout &lt;&lt; "You need to have SOMETHING opened..." &lt;&lt; endl;
          cout &lt;&lt; "ERROR CODE: " &lt;&lt; GetLastError() &lt;&lt; endl;
          system("pause");
          return 1;
      }
      success = false;
  
      DWORD64 baseAddress = GetModule("sample.exe");
      DWORD64 ammo = 0x24ED13273A8;
      DWORD64 addr = baseAddress + ammo;
  
      cout &lt;&lt; "Base Address: " &lt;&lt; hex &lt;&lt; uppercase &lt;&lt; "0x" &lt;&lt; baseAddress &lt;&lt; endl;
      cout &lt;&lt; "Ammo Address: " &lt;&lt; hex &lt;&lt; uppercase &lt;&lt; "0x" &lt;&lt; ammo &lt;&lt; endl;
      cout &lt;&lt; "Complete Address: " &lt;&lt; hex &lt;&lt; uppercase &lt;&lt; "0x" &lt;&lt; addr &lt;&lt; endl;
  
      int buffer = 0;
  
      success = ReadProcessMemory(hProcess, (LPCVOID)addr, (LPVOID)&amp;buffer, sizeof(&amp;buffer), NULL);
  
      if (success) 
      {
          cout &lt;&lt; "ReadProccess succeeded..." &lt;&lt; endl;
          system("pause");
          return 0;
      }
      else if (!success) 
      {
          cout &lt;&lt; "ERROR CODE: " &lt;&lt; GetLastError() &lt;&lt; endl;
          system("pause");
          return 1;
      }
  
      system("pause");
      return 0;
  
  }
  
  bool setHandle(int id, HANDLE &amp;out)
  {
      out = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
      if (!out) return false;
  
      return true;
  }
  
  int getPID(const string name)
  {
      PROCESSENTRY32 entry;
      entry.dwSize = sizeof(PROCESSENTRY32);
      HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  
      if (!Process32First(snapshot, &amp;entry)) return NULL;
  
      do
      {
          if (strcmp(entry.szExeFile, name.c_str()) == 0)
          {
              CloseHandle(snapshot);
              return entry.th32ProcessID;
          }
      } while (Process32Next(snapshot, &amp;entry));
  
      CloseHandle(snapshot);
      return NULL;
  }
  
  DWORD64 GetModule(const string name)
  {
      HMODULE hMods[1024];
      DWORD cbNeeded;
  
      if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &amp;cbNeeded))
      {
          for (int i = 0; i &lt; (cbNeeded / sizeof(HMODULE)); i++)
          {
              TCHAR szModName[MAX_PATH];
              if (GetModuleFileNameEx(hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR)))
              {
                  string modName = szModName;
                  if (modName.find(name) != string::npos)
                  {
                      return (DWORD64)hMods[i];
                  }
              }
          }
      }
      return NULL;
  }
  </code></pre>
  
  <p>I'm kinda new to c++... so sry? :)</p>