Avatar of zhtet
zhtet asked on

C++ check bitness of OS

Hi, I am wondering if there is a way to determine the bitness (can safely assume it's either 32bit or 64bit) of the OS from a C++ 32bit program. Tried sizeof and limits but they are all defined to be 32bit for INT's, either cause it's a 32bit program, or visual C++'s LLP64 architecture is restricting it, whichever.

Visual C++.NET

Avatar of undefined
Last Comment
Jaime Olivares

8/22/2022 - Mon

Correction on my statement above, it's the 32bit-ness of the program causing INT's to remain 32 bit since pointers are still 32 bit as well, i.e. it's not VC++.

to give a better context, i have to load the msado dll, and the program is 32 bit, but i will be compiling it on both 32 and 64 bit machines... i.e. it will be
#import "C:\Program files\Common Files\System\Ado\msado15.dll" rename("EOF", "ADOEOF") or
#import "C:\Program Files (x86)\Common Files\System\Ado\msado15.dll"

depending on the OS...

hope that clears it up..
Jaime Olivares

you can evaluate the sizeof any pointer:

int bits = sizeof(void *) * 8;

notice even if you are running a 64-bit OS, your application not always use 64-bit pointers, it could still have 32-bit pointers.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

yea i stated above, my application is 32 bit, so it still  using 32 bit ptr's though the OS is 64 bit... i need to find out the OS bitness... since it could very well be a 32 bit machine i am compiling on...
Jaime Olivares

you can use GetSystemInfo() and  GetNativeSystemInfo() functions.

but aren't these as well as IsWow64Process all run-time functions? since i am importing a dll to be included during compile time, i would need to know this fact during compile time. or am i mistaken?

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Jaime Olivares

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question