+ Reply to Thread
Results 1 to 6 of 6

Calling Windows API with boolean argument in 64bit Excel: long, byte or boolean?

  1. #1
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Question Calling Windows API with boolean argument in 64bit Excel: long, byte or boolean?

    I need to use the following function of the Windows API:

    Please Login or Register  to view this content.
    According to this page the argument bInheritHandle is a C++ BOOL that, if I'm correct, is 8bit.
    So, in place of xxxxxxx I don't know what data type to use: long, byte or boolean?

    Reason to use byte: VBA byte is 8bit as it's C++ boolean
    Reason to use boolean: because, despite it's 16bits in VBA, it's conceptually the same as a C++ 8bit boolean
    Reason to use long: because most (of the few) examples I find on the web use this
    Last edited by 6diegodiego9; 06-23-2022 at 03:20 AM.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Calling Windows API with boolean argument in 64bit Excel: long, byte or boolean?

    According to Microsoft ... it's a Long
    Please Login or Register  to view this content.
    Not saying it is - that declaration was copied from an MS supplied file and we all know how diligent MS is with things like this.

    Edit: Tried to upload but too large, even zipped. Download link: https://docs.microsoft.com/en-us/off...64-bit-support
    Last edited by cytop; 06-22-2022 at 09:35 AM.

  3. #3
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: Calling Windows API with boolean argument in 64bit Excel: long, byte or boolean?

    Quote Originally Posted by cytop View Post
    According to Microsoft ... it's a Long
    Please Login or Register  to view this content.
    Not saying it is - that declaration was copied from an MS supplied file and we all know how diligent MS is with things like this.

    Edit: Tried to upload but too large, even zipped. Download link: https://docs.microsoft.com/en-us/off...64-bit-support
    Thanks for the link! I didn't know this reference.

    I'm going to accept this as a solution but I keep the question open: why are the natively boolean arguments or return values in Windows API declared as long in VBA?

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: Calling Windows API with boolean argument in 64bit Excel: long, byte or boolean?

    Because booleans in VB6/VBA are not the same as the BOOL type. They are different sizes (2 bytes in VB and 4 in Win32 API - basically an INT) and True is -1 in VBA but 1 in the API.
    Rory

  5. #5
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: Calling Windows API with boolean argument in 64bit Excel: long, byte or boolean?

    Quote Originally Posted by rorya View Post
    Because booleans in VB6/VBA are not the same as the BOOL type. They are different sizes (2 bytes in VB and 4 in Win32 API - basically an INT) and True is -1 in VBA but 1 in the API.
    Ah! the fact(?) that it's 32bit in Win32 API changes all.
    I thought that it was 8bit because I read it in this well accepted post on StackOverflow: https://stackoverflow.com/a/12023089/11738627

    So, do you know what "BOOLEAN" he's talking about there?

    Attachment 784849

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: Calling Windows API with boolean argument in 64bit Excel: long, byte or boolean?

    BOOL and BOOLEAN are not the same (confusingly). In their typedef statements BOOL is INT, BOOLEAN is Byte.

    Edit: See this article: https://docs.microsoft.com/en-gb/win...ectedfrom=MSDN

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Exit Workbook_BeforeClose(Cancel As Boolean) if a public boolean = true
    By meabrams in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2016, 06:10 AM
  2. boolean in excel vba
    By daboho in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2016, 11:28 AM
  3. Optional Boolean Argument
    By cpfrona in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2015, 01:27 AM
  4. Cancel as Boolean argument
    By Larry.LeBlanc@O in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2015, 01:29 PM
  5. Replies: 3
    Last Post: 11-23-2012, 01:57 AM
  6. Using a Boolean function within an If statement: Argument not optional error message
    By elfsprin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-16-2011, 04:12 PM
  7. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) problem
    By 2funny4words in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2009, 07:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1