Here is some code, to illustrate my implementation:
In the dll:
typedef void (CALLBACK * UCANEVENT_CALLBACK)( void );
A function to pass the callback function:
UCAN_API eUCANERROR_T eUCanOpenDriver( UCANEVENT_CALLBACK
lpEventCallbackFn );
Where...
UCAN_API is defined as: extern "C" __declspec(dllexport)
eUCANERROR_T is an enumeration.
In the C# code:
public delegate void UCanEventCallbackDelegate( );
[DllImport("UCanApi.dll")]
public static extern eUCANERROR eUCanOpenDriver(
UCanEventCallbackDelegate lpEventCallbackFn);
(This is defined as a member function of the class
CUCanApi)
UCanEventCallbackDelegate MyUCanEventCallback =
new UCanEventCallbackDelegate( UCanEventCallback );
eError = CUCanApi.eUCanOpenDriver( MyUCanEventCallback );
// Callback implementation
void UCanEventCallback( )
{
....
}
-----Original Message-----
When the callback is invoked from the dll, I get a
fatal error, that shuts down the app.
So you're passing out the delegate to unmanaged code?
Can you post some code?
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ |
http://www.dotnetinterop.comPlease reply only to the newsgroup.
.