思路:
1.先判断是否为64位系统
2.判断是否为64位程序
代码:
// ProcessType.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//判断运行程序exe是否为64位程序
#include <iostream>
#include <Windows.h>
using namespace std;
//判断是否为64位系统
bool is64BitOS()
{
SYSTEM_INFO cur_system_info;
GetNativeSystemInfo(&cur_system_info);
WORD system_str= cur_system_info.wProcessorArchitecture;
//判断是否为64位系统
if (system_str == PROCESSOR_ARCHITECTURE_IA64 || system_str == PROCESSOR_ARCHITECTURE_AMD64)
{
return true;
}
return false;
}
//判断是否为64位进程
//@param:进程id
/*
Parameters
hProcess
A handle to the process. The handle must have the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right. For more information, see Process Security and Access Rights.
Windows Server 2003 and Windows XP: The handle must have the PROCESS_QUERY_INFORMATION access right.
Wow64Process
A pointer to a value that is set to TRUE if the process is running under WOW64 on an Intel64 or x64 processor. If the process is running under 32-bit Windows, the value is set to FALSE. If the process is a 32-bit application running under 64-bit Windows 10 on ARM, the value is set to FALSE. If the process is a 64-bit application running under 64-bit Windows, the value is also set to FALSE.
*/
bool is64BitProcess(DWORD dwPid)
{
if (!is64BitOS())
{
cout << "is 32 Bit OS";
return false;
}
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwPid);
if (hProcess)
{
typedef BOOL(WINAPI * LPEN_ISWOW64PROCESS)(HANDLE, PBOOL);
LPEN_ISWOW64PROCESS fnlsWow64Process = (LPEN_ISWOW64PROCESS)GetProcAddress(GetModuleHandleW(L"kernel32"), "IsWow64Process");
if (NULL!=fnlsWow64Process)
{
BOOL bIsWow64 = FALSE;
fnlsWow64Process(hProcess, &bIsWow64);
CloseHandle(hProcess);
return !bIsWow64;
}
}
return false;
}
int main()
{
DWORD dwPid = GetCurrentProcessId();
bool flag_bit = is64BitProcess(dwPid);
cout << flag_bit << endl;
//is64BitOS();
//std::cout << "Hello World!\n";
}