最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C/C++ 獲取Windows系統(tǒng)的位數(shù)32位或64位的實(shí)現(xiàn)代碼

 更新時(shí)間:2017年10月27日 08:52:48   作者:infoworld  
這篇文章主要介紹了C/C++ 獲取Windows系統(tǒng)的位數(shù)32位或64位的實(shí)現(xiàn)代碼的相關(guān)資料,希望通過本文能幫助到大家,讓大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下

C/C++ 獲取Windows系統(tǒng)的位數(shù)32位或64位的實(shí)現(xiàn)代碼

場景

1.在Windows 64bit系統(tǒng)開發(fā)程序時(shí), 某些情況需要判斷Program Files路徑, 但是64bit系統(tǒng)有兩個(gè)Program Files或 Program Files(x86), 這時(shí)候就需要根據(jù)當(dāng)前系統(tǒng)的位數(shù)來獲取路徑了.

說明

1.通過判斷程序是32bit或64bit并沒有什么用,因?yàn)?4bit系統(tǒng)可以運(yùn)行32bit和64bit程序.

2.64bit系統(tǒng)的kernel32.dll 里有一個(gè)函數(shù)接口 IsWow64Process,只需要判斷這個(gè)dll是否有這個(gè)導(dǎo)出函數(shù)即可.

例子

// test-OSBit.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
//

#include "stdafx.h"
#include <Windows.h>
#include "Shlobj.h"
#include <iostream>


typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

static LPFN_ISWOW64PROCESS fnIsWow64Process = NULL;

//
//  FUNCTION: SafeIsWow64Process(HANDLE, PBOOL)
//
//  PURPOSE: This is a wrapper of the IsWow64Process API. It determines 
//  whether the specified process is running under WOW64. IsWow64Process 
//  does not exist prior to Windows XP with SP2 and Window Server 2003 with 
//  SP1. For compatibility with operating systems that do not support 
//  IsWow64Process, call GetProcAddress to detect whether IsWow64Process is 
/// implemented in Kernel32.dll. If GetProcAddress succeeds, it is safe to 
//  call IsWow64Process dynamically. Otherwise, WOW64 is not present.
//
//  PARAMETERS:
//  * hProcess - A handle to the process. 
//  * Wow64Process - A pointer to a value that is set to TRUE if the process 
//   is running under WOW64. If the process is running under 32-bit Windows, 
//   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.
//
//  RETURN VALUE: If the function succeeds, the return value is TRUE.If 
//  IsWow64Process does not exist in kernel32.dll, or the function fails, 
//  the return value is FALSE. 
//
static BOOL WINAPI SafeIsWow64Process(HANDLE hProcess, PBOOL Wow64Process)
{
  if (fnIsWow64Process == NULL)
  {
    // IsWow64Process is not available on all supported versions of 
    // Windows. Use GetModuleHandle to get a handle to the DLL that 
    // contains the function, and GetProcAddress to get a pointer to the 
    // function if available.
    HMODULE hModule = GetModuleHandle(L"kernel32.dll");
    if (hModule == NULL)
    {
      return FALSE;
    }

    fnIsWow64Process = reinterpret_cast<LPFN_ISWOW64PROCESS>(
      GetProcAddress(hModule, "IsWow64Process"));
    if (fnIsWow64Process == NULL)
    {
      return FALSE;
    }
  }
  return fnIsWow64Process(hProcess, Wow64Process);
}

//
//  FUNCTION: Is64BitOS()
//
//  PURPOSE: The function determines whether the current operating system is 
//  a 64-bit operating system.
//
//  RETURN VALUE: The function returns TRUE if the operating system is 
//  64-bit; otherwise, it returns FALSE.
//
static BOOL Is64BitOS()
{
#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 (SafeIsWow64Process(GetCurrentProcess(), &f64bitOS) && f64bitOS);
#else
  return FALSE; // 64-bit Windows does not support Win16
#endif
}

int _tmain(int argc, _TCHAR* argv[])
{
  TCHAR folder[MAX_PATH] = {0};
  if(Is64BitOS())
    ::SHGetSpecialFolderPath(NULL,folder,CSIDL_PROGRAM_FILESX86,FALSE);
  else
    ::SHGetSpecialFolderPath(NULL,folder,CSIDL_PROGRAM_FILES,FALSE);
  std::wcout << "32bit Program Files: " << folder << std::endl;
  system("pause");
  return 0;
}

輸出:

32bit Program Files: C:\Program Files (x86)

參考

SHGetSpecialFolderPath function

如有疑問請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

  • C++中函數(shù)模板的用法詳細(xì)解析

    C++中函數(shù)模板的用法詳細(xì)解析

    所謂函數(shù)模板實(shí)際上是建立一個(gè)通用函數(shù),其涵涵素類型額形參類型不具體指定,用一個(gè)虛擬的類型來代表,這個(gè)通用函數(shù)就稱為函數(shù)模板
    2013-10-10
  • C語言?程序的編譯系統(tǒng)解析

    C語言?程序的編譯系統(tǒng)解析

    編譯程序的基本功能是把源程序(高級(jí)語言)翻譯成目標(biāo)程序。但是,作為一個(gè)具有實(shí)際應(yīng)用價(jià)值的編譯系統(tǒng),除了基本功能之外,還應(yīng)具備語法檢查、調(diào)試措施、修改手段、覆蓋處理、目標(biāo)程序優(yōu)化、不同語言合用以及人-機(jī)聯(lián)系等重要功能
    2022-02-02
  • C語言實(shí)現(xiàn)任何文件的加密解密功能

    C語言實(shí)現(xiàn)任何文件的加密解密功能

    這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)任何文件的加密解密功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-03-03
  • C++中sprintf使用的方法與printf的區(qū)別分析

    C++中sprintf使用的方法與printf的區(qū)別分析

    這篇文章主要介紹了C++中sprintf使用的方法與printf的區(qū)別,實(shí)例分析了sprintf與printf的具體用法及相關(guān)注意事項(xiàng),具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-01-01
  • C語言實(shí)現(xiàn)三子棋游戲附注釋

    C語言實(shí)現(xiàn)三子棋游戲附注釋

    這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)三子棋游戲附注釋,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • C++中的volatile關(guān)鍵字及其作用

    C++中的volatile關(guān)鍵字及其作用

    本文介紹了C++中的volatile關(guān)鍵字,它用于標(biāo)識(shí)變量可能被意外修改,以及編譯器不應(yīng)進(jìn)行優(yōu)化。本文通過具體的代碼示例,闡述了volatile關(guān)鍵字的作用和使用方法,幫助讀者更好地了解該關(guān)鍵字在C++語言中的應(yīng)用場景和實(shí)現(xiàn)原理
    2023-04-04
  • EasyC++全局變量

    EasyC++全局變量

    這篇文章主要介紹了EasyC++全局變量
    2021-12-12
  • C/C++實(shí)現(xiàn)詞法分析程序的示例代碼

    C/C++實(shí)現(xiàn)詞法分析程序的示例代碼

    這篇文章主要為大家詳細(xì)介紹了如何基于C/C++實(shí)現(xiàn)一個(gè)簡單的詞法分析程序,并通過完成詞法分析程序,了解詞法分析的過程,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)學(xué)習(xí)
    2023-05-05
  • C++如何實(shí)現(xiàn)BitMap數(shù)據(jù)結(jié)構(gòu)

    C++如何實(shí)現(xiàn)BitMap數(shù)據(jù)結(jié)構(gòu)

    這篇文章主要介紹了C++如何實(shí)現(xiàn)BitMap數(shù)據(jù)結(jié)構(gòu),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • c++支持coroutine的簡單示例

    c++支持coroutine的簡單示例

    這篇文章主要介紹了c++支持coroutine的簡單示例,使用的是linux 平臺(tái)做的,需要的朋友可以參考下
    2014-03-03

最新評(píng)論

星子县| 亳州市| 五常市| 清流县| 久治县| 合阳县| 施甸县| 沧源| 航空| 泽普县| 抚松县| 历史| 水城县| 秦安县| 宜春市| 大同县| 普兰店市| 鄂托克前旗| 乌苏市| 兴安盟| 特克斯县| 嘉黎县| 襄城县| 新乡县| 滕州市| 永寿县| 宁晋县| 台湾省| 邻水| 金湖县| 迭部县| 湟源县| 安吉县| 大城县| 连平县| 广丰县| 扶风县| 富宁县| 海原县| 新竹县| 香港|