title: C#: Implementation of, or alternative to, StrCmpLogicalW in shlwapi.dll
body: <p>For natural sorting in my application I currently P/Invoke a function called StrCmpLogicalW in shlwapi.dll. I was thinking about trying to run my application under Mono, but then of course I can't have this P/Invoke stuff (as far as I know anyways).</p>
  
  <p>Is it possible to see the implementation of that method somewhere, or is there a good, clean and efficient C# snippet which does the same thing?</p>
  
  <p>My code currently looks like this:</p>
  
  <pre><code>[SuppressUnmanagedCodeSecurity]
  internal static class SafeNativeMethods
  {
      [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
      public static extern int StrCmpLogicalW(string psz1, string psz2);
  }
  
  public class NaturalStringComparer : IComparer&lt;string&gt;
  {
      private readonly int modifier = 1;
  
      public NaturalStringComparer() : this(false) {}
      public NaturalStringComparer(bool descending)
      {
          if (descending) modifier = -1;
      }
  
      public int Compare(string a, string b)
      {
          return SafeNativeMethods.StrCmpLogicalW(a ?? "", b ?? "") * modifier;
      }
  }
  </code></pre>
  
  <p>So, what I'm looking for is an alternative to the above class which doesn't use an extern function.</p>