以下功能代码判断是否运行在 Windows x64 下。本例使用 Windows API 函数 IsWow64Process,具体请参考MSDN文档:http://msdn.microsoft.com/en-us/library/ms684139(VS.85).aspx
/**
* This program test if this application is a x64 program or
* is a x86 program running under Windows x64.
*
* Version: 0.1 C-Lang
* Author: Fenying
* Date: 2013-08-22
*/
#include <windows.h>
#include <tchar.h>
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
/**
* Don't use the function IsWow64Process as a static function,
* you should load it by function GetProcAddress, because
* it is not available on all version of Windows.
*/
LPFN_ISWOW64PROCESS fnIsWow64Process = NULL;
/**
* This function tells if your application is a x64 program.
*/
BOOL Isx64Application() {
return (sizeof(LPFN_ISWOW64PROCESS) == 8)? TRUE: FALSE;
}
/**
* This function tells if you're under Windows x64.
*/
BOOL IsWow64() {
BOOL bIsWow64 = FALSE;
if (!fnIsWow64Process)
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
if(fnIsWow64Process)
if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
return FALSE;
return bIsWow64;
}
int main( void ) {
if (Isx64Application())
_tprintf(TEXT("The application is a x64 program.
"));
else {
if (!IsWow64())
_tprintf(TEXT("The application is running under Windows x86.
"));
else
_tprintf(TEXT("The application is a x86 program running under Windows x64.
"));
}
return 0;
}
原文地址:http://fenying.blog.163.com/blog/static/10205599320137224339263/