title: Calling IsWowProcess2 from C# .NET (P/Invoke)
body: <p>I have never created a P/Invoke wrapper method in C# because there's a way to do it "the managed way" using .NET Framework classes.</p>
  
  <p>However, I have the need to invoke Win32 API function and I discovered that it's not as easy as I thought. </p>
  
  <p>The function in IsWowProcess2, and the code to call it from C++ is illustrated here.</p>
  
  <p><a href="http://www.rudyhuyn.com/blog/2017/12/13/how-to-detect-that-your-x86-application-runs-on-windows-on-arm/" rel="nofollow noreferrer">http://www.rudyhuyn.com/blog/2017/12/13/how-to-detect-that-your-x86-application-runs-on-windows-on-arm/</a></p>
  
  <p>I've created a silly program to test it, but of course, it doesn't work:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          var result = IsWowProcess2();
      }
  
      [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = false, PreserveSig = true)]
      private static extern MyStruct IsWowProcess2();
  }
  
  internal class MyStruct
  {
      public ushort One { get; set; }
      public ushort Two { get; set; }
  }
  </code></pre>
  
  <p>What's the correct way to create the wrapper method and how to invoke it?</p>