title: Passing managed event handler to unmanaged code in Linux
body: <p>I've been writing a .Net Core C# wrapper for an existing C++ library that will run under Linux. The library has the following:</p>
  <pre><code>int newrelic_record_metric(const char *name, double value);
  
  void newrelic_register_message_handler(void*(*handler)(void*));
  
  void *newrelic_message_handler(void *raw_message);
  </code></pre>
  <p>The first method is easy enough to wrap:</p>
  <pre><code>internal static class AgentSdkWrapper {
      [DllImport(&quot;newrelic-transaction&quot;)]
      public static extern unsafe int newrelic_record_metric(StringBuilder name, double value);
  </code></pre>
  <p>I'm struggling with the signature of the second version, I don't know how I would translate that to C#. I understand I'm dealing with void pointers, but I'm unsure what to do with them.</p>
  <p>Also, according to the library docs, I need to register the third method as a callback to the second method:</p>
  <blockquote>
  <p>You must register the required callback that will send data to New Relic when transactions are  completed. You will need to register the default newrelic_message_handler callback that has already been defined:</p>
  <p>newrelic_register_message_handler(newrelic_message_handler);</p>
  </blockquote>
  <p>I presume I need to assign <code>newrelic_message_handler</code> to a C# delegate and pass that into <code>newrelic_register_message_handler</code>, but I'm unclear how I get there.</p>