473,320 Members | 2,107 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,320 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 16 '05 #1
4 2076
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 16 '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 16 '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 16 '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 16 '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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.