title: Calling Convention of exported methods in ntdll.dll
body: <p>I have some trouble to call an exported method from Ntdll.dll</p>
  
  <p>In debug mode with VS2012 I do get:</p>
  
  <blockquote>
    <p>Run-Time Check Failure #0 - The value of ESP was not properly saved
    across a function call.  This is usually a result of calling a
    function declared with one calling convention with a function pointer
    declared with a different calling convention</p>
  </blockquote>
  
  <p>This is the code I have used (x86 platform, Windows 7).</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;Windows.h&gt;
  
  typedef NTSTATUS (* NTAPI  ZwClose)(HANDLE handle);
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      ZwClose close = (ZwClose) ::GetProcAddress(GetModuleHandle(L"ntdll.dll"), "ZwClose");
      close(INVALID_HANDLE_VALUE);  // Error happens here
          return -1;
  }
  </code></pre>
  
  <p>From what I have read it should work. I have also tried __cdecl and __fastcall as alternate calling conventions but nothing did work. </p>