Reputation: 106
I have built a C# library that accesses a C
dll. The C
dll accesses an API that taps a communication bus. When a message is received on that bus, it generates an interrupt that runs a function (defined as a __cdecl pointer to a function in the C# library). I have a simple console application (C#
) where this all works properly, however when I try to integrate this into the final application (also C#
), I encounter PInvokeStackImbalance
system exception. This is not present in my console application.
When I explicitly add CallingConvention=CallingConvention.Cdecl
in my PInvoke
call, the system exception is resolved, however the interrupt/callback is not tripped in both console and final applications. I have read up on calling conventions but cannot figure out where the disconnect between the console application and final application is. The console app was built to be an analog for the final application aimed at testing the libraries for integration. Where can I look to find out more information about the configs for differences between the two applications, and more importantly, how do I pass a stdcall
pointer cleanly to a C
library?
Edit: This is for x86 development.
Upvotes: 1
Views: 76