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

Markus Forrer 21 Reputation points
2021-04-19T05:55:23.523+00:00

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

Developer technologies | C#
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2021-04-19T07:05:48.03+00:00

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

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Markus Forrer 21 Reputation points
    2021-04-20T04:20:13.693+00:00

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.