title: Writing a Python wrapper for difficult C header file using Cython
body: <p>A while back I wrote an thin wrapper around a commercial DAQ library
  using ctypes.  Since then I've come across Cython and wanted to give
  it a go, thinking it might make it better/cleaner all around than what
  I had before.  Most of the Cython documentation makes sense, and I've
  found most of what I know but the library I'm wrapping is highly
  windows specific and does things a little different than standard C/C+
  + code, at least as far as I can tell.</p>
  
  <p>Here's a couple of snippets from the header file, that I'm not exactly
  sure how to wrap.</p>
  
  <hr>
  
  <pre><code>#ifndef DAQ_H
  #define DAQ_H
  
  #ifdef   __cplusplus
  extern "C" {
  #endif
  
  #if !defined(_DAQAPI32_)
    #define  DAQAPI   __declspec(dllimport)
  #else
    #define  DAQAPI
  #endif
  </code></pre>
  
  <hr>
  
  <p>From what I gather, I probably can ignore most of this in my cython
  definition?  I've tried compiling C code with gcc, but it throws errors at every function definition.  With ctypes I accessed the library directly, and did not use the header file at all.</p>
  
  <hr>
  
  <pre><code>/* Handle Type Definition */
  typedef  INT   DaqHandleT;
  
  /* Initialization and Locking Prototypes */
  DAQAPI DaqHandleT WINAPI   daqOpen(LPSTR daqName);
  DAQAPI DaqError WINAPI     daqClose(DaqHandleT handle);
  DAQAPI DaqError WINAPI     daqOnline(DaqHandleT handle, PBOOL online);
  
  /* Error Handler Type Definitions */
  typedef VOID CALLBACK      DaqErrorHandlerFT(DaqHandleT handle,
  DaqError errCode);
  typedef DaqErrorHandlerFT  *DaqErrorHandlerFPT;
  
  /* Error Handler Function Prototypes */
  DAQAPI DaqError WINAPI  daqSetDefaultErrorHandler(DaqErrorHandlerFPT
  handler);
  DAQAPI DaqError WINAPI  daqSetErrorHandler(DaqHandleT handle,
  DaqErrorHandlerFPT handler);
  DAQAPI DaqError WINAPI  daqProcessError(DaqHandleT handle, DaqError
  errCode);
  DAQAPI DaqError WINAPI  daqGetLastError(DaqHandleT handle, DaqError
  *errCode);
  DAQAPI VOID CALLBACK    daqDefaultErrorHandler(DaqHandleT handle,
  DaqError errCode);
  DAQAPI DaqError WINAPI  daqFormatError(DaqError errorNum, PCHAR msg);
  </code></pre>
  
  <hr>
  
  <p>This is basically how most functions are declared and operate.  They
  only return error codes, all important information to get out of it is
  done through pointers.  I couldn't find anything in the documentation
  on how to work with pointers for return types, I probably didn't look
  hard enough.</p>
  
  <p>Can anyone point me in the right direction for wrapping these sorts of
  functions?</p>
  
  <p>Things like DaqError are actually enums declared in the header file,
  they go abit enum crazy in this library, some 1500 lines of it.</p>
  
  <p>Thanks for any help,</p>