判断进程是64bit还是32bit


#pragma
region
Includes
#include
<stdio.h>
#include
<windows.h>
#pragma
endregion
BOOL  DoesWin32MethodExist(PCWSTR pszModuleName, PCSTR pszMethodName){
HMODULE hModule = GetModuleHandle(pszModuleName);
if (hModule == NULL){
return FALSE;
}
return (GetProcAddress(hModule, pszMethodName) != NULL);
}
BOOL Is64BitOperatingSystem(){
#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
BOOL f64bitOS = FALSE;
return (DoesWin32MethodExist(L"kernel32.dll", "IsWow64Process") && (
IsWow64Process(GetCurrentProcess(), &f64bitOS) && f64bitOS));
#else
return FALSE; // 64-bit Windows does not support Win16
#endif
}
BOOL Is64BitProcess(HANDLE hProcess)
{BOOL f64bitProc = FALSE;
if (Is64BitOperatingSystem())
{
f64bitProc = !(IsWow64Process(hProcess, &f64bitProc) && f64bitProc
);
}
return f64bitProc;
}
int wmain(int argc, wchar_t* argv[])
{if (argc> 1)
{
DWORD dwProcessId = _wtoi(argv[1]);
if (dwProcessId == 0 /*conversion failed*/){
wprintf(L"Invalid process ID.\n");
return 1;
}
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessId);
if (hProcess != NULL){
BOOL f64bitProc = Is64BitProcess(hProcess);
wprintf(L"The process is a %bit process.\n", f64bitProc ? L"64" : L"32");
CloseHandle(hProcess);
}
else
{wprintf(L"OpenProcess(%d) failed w/err 0x%08lx\n", dwProcessId, GetLastError());
}
}
else
{
BOOL f64bitProc = Is64BitProcess(GetCurrentProcess());
wprintf(L"Current process is a %bit process.\n", f64bitProc ? L"64" : L"32");
}
return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值