Advertisement
Guest User

Dans quel environnement s'exécute un prog C++ builder 6?

a guest
Feb 21st, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. int __fastcall TF_Main::Is64BitOS()
  2. {
  3.    // Necessite #include <windows.h>
  4.    // http://msdn.microsoft.com/en-us/library/windows/desktop/ms684139%28v=vs.85%29.aspx
  5.    // http://stackoverflow.com/questions/601089/detect-whether-current-windows-version-is-32-bit-or-64-bit
  6.  
  7.    typedef BOOL (WINAPI *tIsWow64Process)(HANDLE, PBOOL);
  8.    static HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32.dll"));
  9.  
  10.    int IsWow64 = 0;
  11.    hKernel32 = LoadLibrary("kernel32.dll");
  12.  
  13.    if (hKernel32 == 0)
  14.    {
  15.       // Probleme lors du chargement de kernel32.dll
  16.       return(-1);
  17.    }
  18.  
  19.    tIsWow64Process IsWow64Process = (tIsWow64Process) GetProcAddress(hKernel32, "IsWow64Process");
  20.    if (IsWow64Process != NULL)
  21.    {
  22.       if (IsWow64Process(GetCurrentProcess(), &IsWow64))
  23.       {
  24.          FreeLibrary(hKernel32);
  25.          return(IsWow64); // On est dans un environnement Win64
  26.       }
  27.       else
  28.       {
  29.          // Probleme lors de l'appel de IsWow64Process()
  30.          FreeLibrary(hKernel32);
  31.          return(-1);
  32.       }
  33.    }
  34.    else
  35.    {
  36.       FreeLibrary(hKernel32);
  37.       return(0); // On est dans un environnement Win32
  38.    }
  39. }
  40.  
  41. //Exemple d'appel à la fonction Is64BitOS()...
  42.    Is64Bits = Is64BitOS();
  43.  
  44.    if(Is64Bits > 0)
  45.    {
  46.       ShowMessage("Le programme tourne sur Windows 64 bits.");
  47.       ProgramPath = "\\Program Files (x86)\\";
  48.    }
  49.    else
  50.    if(Is64Bits == 0)
  51.    {
  52.       ShowMessage("Le programme tourne sur Windows 32 bits.");
  53.       ProgramPath = "\\Program Files\\";
  54.    }
  55.    else
  56.    if(Is64Bits == -1)
  57.    {
  58.       ShowMessage("Le programme ne sait pas déterminer son environnement d'exécution en 32 ou 64 bits...\nVeuillez signaler ce problème aux développeurs ;-)");
  59.       ProgramPath = "\\Program Files\\";
  60.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement