News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Effective size of BOOL

Started by DRX, January 21, 2012, 07:17:49 AM

Previous topic - Next topic

DRX

I noticed when working on a MASM project earlier today that a byte variable I was using was getting overwritten by a value returned from an API call.  Here's some background:

...

.data?
...
SuccessIndicator db ?
MyVar db ?
...

According to the documentation (for GetDlgItemInt, as I recall) the SuccessIndicator variable is of type BOOL, which according to the 32-bit windows.inc is actually a BYTE.  However, it appears that the SuccessIndicator value is treated like a DWORD, because MyVar was no longer being overwritten when I assembled the following:

...

.data?
...
SuccessIndicator db ?
db 3 DUP (?)
MyVar db ?
...

So my question is, are all BOOL values treated like this (as DWORD) by the API?
If so, does the same go for those that are effectively WORD values as well?

jj2007

Quote from: DRX on January 21, 2012, 07:17:49 AMBOOL, which according to the 32-bit windows.inc is actually a BYTE.

Sure?

include \masm32\MasmBasic\MasmBasic.inc   ; download
   Init
   MsgBox 0, Str$("BOOL=%i", BOOL), "Surprise:", MB_OK
   Exit
end start

sinsi

From windows.inc (I assume you are using it).
QuoteBOOL typedef DWORD

Light travels faster than sound, that's why some people seem bright until you hear them.

DRX

You guys are right :red.  It is:
BOOL typedef DWORD

I was using my old Win98 computer (because it has the necessary MIDI hardware) and old version '98 compatible version of MASM for this project and messed up the find command in searching for BOOL, so all I saw was the old "bool typedef BYTE" in the 8-bit section of the windows.inc file.

Lesson learned: I will check the .inc file thoroughly first before trying assembling a new project in x64 ABI where (without looking) I suspect the BOOL would be a QWORD.

bomz

Quote.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib

.data
mestitle   db "Bomz",0
form      db "BOOL Size: %u bytes", 0


.data?
buffer      db 512 dup(?)
variable   BOOL ?

.code
start:
invoke wsprintf,ADDR buffer,ADDR form,SIZEOF variable
invoke MessageBox,0,ADDR buffer,ADDR mestitle,MB_ICONASTERISK
invoke ExitProcess,0
end start

dedndave

"BOOL" and "bool" are different animals

but - you may find that "BOOL" is platform dependant
it's a C thing - we try to avoid it, other than when MS uses it   :P