I've built a DLL using PellesC that needs to be used from C#. Some functions exported from this DLL return a boolean (bool from stdbool.h). How large are these things? Logically, they should be 1 bit ofcourse, but one function executes a "return false" that in C# sometimes is interpreted as 'true'. A bit of research showed the LSB in the return value can be trusted but the rest of the word cannot, so in the header of the DLL it says:
#include <stdbool.h>
__declspec( dllexport ) bool __stdcall foo( void );
but in C# I need to define and use it as follows:
[DllImport( "foo.dll")]
public static extern int foo( void );
if ( (foo() & 0x01) == 0 )
{
// Do something interesting here
}
...which obviously should've been:
[DllImport( "foo.dll")]
public static extern bool foo( void );
if (!foo() )
{
// Do something interesting here
}
Unfortunately, the DLL's API is fixed because the same sources are used in another platform's implementation. I can't just change the return values from bool to int (which would be a debatable workaround anyway).
So, what it boils down to: how large is a bool returnvalue? Does it match C#'s idea of a boolean?