zoukankan      html  css  js  c++  java
  • 判断进程是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. ");
    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. ", f64bitProc ? L"64" : L"32");
    CloseHandle(hProcess);
    }
    else
    {wprintf(L"OpenProcess(%d) failed w/err 0x%08lx ", dwProcessId, GetLastError());
    }
    }
    else
    {
    BOOL f64bitProc = Is64BitProcess(GetCurrentProcess());
    wprintf(L"Current process is a %bit process. ", f64bitProc ? L"64" : L"32");
    }
    return 0;
    }

    http://www.cnblogs.com/lzjsky/archive/2010/12/01/1893169.html

  • 相关阅读:
    Thinkpad R400无线网络一个都不见了!
    如果使用安卓4.4的SD卡?
    如何使用安卓4.4的SD卡?
    在IAR使用FreeRTOS出现Error[Pa045]: function "XXX" has no prototype
    DSP5509的RTC实验-第3篇
    LWM2M简介-学习记录
    DSP5509的定时器实验-第2篇
    DSP5509的XF实验-第一篇
    华为LiteOS系统使用-任务调度函数-第一篇
    2017-12-24自选的股票之春秋航空
  • 原文地址:https://www.cnblogs.com/findumars/p/5625100.html
Copyright © 2011-2022 走看看