CLI/BOOL to bool conversion.
-
I've got a C++ app that makes calls into a C# library. One of the calls in the C# lib is: void myFunc ( bool Flag ) I've done some marshalling for strings in other functions, but the bool has me scratching my head. How do I convert my C++ BOOL to a .NET bool for my C# call? What am I overlooking? Any help you could send would be appreciated. Cheers. Mike.
-
I've got a C++ app that makes calls into a C# library. One of the calls in the C# lib is: void myFunc ( bool Flag ) I've done some marshalling for strings in other functions, but the bool has me scratching my head. How do I convert my C++ BOOL to a .NET bool for my C# call? What am I overlooking? Any help you could send would be appreciated. Cheers. Mike.
Mike Doner wrote:
How do I convert my C++ BOOL to a .NET bool for my C# call?
The C++ BOOL translates to the C# int. In C++, a BOOL evaluates to FALSE if it's 0,and to TRUE if it's non-zero (though typically TRUE evaluates to 1). To convert a BOOL value to the C# bool, compare with 0. Example:
BOOL cpp = TRUE;
bool cs = (bool)(cpp != 0); // the cast may or may not be needed, you can check that out.
C++/CLI correctly treats bool as the .NET bool type. [Edit]when I said evaluate above, it practically means a #define since there is no actual evaluation there[/Edit]
Regards, Nish
My technology blog: voidnish.wordpress.com Code Project Forums : New Posts Monitor This application monitors for new posts in the Code Project forums.
modified on Tuesday, September 28, 2010 1:02 PM
-
Mike Doner wrote:
How do I convert my C++ BOOL to a .NET bool for my C# call?
The C++ BOOL translates to the C# int. In C++, a BOOL evaluates to FALSE if it's 0,and to TRUE if it's non-zero (though typically TRUE evaluates to 1). To convert a BOOL value to the C# bool, compare with 0. Example:
BOOL cpp = TRUE;
bool cs = (bool)(cpp != 0); // the cast may or may not be needed, you can check that out.
C++/CLI correctly treats bool as the .NET bool type. [Edit]when I said evaluate above, it practically means a #define since there is no actual evaluation there[/Edit]
Regards, Nish
My technology blog: voidnish.wordpress.com Code Project Forums : New Posts Monitor This application monitors for new posts in the Code Project forums.
modified on Tuesday, September 28, 2010 1:02 PM
Thanks Nish, That did it... I knew it had to be simple. Cheers. M.