0

I have a COM Server function with an int parameter. When I call the function in Matlab and pass in "true" as an argument, C++ evaluates the passed in "true" value to -1 for my int parameter (I'm stepping through my code).

When I pass in "false", it evaluates to 0 just fine.

I'm doing this because I used to only allow true or false values for this parameter, but now I accept ints 0-4 so I maintain the same logic with inputs 0 and 1 for backwards compatibility.

I just don't understand why a "true" value evaluates to -1!

4

1 回答 1

2

From http://msdn.microsoft.com/en-us/library/t2t3725f.aspx : the default format for Boolean types marshaling is UnmanagedType.VariantBool which is

2-byte integer value where the value -1 represents true and 0 represents false

于 2013-05-10T19:13:20.697 回答