Hi
My C# app is being called from a callback from an unmanaged DLL. One of
the parameters of the callback is of type BOOL. I am using PInvoke to
marshal this to a (managed) bool. The problem is that no matter if we
pass TRUE or FALSE, the bool is always marshalled as true.
// unmanaged code in dll
typedef bool (__stdcall *BoolCallBack)( short b);
extern "C" BOOL __declspec(dlle xport) __stdcall
BoolCallback(Bo olCallBack lpBoolCallBack, BOOL b)
{
return lpBoolCallBack( b);
}
// c#
private delegate bool BoolCallbackDel egate(bool b);
[DllImport("Unma nagedDll")]
private static extern bool BoolCallback(Bo olCallbackDeleg ate
lpBoolCallBack, bool b);
private static bool BoolCallbackDel gate(bool b)
{
return b;
}
static void Main(string[] args)
{
bool b = BoolCallback(Bo olCallbackDelga te, true);
Debug.Assert(b == true);
b = BoolCallback(Bo olCallbackDelga te, false);
Debug.Assert(b == false);
}
The second Assert alwasys asserts because the callback is returning
true when it should be false.
I think that this is a bug somewhere in c#/clr/PInkove because this
doesnt happen in c++ clr. I think it was fixed for c++ clr under this
kb article http://support.microsoft.com/default.aspx?kbid=823071 but
not fixed for c#.
Any thoughts?
Mark