Link to home
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.


Thanks
Avatar of zhtet
zhtet

ASKER

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++.
Avatar of zhtet

ASKER

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..
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.
Avatar of zhtet

ASKER

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...
you can use GetSystemInfo() and  GetNativeSystemInfo() functions.
Avatar of zhtet

ASKER

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?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial