question

MarkusForrer-7355 avatar image
0 Votes"
MarkusForrer-7355 asked MarkusForrer-7355 commented

Callback C++ dll -> C#: Run-Time Check Failure #0

In my project I have a .net core 3.1 C# app and an unmanaged C++ dll. From the C++ dll I want to implement a callback. The callback works only once, then I get the error 'Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call'.

Thanks for any hints

88869-c.jpg88870-c.jpg


dotnet-csharp
c.jpg (50.7 KiB)
c.jpg (61.0 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your answer.

I changed the 3 __stdcall to __cdecl and now it works better (about 1 minute). After that I get the following error message on the line '_observer(message);': An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.

0 Votes 0 ·
Viorel-1 avatar image
0 Votes"
Viorel-1 answered

There is a discrepancy between CallingConvention.Cdecl and __stdcall. Try using the same convention.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MarkusForrer-7355 avatar image
0 Votes"
MarkusForrer-7355 answered MarkusForrer-7355 commented

Thank you for your answer.

I changed the 3 __stdcall to __cdecl and now it works better (about 1 minute). After that I get the following error message on the line '_observer(message);': An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


I think that the new issue is not caused by calling convention, but probably by incorrect handling of generated function pointer. To reproduce the problem, maybe you can show the current code, but this time as a text or attachment (perhaps in a new question, because it seems to need different solutions).

0 Votes 0 ·

I tried to post the test solution as a zip. But it's not possible. It is also not possible to post code as text. Could I send you the test solution my mail?

0 Votes 0 ·