473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How big is a C BOOLEAN

Stupid question, but since I can't find it in the VS help...
I need to create a structure and pass it to a Win32 API function.

How many bytes is a C BOOLEAN? And is it the same size as a C#
bool/System.Boolean? If so is it set (values) the same, or do I need to
create an integer of the required size and set it to 0 or -1 as required for
passing to the external Win32 DLL?

Thanks.

Dale


Nov 22 '05 #1
4 2631
There is a method you can call in .net to show the size, but I dont have it
handy, you would instantiate some variable then print and call something to
show the size;

Isnt a C boolean the same size as INT?

And I think its either zero for false or non-zero (undefined) for true?
"Dale" <da******@foxcustomsoftware.com> wrote in message
news:aV7td.448262$nl.23846@pd7tw3no...
Stupid question, but since I can't find it in the VS help...
I need to create a structure and pass it to a Win32 API function.

How many bytes is a C BOOLEAN? And is it the same size as a C#
bool/System.Boolean? If so is it set (values) the same, or do I need to
create an integer of the required size and set it to 0 or -1 as required for passing to the external Win32 DLL?

Thanks.

Dale

Nov 22 '05 #2
>> How many bytes is a C BOOLEAN? And is it the same size as a C#
bool/System.Boolean? If so is it set (values) the same, or do I need to
create an integer of the required size and set it to 0 or -1 as required

for
passing to the external Win32 DLL?

I don't think C has a BOOLEAN type. Most likely a #define.
But if you have it defined somewhere and you want the size,
try printing sizeof(BOOLEAN).
You can also print TRUE and FALSE (also #defines, if you ask me)
--
Mihai
-------------------------
Replace _year_ with _ to get the real email
Nov 22 '05 #3
Stupid question, but since I can't find it in the VS help...
Not exactly what you're asking for, but see
http://msdn.microsoft.com/library/en...orbooleans.asp

How many bytes is a C BOOLEAN?
The Win32 BOOELAN type is 1 byte. It's defined as

typedef BYTE BOOLEAN;

in Winnt.h in the Platform SDK.

And is it the same size as a C# bool/System.Boolean?
Yes

If so is it set (values) the same, or do I need to
create an integer of the required size and set it to 0 or -1 as required for
passing to the external Win32 DLL?


No, the runtime can handle marshaling a managed bool to various kinds
of native ones, including BOOLEAN. Just apply the
MarshalAs(UnmanagedType.U1) attribute like the MSDN page linked to
above says.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 22 '05 #4
Beware the booleans!
Win32 defines different versions of booleans.
1. BOOL used by most Win32 API's, is an unsigned int (4 bytes)
2. BOOLEAN is a single byte, only used by a few win32 API's!!
3. and C/C++ has it's builtin 'bool' which is a single byte

Willy.

"Dale" <da******@foxcustomsoftware.com> wrote in message
news:aV7td.448262$nl.23846@pd7tw3no...
Stupid question, but since I can't find it in the VS help...
I need to create a structure and pass it to a Win32 API function.

How many bytes is a C BOOLEAN? And is it the same size as a C#
bool/System.Boolean? If so is it set (values) the same, or do I need to
create an integer of the required size and set it to 0 or -1 as required
for
passing to the external Win32 DLL?

Thanks.

Dale

Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: greg | last post by:
Discussion is invited on the following proto-PEP. ------------------------------------------------------------- PEP ??? - Overloadable Boolean Operators...
2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
8
by: Metro Sauper | last post by:
Why is the default text representation for booleans in C# 'True' and 'False' whereas in xml it is 'true' and 'false'? It seems like it would make sense to have them both the same. Metro T....
2
by: Raj | last post by:
Hi, When we are sorting the DataGrid Boolean column the grid is becoming redcross. I have my own PPMIPDataGridBoolColumn class inherited from System.Windows.Forms.DataGridBoolColumn. In this...
10
by: Henri | last post by:
In java for instance there's a way to use booleans as objects and not as value types. I would like to do the same in VB.NET so that I can check if the boolean has been explicitely defined (is not...
0
by: ECathell | last post by:
Ok this may be a silly question...but here goes... I need to extend the boolean type. the reason for this is I have a base collection that has boolean properties. Then my inherited class has...
5
by: Rob Meade | last post by:
Hi all, Quick question if I may... I have a function which depending on whether it was succesful to do something or not returns True or False as a boolean. I have another function which...
10
by: dba123 | last post by:
Why am I getting this error for Budget? Error: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: String was not...
16
by: Shawnk | last post by:
I would like to perform various boolean operations on bitmapped (FlagsAttribute) enum types for a state machine design as in; ------------------- enum portState { Unknown, Open,
19
by: tshad | last post by:
I have a value in my sql table set to tinyint (can't set to bit). I am trying to move it into a boolean field in my program and have tried: isTrue = (int)dbReader and isTrue =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.