I have C++ project with functions:
_API void __stdcall InstallMailHandler(MailHdlPtrType Hdl)
{ ... }
_API void __stdcall UninstallMailHandler(MailHdlPtrType Hdl)
{ ... }
typedef void (STDCALL *MailHdlPtrType)(unsigned char instNo, bla bla bla);
And I have in C#:
public static extern void InstallMailHandler(MailHdlPtrType Hdl);
public static extern void UninstallMailHandler(MailHdlPtrType Hdl);
public delegate void MailHdlPtrType(byte instno, bla bla bla);
But when I call InstallMailHandler and UninstallMailHandler from C# with the same function in arguments, it results in different addresses in C++ so it cannot uninstall previously installed mail handler.
Is it possible to somehow ensure that both invokes will result in the same function address, or maybe set an address explicitly?
I think the problem is that the new delegate object is created in each call.
You probably call them like that:
or in equivalent short form:
I think you just need to keep the same delegate: