I've been able to get most things working with regard to mapping from unmanaged C++ to C#, but the area I'm having a problem with is with a C++ callback to a C# delegate. The delegate is being called and executing, but when the delegate ends and sends the return code to C++, I'm getting a Windows error. Nothing is being returned to the managed debugger and the app just dies.
I would really appreciate any help that could be provided. The following is what I've been working with. Thanks.
Expand|Select|Wrap|Line Numbers
- 3-d Party C++:
- _declspec(dllexport) ULONG NIrtd_startDataStream(
- NIrtd_tAPIauth *authorization,
- NIrtd_tQuery *query,
- ULONG updateRate,
- NIrtd_funCallback callback,
- void *yourpointer,
- NIrtd_tRequestId *requestId);
- /* Call back routine definition */
- typedef ULONG (* NIrtd_funCallback) (
- ULONG return_code,
- NIrtd_tRequestId requestid,
- NIrtd_stTableGroup * tableGroup,
- void * yourpointer);
- C++ Wrapper:
- extern "C" __declspec(dllimport) ULONG NIrtd_startDataStream_CLib(
- AuthInfo_CLib *authInfoStruct,
- Query_CLib *queryStruct,
- ULONG updateRate,
- NIrtd_funCallback callback,
- AppPtr_CLib *appPtr,
- Request_CLib *requestStruct
- );
- C#:
- public delegate uint RealTimeCallBack(uint return_code,
- IntPtr requestId,
- ref TableGroupStruct tableGroup,
- ref IntPtr appPtr);
- private static RealTimeCallBack _RealTimeCallBack = null;
- private uint RealTimeCallBackHandler(uint return_code,
- IntPtr requestId,
- ref TableGroupStruct tableGroupStruct,
- ref IntPtr appPtr)
- {
- try
- {
- Console.WriteLine("server: Callback handler called");
- }
- catch(Exception ex)
- {
- throw new Exception("RealTimeCallBackHandler: " +
- ex.ToString() );
- }
- return 0;
- }
- [DllImport("RtdApi.dll")]
- public static extern uint NIrtd_startDataStream_CLib(
- ref AuthInfo authInfo,
- ref Query query,
- uint updateRate,
- RealTimeCallBack callback,
- ref AppPtr appPtr,
- ref Request request);
As mentioned, the startDataStream_CLib is setting things up properly and the delegate is being fired, but it's after the delegate ends (after the closing brace) that the app dies.
Any ideas?
Thanks.
Juan