title: Calling methods from C/C++ DLL with Python
body: <p>I do have a tutorial here about calling functions from a c/c++ dll, the example is written here from the <a href="https://docs.python.org/3.3/library/ctypes.html#function-prototypes" rel="nofollow">official tutorial</a>.</p>
  
  <pre><code>WINUSERAPI int WINAPI
  MessageBoxA(
      HWND hWnd,
      LPCSTR lpText,
      LPCSTR lpCaption,
      UINT uType);
  
  Here is the wrapping with ctypes:
  
  &gt;&gt;&gt;
  &gt;&gt;&gt; from ctypes import c_int, WINFUNCTYPE, windll
  &gt;&gt;&gt; from ctypes.wintypes import HWND, LPCSTR, UINT
  &gt;&gt;&gt; prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT)
  &gt;&gt;&gt; paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0)
  &gt;&gt;&gt; MessageBox = prototype(("MessageBoxA", windll.user32), paramflags)
  &gt;&gt;&gt;
  The MessageBox foreign function can now be called in these ways:
  
  &gt;&gt;&gt;
  &gt;&gt;&gt; MessageBox()
  &gt;&gt;&gt; MessageBox(text="Spam, spam, spam")
  &gt;&gt;&gt; MessageBox(flags=2, text="foo bar")
  &gt;&gt;&gt;
  A second example demonstrates output parameters. The win32 GetWindowRect function retrieves the dimensions of a specified window by copying them into RECT structure that the caller has to supply. Here is the C declaration:
  
  WINUSERAPI BOOL WINAPI
  GetWindowRect(
       HWND hWnd,
       LPRECT lpRect);
  Here is the wrapping with ctypes:
  
  &gt;&gt;&gt;
  &gt;&gt;&gt; from ctypes import POINTER, WINFUNCTYPE, windll, WinError
  &gt;&gt;&gt; from ctypes.wintypes import BOOL, HWND, RECT
  &gt;&gt;&gt; prototype = WINFUNCTYPE(BOOL, HWND, POINTER(RECT))
  &gt;&gt;&gt; paramflags = (1, "hwnd"), (2, "lprect")
  &gt;&gt;&gt; GetWindowRect = prototype(("GetWindowRect", windll.user32), paramflags)
  &gt;&gt;&gt;
  </code></pre>
  
  <p>This example works when the function is external, however, let's assume I have a reference to an object, and I want to call a function from that object with params, how do I do that?</p>
  
  <p>I did saw the log of all function signatures from 'dumpbin -exports', and I tried using the full name of the function, and still it didn't work.</p>
  
  <p>Any other ideas would be blessed.</p>