Hi there,
we have this C++ DLL we wrote some time ago to do some Win32 native
stuff for us.
The function we're calling in the DLL returns a boolean value (type
bool) indicating success of the operation.
We declare the import in C# like follows:
DllImport("xyz.dll")]
private static extern bool DoSomething(...);
We call the function like this:
bool result = DoSomething(...);
Now: we're using this in Visual Studio 2008. When we set the target
framework version to 2.0 everything works fine - the function returns
false, the result-variable has the value false.
As soon as we switch the target framework version to 3.5 (no other
changes to the project), the C++ function still returns false, but the
result-variable is set to true!
How could that be?
As a workaround we've change the result type from bool to int, returning
defined values for success or failure, but this is not very satisfactory...
Any advice?
Thanks
Thorsten
Willy Denoyette [MVP] - 20 Mar 2008 13:47 GMT
> Hi there,
>
[quoted text clipped - 31 lines]
> Thanks
> Thorsten
If you are sure that the C function returns a bool, and not a BOOL, then it
should work, else you should marshal the return value using:
[return: MarshalAs(UnmanagedType.Bool)]
Willy.