码迷,mamicode.com
首页 > Windows程序 > 详细

[转]判断程序是否运行在 Windows x64 系统下

时间:2016-06-17 22:31:33      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:

以下功能代码判断是否运行在 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.\n"));
    else {
        if (!IsWow64())
            _tprintf(TEXT("The application is running under Windows x86.\n"));
        else
            _tprintf(TEXT("The application is a x86 program running under Windows x64.\n"));
    }
 
    return 0;
}
 
 
 
原文地址:http://fenying.blog.163.com/blog/static/10205599320137224339263/

[转]判断程序是否运行在 Windows x64 系统下

标签:

原文地址:http://www.cnblogs.com/schowen/p/5595210.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!