title: How to pass a C++ callback function to a VB.NET program?
body: <p>I'm trying to pass a callback function from a C++ dll to a VB.NET application.
  Here is my current C++ code :</p>
  
  <pre><code>void DLL_EXPORT registerEvent( void (*callBackFunction)(string str),string str) 
      {
          callBackFunction(str);
      }
  
  void  test(string str)
      {
        MessageBoxA(0,str.c_str(), "",MB_OK);
      }
  
  LRESULT CALLBACK keyHandler(int nCode, WPARAM wParam, LPARAM lParam)
  
      {
        ...
       registerEvent(&amp;test, txt); //txt = the text received after user input with some additions
       return CallNextHookEx(hookHandle, nCode,
          wParam, lParam);
      }
  </code></pre>
  
  <p>This is working inside the C++ dll (the messagebox is called with the correct text)
  But i'd like to "trigger" the test procedure in the VB application with the text to use the VB Messagebox for example.</p>
  
  <p>Here is my current VB.NET code :</p>
  
  <pre><code> Public Delegate Sub Callback(ByVal str As String)
  
   Private Declare Sub registerEvent Lib "path\mycppdll.dll" _
      (ByVal cb As Callback, ByVal str As String)
  
   Dim cb As New Callback(AddressOf CallBackFunc)
   Public Sub CallBackFunc(ByVal str As String)
    'this should be the equivalent of the "test" proc in c++ but it's not triggered
  
   End Sub
  </code></pre>
  
  <p>I think i'm missing something ??!
  Any help will be appreciated !</p>