title: Program crashes when trying to dereference non null pointer to BYTE aka(unsigned char)
body: <p>I'm trying to dereference the <code>modBaseAddr</code> (<code>BYTE*</code> aka <code>unsigned char*</code>) member of a <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms684225(v=vs.85).aspx" rel="nofollow">MODULEENTRY32</a> structure in <code>tlhelp32.h</code>. But when I try to dereference it my program crashes. I did an <code>if</code> statement to make sure it wasn't a <code>nullptr</code>. It isn't but my program still crashes. Here's my code:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;tlhelp32.h&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      DWORD pid = 0xFFFFFFFF;
      MODULEENTRY32 mod_entry;
      mod_entry.dwSize = sizeof(MODULEENTRY32);
      HANDLE procH;
  
      cout &lt;&lt; "PID: " &lt;&lt; flush;
      cin &gt;&gt; pid;
  
      procH = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE|TH32CS_SNAPMODULE32, pid);
      if(procH == INVALID_HANDLE_VALUE)
      {
          cout &lt;&lt; "Failed to retrieve process handle" &lt;&lt; endl;
          CloseHandle(procH);
          return 1;
      }
      if(!(Module32First(procH, &amp;mod_entry))){cout &lt;&lt; "Mod32 1st failed\n";CloseHandle(procH);return 1;}
  
      if(mod_entry.modBaseAddr == nullptr){cout &lt;&lt; "modBaseAddr is empty\n";CloseHandle(procH);return 1;}
      BYTE mod_baseaddr = *mod_entry.modBaseAddr; //&lt;-------------------Causes program to crash.
  
      return 0;
  }
  </code></pre>