You are currently browsing the archives for the Visual Studio category


How to check Windows or process is 64bit

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
bool Is64BitWindows()
{
#if defined(_WIN64)
	return true;  // 64-bit programs run only on Win64
#elif defined(_WIN32)
 
	// 32-bit programs run on both 32-bit and 64-bit Windows
	// so must sniff
	BOOL f64 = FALSE;
	LPFN_ISWOW64PROCESS fnIsWow64Process;
 
	fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
	if (NULL != fnIsWow64Process)
	{
		return !!(fnIsWow64Process(GetCurrentProcess(), &f64) && f64);
	}
 
	return false;
#else
	return false; // Win64 does not support Win16
#endif
}

http://stackoverflow.com/questions/336633/how-to-detect-windows-64-bit-platform-with-net

Other functions, for finding CPU and whether the process is 64bit.

typedef void(WINAPI *LPFN_GetNativeSystemInfo)(LPSYSTEM_INFO);
LPCWSTR GetPlatformW()
{
	static WCHAR sT[64];
	static bool done = false;
	if (done)
		return sT;
 
	LPFN_GetNativeSystemInfo fnGetNativeSystemInfo = (LPFN_GetNativeSystemInfo)GetProcAddress(
		GetModuleHandle(TEXT("kernel32")), "GetNativeSystemInfo");
 
	if (NULL == fnGetNativeSystemInfo)
	{
		lstrcpy(sT, L"Unknown");
	}
	else
	{
		SYSTEM_INFO si = { 0 };
		fnGetNativeSystemInfo(&si);
		switch (si.wProcessorArchitecture)
		{
		case PROCESSOR_ARCHITECTURE_AMD64:	lstrcpy(sT, L"AMD64");	break;
		case PROCESSOR_ARCHITECTURE_ARM:	lstrcpy(sT, L"ARM");	break;
		case PROCESSOR_ARCHITECTURE_IA64:	lstrcpy(sT, L"IA64");	break;
		case PROCESSOR_ARCHITECTURE_INTEL:	lstrcpy(sT, L"INTEL");	break;
		default:lstrcpy(sT, L"Unknown"); break;
		}
	}
	return sT;
}
 
bool Is64BitProcess()
{
#if defined(_WIN64)
	return true;
#else
	return false;
#endif
}

I tried to run this code only on AMD64. I don’t know what happens in ARM or IA64 platforms.

Differences of Command prompt of Visual Studio

There are many kind of shortcuts of command prompt of Visual Studio. Basically the differences are the setting of Host and Target. Host refers to the compiler or linker of which 64bit or 32bit is chosen. Target refers to the resultant exe or dll which is targeted 64bit or 32bit.

Developer Command Prompt for VS 2017 (default)

Host:32bit
Target:32bit

x64 Native Tools Command Prompt for VS 2017

Host:64bit
Target:64bit

x64_x86 Cross Tools Command Prompt for VS 2017

Host:64bit
Target:32bit

x86 Native Tools Command Prompt for VS 2017

Same as the default.

x86_x64 Cross Tools Command Prompt for VS 2017

Host:32bit
Target:64bit