title: Windows/Visual c++ | Weird behaviour of Struct in x64
body: <p>I want to read the PE-Headers of an x86 executeable on windows.
  To do that I use the standart stcructures given by the 'windows.h'.
  ('image' is in this example a char* to by mapped PE-Image)</p>
  <pre><code>int main()
  {
      IMAGE_DOS_HEADER* dosheader = PIMAGE_DOS_HEADER(image);
      IMAGE_NT_HEADERS32* ntheader = PIMAGE_NT_HEADERS32(DWORD(image) + dosheader-&gt;e_lfanew);
      std::cout &lt;&lt; &quot;breakpoint 1.&quot; &lt;&lt; std::endl;
      ntheader-&gt;Signature;
      std::cout &lt;&lt; &quot;breakpoint 2.&quot; &lt;&lt; std::endl;
  }
  
  </code></pre>
  <p>Output:</p>
  <pre><code>breakpoint 1.
  </code></pre>
  <p>Conclusion:
  Thn Program crashes when using a Variable of the Structure IMAGE_NT_HEADERS32.</p>
  <p><strong>Now the weird thing</strong>:<br/>
  I compile with Visual c++ compiler (cl.exe), with <br/>'[vcvarsall.bat] Environment initialized for: 'x64''<br/>
  <br/>
  But if I compile my code as x86 executeable, the Structure works just fine and both breakpoints get triggered.
  <br/>
  The IMAGE_DOS_HEADER structure works just fine, so i cant make myself any sense out of it.
  <br/>
  My Question is now: why does that happen? I mean the IMAGE_NT_HEADERS32 structure should be the same on both x64 and x86, isnt it?</p>