title: How to detect that a given PE file (exe or dll) is 64 bit or 32 bit
body: <p>I need to detect whether a given .dll or .exe file is 32 bit or 64 bit</p>
  
  <p>At the moment I have only one solution: read the PE Header from the specified file and take the 'Machine' field from there.</p>
  
  <p>( Specification: <a href="http://download.microsoft.com/download/9/c/5/9c5b2167-8017-4bae-9fde-d599bac8184a/pecoff_v8.docx" rel="nofollow noreferrer">Microsoft Portable Executable and Common Object File Format Specification</a> (.docx file) at section "3.3. COFF File Header (Object and Image)" )</p>
  
  <p>This field can take up to about 20 values. Three of them are:</p>
  
  <pre><code>IMAGE_FILE_MACHINE_I386  ( == 32bit )
  
  IMAGE_FILE_MACHINE_IA64  ( == 64bit )
  
  IMAGE_FILE_MACHINE_AMD64 ( == 64bit )
  </code></pre>
  
  <p>My questions:</p>
  
  <p>1) Is 'Machine' to bitness mapping correct or did I miss something? Are there any other caveats?</p>
  
  <p>2) Is there easier way to detect 32/64 bitness (probably some specific field in PE format I didn't notice or some special system function)?</p>