title: Why would C# mark all methods and types as System.Runtime.InteropServices.Charset.Ansi?
body: <p>I was playing around with Visual Studio today, doing some C# to PInvoke some stuff from Win32 APIs. That is when I noticed this caption (please open in new tab to view full size) </p>
  
  <p><img src="https://i.stack.imgur.com/aWJIU.png" alt="Visual Studio"></p>
  
  <p>It reads:</p>
  
  <blockquote>
    <p>Although the common language runtime default is System.Runtime.InteropServices.CharSet.Auto, languages may override this default. For example, by default C# marks all methods and types as System.Runtime.InteropServices.CharSet.Ansi.</p>
  </blockquote>
  
  <p>Why ANSI? From reading Mark Russinovich's <em>Windows Internals,</em> I have read:</p>
  
  <blockquote>
    <p>Because many applications deal with 8-bit (single-byte) ANSI character strings, many Windows 
    functions that accept string parameters have two entry points: a Unicode (wide, 16-bit) version and 
    an ANSI (narrow, 8-bit) version. <strong>If you call the narrow version of a Windows function, there is a slight performance impact as input string parameters are converted to Unicode before being processed 
    by the system and output parameters are converted from Unicode to ANSI before being returned to 
    the application.</strong></p>
  </blockquote>
  
  <p>So, am I understanding correctly that C#'s default when PInvoking unmanaged code  is to accept that performance impact?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>So if I do something like: </p>
  
  <pre><code>[DllImport("kernel32.dll", Charset = CharSet.Auto]
  public static extern bool Foo(IntPtr hHandle);
  </code></pre>
  
  <p>And let's say that inside kernel32.dll, there exists a <code>FooA</code> and a <code>FooW</code> ... how does C# know which entry point to use?  The help text in Visual Studio makes me think that it'll choose the ANSI entry point by default, but we would prefer the wide version if a performance impact (however negligible) can be avoided.</p>