title: Problems with pinvoke signatures throwing System.AccessViolationException with libuiohook
body: <p>I'm trying to write a wrapper for <a href="https://github.com/kwhat/libuiohook" rel="nofollow">libuiohook</a> in C# using P/Invoke.
  But I can't even get the simple <code>hook_run</code> signature to work.</p>
  
  <p>My code:</p>
  
  <pre><code>static void Main(string[] args)
  {
      var result = Start();
      Console.WriteLine(result);
      Console.ReadLine();
      Stop();
  }
  
  [DllImport("libuiohook", EntryPoint = "hook_stop", 
  CallingConvention = CallingConvention.Cdecl)] //StdCall gives the same problems
  private static extern int Stop();
  
  [DllImport("libuiohook", EntryPoint = "hook_run", 
  CallingConvention = CallingConvention.Cdecl)]
  private static extern int Start();
  </code></pre>
  
  <p>The native interface is: (<a href="https://github.com/kwhat/libuiohook/blob/master/include/uiohook.h" rel="nofollow">Full public interface</a>)</p>
  
  <pre><code>// Insert the event hook.
  UIOHOOK_API int hook_run();
  
  // Withdraw the event hook.
  UIOHOOK_API int hook_stop();
  </code></pre>
  
  <p>It keeps throwing <code>System.AccessViolationException</code> or blocks at <code>Start()</code>.
  What is the problem with the signatures?</p>