ORC,
You could try, but it wouldn't be accurate. The reasoning behind BOOL
in Win32 is to provide a true/false value. Zero is false, true is not
false. There are really only two states that can be returned, they just
choose to use 32 bits to represent it. Since a bool represents the same
thing in .NET, they can be mapped accurately.
When the return type is an integer, then the state can be any value that
an int can represent. If you map this to bool (which in reality, has only
two values, true and false), you will not get an accurate representation of
the return value. You ^could^ do it, but you won't get the right
information back.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"ORC" <or*@sol.dk> wrote in message
news:ea**************@TK2MSFTNGP14.phx.gbl...
Thanks.
As the windows BOOL is defined as:
typedef int BOOL; in WINDEF.H
I assume that an API that returns an int can be marshalled to a C# bool -
or
am I wrong?
What about a BOOL (int) parameter in an API function - is that also
marshalled to C# bool ?
Thanks for your help!
Ole
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:OD****************@TK2MSFTNGP10.phx.gbl... >Is the bool type actually an Int32 with 0 as false and non zero as true?
No, bool is one byte.
>The
>reason for my question is that I've seen a lot of API calls that return
>a
>Int32 implemented in C# as an bool like:
>[DllImport("kernel32.dll", EntryPoint="PurgeComm", SetLastError=true)]
>private static extern bool PurgeComm( Int32 hFile, UInt32 dwFlags);
That's correct, the runtime can marshal a Win32 BOOL to a C# bool.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.