J.R. Heisey
11/26/2007 10:04:00 PM
I have a DLL that takes a pointer to a callback function of type:
typedef void ( __stdcall * StdMyCallback_T)(void* context, const char *
sName, bool bState,
EError error, const char * pErrorMsg);
I have defined a delegate as such:
public delegate void MyCallbackDelegate(IntPtr iPtr, IntPtr sName,
[In,MarshalAs( UnmanagedType.I1 )] bool bState, Error error,
IntPtr sErrorMsg);
The callback function in managed code is defined as:
private void CDCI_My_Callback_Handler(IntPtr iPtr, IntPtr sName, bool
bState,Error error,
IntPtr
sErrorMsg)
{
MyEventArgs evt = new MyEventArgs(sName, bState,error,
sErrorMsg);
... // other stuff
}
However the bState parameter is not properly marshaled. In the MarshalAs
directive I've also tried UnmanagedType.Bool. When I look at the assembly
code in the C++ based unmanaged DLL for the parameter bState, I see the al
register getting set then eax register is pushed onto the stack. Three extra
bytes with undefined values are pushed. I expect for memory alignment
reasons. Now how do I get the Managed code to marshal the bool parameter
properly?
Microsoft you listening?
Thanks,
J.R. Heisey