Im using this tiny piece of code to get to know if my Windows is 32 or 64 bit:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
static int is64bitOS()
{
SYSTEM_INFO si;
GetSystemInfo(&si);
if((si.wProcessorArchitecture & PROCESSOR_ARCHITECTURE_IA64)||(si.wProcessorArchitecture & PROCESSOR_ARCHITECTURE_AMD64)==64)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
printf("%d\n", is64bitOS());
return 0;
}
I bought and installed 64 bit version of Windows 7 - however, the above code shows 0 meaning my os is 32 bit ... how to deal with it?
Ok, my other approaches, which basically do not work as well ... On my 64-bit Windows 7 I only see 32 bit ..
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
int getArchType1()
{
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
switch(sysInfo.wProcessorArchitecture)
{
case 6:
return 64;
case 9:
return 64;
case 0:
return 32;
default:
return -1;
}
}
static char *getArchType2()
{
char *archType = malloc(sizeof(char) * (255));
memset(archType, '\0', 255);
#if defined _WIN64
strcpy(archType, "64-bit");
#else
strcpy(archType, "32-bit");
#endif // defined
return archType;
}
int main()
{
char *arch = getArchType1();
printf("%s\n", arch);
free(arch);
printf("%d\n", getArchType2());
char c;
scanf("%c", &c);
return 0;
}