According to the on line help it said I1. However your assertion is
bool parameters in functions defined in the same unmanaged DLL. When I
working. Perhaps there was some stack corruption due to the unmarshaled
Hmm ... looking over my code I use U1 in most cases and in the callback
I'm using I1. Seems to work but I will revert the I1 to U1 for consistancy.
Michael Phillips, Jr. wrote:
> Did you try using UnmanagedType.U1 to represent bool?
>
> See:
>
http://msdn2.microsoft.com/en-us/library/t2t3725f.aspx >
> "J.R. Heisey" <jrheisey@synaptics.com> wrote in message
> news:uKfXHhHMIHA.4272@TK2MSFTNGP05.phx.gbl...
>
>>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
>>
>>
>
>