> | Hi
> |
[quoted text clipped - 56 lines]
>
> Willy.
Thanks for your reply Willy
Perhaps my example was unclear. The problem does not lie with passing
the bool to the unmanaged dll nor does it lie with with the return from
the unmanaged dll, it lies with the unmanaged dll calling a managed
callback with a BOOL as a parameter. (FYI it doesn't matter if you use
a c++ bool, a char, DWORD or whatever - the problem is still the same)
If you step through the code, the unmanaged dll, cleary calls the
callback with TRUE but it appears as false in the csharp code. Even
changing the delegate prototype to the following does not solve the
problem:
private static extern bool BoolCallback(BoolCallbackDelegate
lpBoolCallBack,[MarshalAs(UnmanagedType.Bool)]bool b);
The c++ clr version (below) of my csharp example works so it looks like
a problem with csharp?!?
ref class Program
{
private:
delegate bool BoolCallbackDelgate(bool b);
static bool GetBool(bool b)
{
return b;
}
public:
static void Main()
{
BoolCallbackDelgate^ fp = gcnew BoolCallbackDelgate(GetBool);
GCHandle gch = GCHandle::Alloc(fp);
IntPtr ip = Marshal::GetFunctionPointerForDelegate(fp);
BoolCallBack cb = static_cast<BoolCallBack>(ip.ToPointer());
bool b = BoolCallback(cb, true);
Debug::Assert(b == true);
b = BoolCallback(cb, false);
Debug::Assert(b == false);
}
};
Mark
Willy Denoyette [MVP] - 20 Nov 2006 18:00 GMT
>> | Hi
>> |
[quoted text clipped - 103 lines]
>
> Mark
typedef bool (__stdcall *BoolCallBack)(short b);
should be:
typedef bool (__stdcall *BoolCallBack)(BOOL b);
Willy.