title: PInvoke marshalling of integers returning incorrect result
body: <p>I have a very simple function in an unmanaged DLL, but I'm not getting the correct return value back from it.  </p>
  
  <p>I can confirm that the general PInvoke mechanism is working with one function in my C DLL:</p>
  
  <pre><code>/* Return an integer */
  extern "C" __declspec(dllexport) long get_num()
  {
      return 42;
  }
  </code></pre>
  
  <p>I call the above unmanaged entry point like so from C# .NET:</p>
  
  <pre><code>[DllImport("My_C_DLL.dll")]
  extern static long get_num();
  // ...
  long ans = get_num();
  Console.WriteLine("The answer is {0}.", ans);
  </code></pre>
  
  <p>This works fine, but passing marshalled parameters to another function in the DLL returns a wrong result:</p>
  
  <pre><code>/* Add two integers */
  extern "C" __declspec(dllexport) long add_num(long a, long b)
  {
      long sum = a + b;
  
      return sum;
  }
  </code></pre>
  
  <p>Called from C# as:</p>
  
  <pre><code>[DllImport("My_C_DLL.dll")]
  extern static long add_num(long a, long b);
  
  long a = 6, b = 12;
  long sum = add_num(a, b);
  Console.WriteLine("The answer is {0}.", sum);
  </code></pre>
  
  <p>This gives me back a result of "6", or whatever I set the input value of <strong>a</strong> to be.</p>
  
  <p>I'm guessing that some incorrect marshalling of the input values is messing up the call stack, resulting in the bad return value, but where is the error?</p>