Help with managed function use as a callback for a native dll in vb.net
Hello,
I have a third party C dll that I am working with to integrate an hardware device into my application,
The main functions I am having problems with are as follows
int SetEvent(int, long);
the SetEvent functions above takes two parameters, the first one is an integer event Id and the second argument is a function pointer.
The function pointer is to be created by the user in any language of choice, and from the documentation, the prototype for the callback function goes like this:
int *callbackfunc(int code, int docid, char *code);
This callback is to be implemented in VB2010 and the (char* code) argument is to be used as a return parameter for retrieving a return character string from the native dll.
However I have been unable to get my code to work after trying out several suggestion I google on the internet.
Here is my code implementation of the callback function and the P/Invoke I used in my applications:
<br />
Public Declare Ansi Function mfSetEvent Lib "flib.dll" (ByVal nevent As System.Int32, <MarshalAs(UnmanagedType.FunctionPtr)> ByVal callback As System.Delegate) As System.Int32<br />
<br />
Public Delegate Function CodeLine(ByVal c As Integer, ByVal did As Integer, ByVal codeline As StringBuilder)<br />
<br />
Private Function OnCodeline(ByVal code As Integer, ByVal docid As Integer, ByVal codeline As StringBuilder)<br />
<br />
'Dim szcodeline As StringBuilder = New StringBuilder(100)<br />
' szcodeline = codeline<br />
' Console.Write("OnCodeline {0:D} {1:D} {2}" & vbNewLine, code, docid, szcodeline.ToString)<br />
Return 1<br />
End Function
However, when I run the application, my program always crashes without reporting an exception