title: Implement callback C# functions for C++ DLL
body: <p>I'm writing a DLL wrapper for my C++ library, to be called from C#. This wrapper should also have callback functions called from the library and implemented in C#. These functions have for instance std::vector&lt;unsigned char> as output parameters. I don't know how to make this. How do I pass a buffer of unknown size from C# to C++ via a callback function? </p>
  
  <p>Let's take this example</p>
  
  <pre><code>CallbackFunction FunctionImplementedInCSharp;
  
  void FunctionCalledFromLib(const std::vector&lt;unsigned char&gt;&amp; input, std::vector&lt;unsigned char&gt;&amp; output)
  {
      // Here FunctionImplementedInCSharp (C# delegate) should somehow be called
  }
  
  void RegisterFunction(CallbackFunction f)
  {
      FunctionImplementedInCSharp = f;
  }
  </code></pre>
  
  <p>How should  <code>CallbackFunction</code> be defined and what is the code inside FunctionCalledFromLib? </p>
  
  <p>One of the things that dumb me is: how do I delete a buffer created by C# inside C++ code?</p>