PDA

View Full Version : تشخيص ويندوز 32bit و 64bit با دلفي



h_mohamadi
جمعه 25 تیر 1389, 17:04 عصر
سلام دوستان و اساتيد محترم
من دنبال دستوري هستم که بتواند تشخيص دهد که ويندوز 32bit و 64bit است.

SAASTN
جمعه 25 تیر 1389, 19:00 عصر
خودم تست نکردم ولی یه راه خرزوخانی اینه که SizeOf(Integer) باید تو 32بیتی 4 برگزدونه و تو 64بیتی 8.

Felony
جمعه 25 تیر 1389, 19:29 عصر
خودم تست نکردم ولی یه راه خرزوخانی اینه که SizeOf(Integer) باید تو 32بیتی 4 برگزدونه و تو 64بیتی 8.

فرقی نمیکنه ، چه در ویندوز 32 بیت و چه در ویندوز 64 بیت سایز متغییر از نوع صحیح 4 بایت هست ( چون در دلفی از نوع اشاره گر هستند ).

از تابع زیر استفاده کنید :

function Test64Bit: Boolean;
type
TIsWow64Process = function(
Handle: THandle;
var Res: BOOL
): BOOL; stdcall;
var
IsWow64Result: BOOL;
IsWow64Process: TIsWow64Process;
begin
IsWow64Process := GetProcAddress(
GetModuleHandle('kernel32'), 'IsWow64Process'
);
if Assigned(IsWow64Process) then
begin
if not IsWow64Process(GetCurrentProcess, IsWow64Result) then
raise Exception.Create('Bad process handle');
Result := IsWow64Result;
end
else
Result := False;
end;



نحوه استفاده :
if Test64Bit then
ShowMessage('Current OS is 64 bit')
else
ShowMessage('Current OS is 32 bit');

SAASTN
جمعه 25 تیر 1389, 22:53 عصر
فرقی نمیکنه ، چه در ویندوز 32 بیت و چه در ویندوز 64 بیت سایز متغییر از نوع صحیح 4 بایت هست .
تا جایی که من می دونم سایز Integer و Cardinal با توجه به سیستم عامل تغییر می کنه و برابر سایز بهینه در سیستم عامله، یادمه که توی Help دلفی های قدیمی تر دقیقا ذکر شده بود که سایز این انواع قبلا 16بیت بوده و توی ویندوزهای 32بیتی 4 بایت شده، اما توی Help 2007 فقط نوشته:

The generic integer types are Integer and Cardinal; use these whenever possible, since they result in the best performance for the underlying CPU and operating system.
که لزوما به این معنی نیست که توی 64 بیتی حتما باید سایز این انواع 64 بیت بشه. از طرفی سرچ که کردم به این مطلب خوردم که بدتر گیجم کرد:

CPU specific Integer types are listed below:

NativeUInt (Unsigned, depends on CPU register size)
NativeInt (Signed, depends on CPU register size)
Note that the sizes of this Integer types actually depend on the “target architecture” you’re going to compile you program for. So if you are targeting Windows for 64 bit you will get 8 Byte wide native Integers. If you target the 32 bit Windows and you’re running your application on 64 bit Windows, NativeInt will still be 4 bytes wide.

And at last, the “generic” data types:

Cardinal (Unsigned, depends on OS definition of Integer)
Integer (Signed, depends on OS definition of Integer)
Yes, it might be confusing, but Integer and Cardinal are not CPU specific, but rather OS specific. In the case of Windows for 64 bit, the “int” is still 4 Bytes wide.
منبع:http://alex.ciobanu.org/?p=52
کسی می تونه راهنمایی کنه؟
این NativeInt تو چه نسخه ای اضافه شده؟
ضمنا ببخشید که از موضوع فاصله گرفتم، اگه صلاح می دونید ببرم تو یه تاپیک جدا گانه.

Felony
شنبه 26 تیر 1389, 07:20 صبح
https://forums.embarcadero.com/thread.jspa?threadID=38317