C++/VB - API to determine if OS is 32bit or 64 bit.
Asked By DF on 14-Dec-08 09:59 PM
Looked at GetVersionEx but only returns build numbers.
GetSystemInfo returns processor type not OS bit type.
ISWOWProcess can report true for a 32 process in 64 bit OS - but 64 bit
process in 64 bit OS returns false so not definitive enough!
expvb replied on 14-Dec-08 10:52 PM
VB6 and earlier can only create 32 bits processes. If you are using DotNet,
then please post your question here:
This newsgroup is for VB6 and lower, which is incompatible with what you are
using. DotNet has separate groups; all of which have either "dotnet" or
then it's for VB6 and lower only.
Bill McCarthy replied on 15-Dec-08 03:09 AM
Hi DFA,
As has been said , VB6 is 32 bit only. If however you are still trying to
see if the host is 64 bit for some reason, then you can use the
GetNativeSystemInfo call. (note GetSsytemInfo call from VB6 will always
return 0 for the processor type)
The followign is Q&D from API viewer. you should probably replace dwOemID
with two words (16 bit, Integer):
WORD wProcessorArchitecture;
WORD wReserved;
Private Declare Sub GetNativeSystemInfo Lib "kernel32" (lpSystemInfo As
SYSTEM_INFO)
Private Type SYSTEM_INFO
dwOemID As Long
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOrfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
dwReserved As Long
End Type
Private Const PROCESSOR_ARCHITECTURE_INTEL = 0
Private Const PROCESSOR_ARCHITECTURE_IA64 = 6
Private Const PROCESSOR_ARCHITECTURE_AMD64 = 9
'
Dim si As SYSTEM_INFO
GetNativeSystemInfo si
MsgBox si.dwOemID
I saw someone else mentioned .NET. If that's applicable you can use the
above, changing Long to Int32. If you are deploying an app where you
haven't set explicitly to x64 or x86, you can simply test the IntPtr.Size as
that will be 4 bytes on x86 and 8 on x64.
MikeD replied on 15-Dec-08 04:38 PM
Call the GetNativeSystemInfo API function. This function is only supported under WinXP and later.
http://msdn.microsoft.com/en-us/library/ms724340(VS.85).aspx
Private Type SYSTEM_INFO
wProcessorArchitecture As Integer
wReserved As Integer
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
wProcessorLevel As Integer
wProcessorRevision As Integer
End Type
Private Declare Sub GetNativeSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
'Constants for GetSystemInfo and GetNativeSystemInfo API functions (SYSTEM_INFO structure)
Private Const PROCESSOR_ARCHITECTURE_AMD64 As Long = 9 'x64 (AMD or Intel)
Private Const PROCESSOR_ARCHITECTURE_IA64 As Long = 6 'Intel Itanium Processor Family (IPF)
Private Const PROCESSOR_ARCHITECTURE_INTEL As Long = 0 'x86
Private Const PROCESSOR_ARCHITECTURE_UNKNOWN As Long = &HFFFF& 'Unknown architecture
Private Const PROCESSOR_INTEL_386 As Long = 386
Private Const PROCESSOR_INTEL_486 As Long = 486
Private Const PROCESSOR_INTEL_PENTIUM As Long = 586
Private Const PROCESSOR_INTEL_IA64 As Long = 2200
Private Const PROCESSOR_AMD_X8664 As Long = 8664
Public Function IsOS64Bit() As Boolean
Dim si As SYSTEM_INFO
If IsWinXP Then 'can only call GetNativeSystemInfo under WinXP and later
Call GetNativeSystemInfo(si)
If (si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64) Or (si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_IA64)
Then
IsOS64Bit = True
Else
IsOS64Bit = False
End If
Else
IsOS64Bit = False
End If
End Function
(I figure you can write your own IsWinXP function; just make sure it returns True for XP AND LATER)
--
Mike
MikeD replied on 15-Dec-08 04:41 PM
What possibly indicates anything about .NET in that question?
it is quite possible to run a VB6 app on a 64 bit OS and need to know if the OS is 32 bit or 64 bit.
--
Mike
MikeD replied on 15-Dec-08 06:00 PM
Actually, in re-reading and noticing this time that he specifically
mentioned 64 bit processes, I guess you could come to the conclusion that he
was talking about .NET.
--
Mike
DF replied on 15-Dec-08 07:50 PM
So the SYSTEM_INFO.PROCESSORARCHITECTURE property is actually reporting the
OS "bit count (32/64)" NOT the hardware processor type?
This is not explained well in API docs.
Thanks
DFA
DF replied on 15-Dec-08 07:54 PM
I assumed the Windows API is language agnostic?
Is there a microsoft.public.winapi discussion group?
Thanks for the clarification
DFA
DF replied on 15-Dec-08 07:57 PM
Testing for int size seems a possibility. Not very OS deterministic though.
If API can report build numbers surely they can report bit size of the OS.
Regards
DFA
Karl E. Peterson replied on 15-Dec-08 08:33 PM
To an extent. Some languages are more naturally suited to calling it than others.
Take a look at the microsoft.public.win32.programmer.* hierarchy; there's actually
quite a selection. They too are not focused on using dotnet languages, but rather
more C/C++ oriented. If you can speak very generically, though, it's a good place
to try.
--
.NET: It's About Trust!
http://vfred.mvps.org
Larry Serflaten replied on 15-Dec-08 09:47 PM
You might try something like this:
Dim wmi, prc
Set wmi = GetObject("winmgmts:\\")
For Each prc In wmi.execQuery("SELECT * FROM Win32_Processor")
Debug.Print prc.Name, "Bit Sizes - ADDR:"; prc.AddressWidth, "DATA:"; prc.DataWidth
Next
LFS
MikeD replied on 16-Dec-08 09:34 AM
I suggest you take a look at this page:
http://msdn.microsoft.com/en-us/library/ms724429(VS.85).aspx
--
Mike
Alfred replied on 16-Dec-08 05:40 PM
The Windows api newsgroup is
Thorsten Albers replied on 17-Dec-08 07:37 AM
DFA <DFA@> schrieb im Beitrag
Other than with VB with C/C++ it is more or less essential to use the
Windows API. Therefore C/C++ related newsgroups are not separated into
Windows API and non-Windows API newsgroups. Just look for a newsgroup
appropiate for the programming language in use.
--
Thorsten Albers - albers (a) uni-freiburg.de