2011-05-04 1 views

답변

16

OpenProcess 함수를 사용하여 PID 핸들을 가져온 다음 IsWow64Process 함수를 호출 할 수 있습니다.

일부 Windows 버전에는이 기능이 없으므로 GetProcAddress 기능을 사용하여 IsWow64Process 기능을로드해야합니다.

확인 64 비트 델파이에서 컴파일이 코드는,이 잘못된 결과를 가지고 있으면이 샘플 코드

{$APPTYPE CONSOLE} 

uses 
    Windows, 
    SysUtils; 

type 
    TIsWow64Process = function(Handle:THandle; var IsWow64 : BOOL) : BOOL; stdcall; 
var 
    IsWow64Process : TIsWow64Process; 

procedure Init_IsWow64Process; 
var 
    hKernel32  : Integer; 
begin 
    hKernel32 := LoadLibrary(kernel32); 
    if (hKernel32 = 0) then RaiseLastOSError; 
    try 
    IsWow64Process := GetProcAddress(hkernel32, 'IsWow64Process'); 
    finally 
    FreeLibrary(hKernel32); 
    end; 
end; 

function PidIs64BitsProcess(dwProcessId: DWORD): Boolean; 
var 
    IsWow64  : BOOL; 
    PidHandle  : THandle; 
begin 
    Result := False; 
    if Assigned(IsWow64Process) then 
    begin 
    //check if the current app is running under WOW 
    if IsWow64Process(GetCurrentProcess(), IsWow64) then 
     Result := IsWow64 
    else 
     RaiseLastOSError; 

    //the current delphi App is not running under wow64, so the current Window OS is 32 bit 
    //and obviously all the apps are 32 bits. 
    if not Result then Exit; 

    PidHandle := OpenProcess(PROCESS_QUERY_INFORMATION,False,dwProcessId); 
    if PidHandle > 0 then 
    try 
     if (IsWow64Process(PidHandle, IsWow64)) then 
     Result := not IsWow64 
     else 
     RaiseLastOSError; 
    finally 
     CloseHandle(PidHandle); 
    end; 
    end; 
end; 


begin 
    try 
    Init_IsWow64Process; 
    //here pass the pid which you want to check 
    Writeln(BoolToStr(PidIs64BitsProcess(1940),True)); 
    except 
    on E:Exception do 
     Writeln(E.Classname, ': ', E.Message); 
    end; 
    Readln; 
end. 
+0

하지만. "IsWow64에서 IsWow64 : 프로세스가 64 비트 Windows에서 실행되는 64 비트 응용 프로그램 인 경우 값도 FALSE로 설정됩니다." 그리고 우리는 항상 64 비트 프로세스에서 False를 얻습니다. –

관련 문제