title: How To Marshal Return Values Of WinApi Functions?
body: <p><strong>Simple:</strong> How can I <strong>explicitly marshal</strong> the result of a WinAPi function ?
  <hr>
  I know how to marshal parameters of WinApi functions in C# but how can I also marshal the return values ? Or do I actually have to marshal them ? I understand WinAPi returns only <code>BOOL</code> or all types of <code>INT</code> (handles are int as well in unmanaged code).</p>
  
  <pre><code>// common signature
  [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
  static extern int GetFileAttributes([MarshalAs(UnmanagedType.LPStr)] string filename);
  
  // my prefered signature because easy to handle the result
  [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
  static extern FileAttributes GetFileAttributes([MarshalAs(UnmanagedType.LPStr)] string filename);
  </code></pre>
  
  <p>Since <code>FileAttributes</code> is enum and each value can easily be cast to <code>int</code> I'm sure I'm safe with this notation. But can I marshal the result in this one signature like I do with the parameters ? I actually only know <code>Marshal</code> class and <code>MarshalAs</code> attribute.</p>