We help IT Professionals succeed at work.

C++ check bitness of OS

zhtet
zhtet asked
on
385 Views
Last Modified: 2012-06-21
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
Comment
Watch Question

Author

Commented:
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++.

Author

Commented:
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 OlivaresSoftware Architect
CERTIFIED EXPERT
Top Expert 2008

Commented:
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.

Author

Commented:
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 OlivaresSoftware Architect
CERTIFIED EXPERT
Top Expert 2008

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

Author

Commented:
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
Software Architect
CERTIFIED EXPERT
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.