sysutils.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. Sysutils unit for win32
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit sysutils;
  14. interface
  15. {$IFNDEF VIRTUALPASCAL}
  16. {$MODE objfpc}
  17. {$ENDIF}
  18. { force ansistrings }
  19. {$H+}
  20. uses
  21. {$IFDEF VIRTUALPASCAL}
  22. vpglue,
  23. strings,
  24. crt,
  25. {$ENDIF}
  26. dos,
  27. windows;
  28. { Include platform independent interface part }
  29. {$i sysutilh.inc}
  30. type
  31. TSystemTime = Windows.TSystemTime;
  32. EWin32Error = class(Exception)
  33. public
  34. ErrorCode : DWORD;
  35. end;
  36. Var
  37. Win32Platform : Longint;
  38. Win32MajorVersion,
  39. Win32MinorVersion,
  40. Win32BuildNumber : dword;
  41. Win32CSDVersion : ShortString; // CSD record is 128 bytes only?
  42. implementation
  43. { Include platform independent implementation part }
  44. {$i sysutils.inc}
  45. {****************************************************************************
  46. File Functions
  47. ****************************************************************************}
  48. Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
  49. const
  50. AccessMode: array[0..2] of Cardinal = (
  51. GENERIC_READ,
  52. GENERIC_WRITE,
  53. GENERIC_READ or GENERIC_WRITE);
  54. ShareMode: array[0..4] of Integer = (
  55. 0,
  56. 0,
  57. FILE_SHARE_READ,
  58. FILE_SHARE_WRITE,
  59. FILE_SHARE_READ or FILE_SHARE_WRITE);
  60. Var
  61. FN : string;
  62. begin
  63. FN:=FileName+#0;
  64. result := CreateFile(@FN[1], dword(AccessMode[Mode and 3]),
  65. dword(ShareMode[(Mode and $F0) shr 4]), nil, OPEN_EXISTING,
  66. FILE_ATTRIBUTE_NORMAL, 0);
  67. end;
  68. Function FileCreate (Const FileName : String) : Longint;
  69. Var
  70. FN : string;
  71. begin
  72. FN:=FileName+#0;
  73. Result := CreateFile(@FN[1], GENERIC_READ or GENERIC_WRITE,
  74. 0, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  75. end;
  76. Function FileCreate (Const FileName : String; Mode:longint) : Longint;
  77. begin
  78. FileCreate:=FileCreate(FileName);
  79. end;
  80. Function FileRead (Handle : Longint; Var Buffer; Count : longint) : Longint;
  81. Var
  82. res : dword;
  83. begin
  84. if ReadFile(Handle, Buffer, Count, res, nil) then
  85. FileRead:=Res
  86. else
  87. FileRead:=-1;
  88. end;
  89. Function FileWrite (Handle : Longint; const Buffer; Count : Longint) : Longint;
  90. Var
  91. Res : dword;
  92. begin
  93. if WriteFile(Handle, Buffer, Count, Res, nil) then
  94. FileWrite:=Res
  95. else
  96. FileWrite:=-1;
  97. end;
  98. Function FileSeek (Handle,FOffset,Origin : Longint) : Longint;
  99. begin
  100. Result := longint(SetFilePointer(Handle, FOffset, nil, Origin));
  101. end;
  102. Function FileSeek (Handle : Longint; FOffset,Origin : Int64) : Int64;
  103. begin
  104. {$warning need to add 64bit call }
  105. Result := longint(SetFilePointer(Handle, FOffset, nil, Origin));
  106. end;
  107. Procedure FileClose (Handle : Longint);
  108. begin
  109. if Handle<=4 then
  110. exit;
  111. CloseHandle(Handle);
  112. end;
  113. Function FileTruncate (Handle,Size: Longint) : boolean;
  114. begin
  115. Result:=longint(SetFilePointer(handle,Size,nil,FILE_BEGIN))<>-1;
  116. If Result then
  117. Result:=SetEndOfFile(handle);
  118. end;
  119. Function DosToWinTime (DTime:longint;Var Wtime : TFileTime):longbool;
  120. var
  121. lft : TFileTime;
  122. begin
  123. {$IFDEF VIRTUALPASCAL}
  124. DosToWinTime:=DosDateTimeToFileTime(longrec(dtime).hi,longrec(dtime).lo,lft) and
  125. LocalFileTimeToFileTime(lft,Wtime);
  126. {$ELSE}
  127. DosToWinTime:=DosDateTimeToFileTime(longrec(dtime).hi,longrec(dtime).lo,@lft) and
  128. LocalFileTimeToFileTime(lft,Wtime);
  129. {$ENDIF}
  130. end;
  131. Function WinToDosTime (Var Wtime : TFileTime;var DTime:longint):longbool;
  132. var
  133. lft : TFileTime;
  134. begin
  135. WinToDosTime:=FileTimeToLocalFileTime(WTime,lft) and
  136. FileTimeToDosDateTime(lft,Longrec(Dtime).Hi,LongRec(DTIME).lo);
  137. end;
  138. Function FileAge (Const FileName : String): Longint;
  139. var
  140. Handle: THandle;
  141. FindData: TWin32FindData;
  142. begin
  143. Handle := FindFirstFile(Pchar(FileName), FindData);
  144. if Handle <> INVALID_HANDLE_VALUE then
  145. begin
  146. Windows.FindClose(Handle);
  147. if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
  148. If WinToDosTime(FindData.ftLastWriteTime,Result) then
  149. exit;
  150. end;
  151. Result := -1;
  152. end;
  153. Function FileExists (Const FileName : String) : Boolean;
  154. var
  155. Handle: THandle;
  156. FindData: TWin32FindData;
  157. begin
  158. Handle := FindFirstFile(Pchar(FileName), FindData);
  159. Result:=Handle <> INVALID_HANDLE_VALUE;
  160. If Result then
  161. Windows.FindClose(Handle);
  162. end;
  163. Function DirectoryExists (Const Directory : String) : Boolean;
  164. var
  165. Handle: THandle;
  166. FindData: TWin32FindData;
  167. begin
  168. Handle := FindFirstFile(Pchar(Directory), FindData);
  169. Result:=(Handle <> INVALID_HANDLE_VALUE) and
  170. ((FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY);
  171. If Result then
  172. Windows.FindClose(Handle);
  173. end;
  174. Function FindMatch(var f: TSearchRec) : Longint;
  175. begin
  176. { Find file with correct attribute }
  177. While (F.FindData.dwFileAttributes and cardinal(F.ExcludeAttr))<>0 do
  178. begin
  179. if not FindNextFile (F.FindHandle,F.FindData) then
  180. begin
  181. Result:=GetLastError;
  182. exit;
  183. end;
  184. end;
  185. { Convert some attributes back }
  186. WinToDosTime(F.FindData.ftLastWriteTime,F.Time);
  187. f.size:=F.FindData.NFileSizeLow;
  188. f.attr:=F.FindData.dwFileAttributes;
  189. f.Name:=StrPas(@F.FindData.cFileName);
  190. Result:=0;
  191. end;
  192. Function FindFirst (Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
  193. begin
  194. Rslt.Name:=Path;
  195. Rslt.Attr:=attr;
  196. Rslt.ExcludeAttr:=(not Attr) and ($1e);
  197. { $1e = faHidden or faSysFile or faVolumeID or faDirectory }
  198. { FindFirstFile is a Win32 Call }
  199. Rslt.FindHandle:=FindFirstFile (PChar(Path),Rslt.FindData);
  200. If Rslt.FindHandle=Invalid_Handle_value then
  201. begin
  202. Result:=GetLastError;
  203. exit;
  204. end;
  205. { Find file with correct attribute }
  206. Result:=FindMatch(Rslt);
  207. end;
  208. Function FindNext (Var Rslt : TSearchRec) : Longint;
  209. begin
  210. if FindNextFile(Rslt.FindHandle, Rslt.FindData) then
  211. Result := FindMatch(Rslt)
  212. else
  213. Result := GetLastError;
  214. end;
  215. Procedure FindClose (Var F : TSearchrec);
  216. begin
  217. if F.FindHandle <> INVALID_HANDLE_VALUE then
  218. Windows.FindClose(F.FindHandle);
  219. end;
  220. Function FileGetDate (Handle : Longint) : Longint;
  221. Var
  222. FT : TFileTime;
  223. begin
  224. If GetFileTime(Handle,nil,nil,@ft) and
  225. WinToDosTime(FT,Result) then
  226. exit;
  227. Result:=-1;
  228. end;
  229. Function FileSetDate (Handle,Age : Longint) : Longint;
  230. Var
  231. FT: TFileTime;
  232. begin
  233. {$IFDEF VIRTUALPASCAL}
  234. Result := 0;
  235. {$ELSE}
  236. Result := 0;
  237. if DosToWinTime(Age,FT) and
  238. SetFileTime(Handle, ft, ft, FT) then
  239. Exit;
  240. Result := GetLastError;
  241. {$ENDIF}
  242. end;
  243. Function FileGetAttr (Const FileName : String) : Longint;
  244. begin
  245. Result:=GetFileAttributes(PChar(FileName));
  246. end;
  247. Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
  248. begin
  249. if not SetFileAttributes(PChar(FileName), Attr) then
  250. Result := GetLastError
  251. else
  252. Result:=0;
  253. end;
  254. Function DeleteFile (Const FileName : String) : Boolean;
  255. begin
  256. DeleteFile:=Windows.DeleteFile(Pchar(FileName));
  257. end;
  258. Function RenameFile (Const OldName, NewName : String) : Boolean;
  259. begin
  260. Result := MoveFile(PChar(OldName), PChar(NewName));
  261. end;
  262. {****************************************************************************
  263. Disk Functions
  264. ****************************************************************************}
  265. function GetDiskFreeSpace(drive:pchar;var sector_cluster,bytes_sector,
  266. freeclusters,totalclusters:longint):longbool;
  267. stdcall;external 'kernel32' name 'GetDiskFreeSpaceA';
  268. type
  269. {$IFDEF VIRTUALPASCAL}
  270. {&StdCall+}
  271. TGetDiskFreeSpaceEx = function(drive:pchar;var availableforcaller,total,free):longbool;
  272. {&StdCall-}
  273. {$ELSE}
  274. TGetDiskFreeSpaceEx = function(drive:pchar;var availableforcaller,total,free):longbool;stdcall;
  275. {$ENDIF}
  276. var
  277. GetDiskFreeSpaceEx : TGetDiskFreeSpaceEx;
  278. function diskfree(drive : byte) : int64;
  279. var
  280. disk : array[1..4] of char;
  281. secs,bytes,
  282. free,total : longint;
  283. qwtotal,qwfree,qwcaller : int64;
  284. begin
  285. if drive=0 then
  286. begin
  287. disk[1]:='\';
  288. disk[2]:=#0;
  289. end
  290. else
  291. begin
  292. disk[1]:=chr(drive+64);
  293. disk[2]:=':';
  294. disk[3]:='\';
  295. disk[4]:=#0;
  296. end;
  297. if assigned(GetDiskFreeSpaceEx) then
  298. begin
  299. if GetDiskFreeSpaceEx(@disk,qwcaller,qwtotal,qwfree) then
  300. diskfree:=qwfree
  301. else
  302. diskfree:=-1;
  303. end
  304. else
  305. begin
  306. if GetDiskFreeSpace(@disk,secs,bytes,free,total) then
  307. diskfree:=int64(free)*secs*bytes
  308. else
  309. diskfree:=-1;
  310. end;
  311. end;
  312. function disksize(drive : byte) : int64;
  313. var
  314. disk : array[1..4] of char;
  315. secs,bytes,
  316. free,total : longint;
  317. qwtotal,qwfree,qwcaller : int64;
  318. begin
  319. if drive=0 then
  320. begin
  321. disk[1]:='\';
  322. disk[2]:=#0;
  323. end
  324. else
  325. begin
  326. disk[1]:=chr(drive+64);
  327. disk[2]:=':';
  328. disk[3]:='\';
  329. disk[4]:=#0;
  330. end;
  331. if assigned(GetDiskFreeSpaceEx) then
  332. begin
  333. if GetDiskFreeSpaceEx(@disk,qwcaller,qwtotal,qwfree) then
  334. disksize:=qwtotal
  335. else
  336. disksize:=-1;
  337. end
  338. else
  339. begin
  340. if GetDiskFreeSpace(@disk,secs,bytes,free,total) then
  341. disksize:=int64(total)*secs*bytes
  342. else
  343. disksize:=-1;
  344. end;
  345. end;
  346. Function GetCurrentDir : String;
  347. begin
  348. GetDir(0, result);
  349. end;
  350. Function SetCurrentDir (Const NewDir : String) : Boolean;
  351. begin
  352. {$I-}
  353. ChDir(NewDir);
  354. {$I+}
  355. result := (IOResult = 0);
  356. end;
  357. Function CreateDir (Const NewDir : String) : Boolean;
  358. begin
  359. {$I-}
  360. MkDir(NewDir);
  361. {$I+}
  362. result := (IOResult = 0);
  363. end;
  364. Function RemoveDir (Const Dir : String) : Boolean;
  365. begin
  366. {$I-}
  367. RmDir(Dir);
  368. {$I+}
  369. result := (IOResult = 0);
  370. end;
  371. {****************************************************************************
  372. Time Functions
  373. ****************************************************************************}
  374. Procedure GetLocalTime(var SystemTime: TSystemTime);
  375. Var
  376. Syst : Windows.TSystemtime;
  377. begin
  378. windows.Getlocaltime(@syst);
  379. SystemTime.year:=syst.wYear;
  380. SystemTime.month:=syst.wMonth;
  381. SystemTime.day:=syst.wDay;
  382. SystemTime.hour:=syst.wHour;
  383. SystemTime.minute:=syst.wMinute;
  384. SystemTime.second:=syst.wSecond;
  385. SystemTime.millisecond:=syst.wMilliSeconds;
  386. end;
  387. {****************************************************************************
  388. Misc Functions
  389. ****************************************************************************}
  390. procedure Beep;
  391. begin
  392. MessageBeep(0);
  393. end;
  394. {****************************************************************************
  395. Locale Functions
  396. ****************************************************************************}
  397. Procedure InitAnsi;
  398. Var
  399. i : longint;
  400. begin
  401. { Fill table entries 0 to 127 }
  402. for i := 0 to 96 do
  403. UpperCaseTable[i] := chr(i);
  404. for i := 97 to 122 do
  405. UpperCaseTable[i] := chr(i - 32);
  406. for i := 123 to 191 do
  407. UpperCaseTable[i] := chr(i);
  408. Move (CPISO88591UCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  409. for i := 0 to 64 do
  410. LowerCaseTable[i] := chr(i);
  411. for i := 65 to 90 do
  412. LowerCaseTable[i] := chr(i + 32);
  413. for i := 91 to 191 do
  414. LowerCaseTable[i] := chr(i);
  415. Move (CPISO88591LCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  416. end;
  417. function GetLocaleStr(LID, LT: Longint; const Def: string): ShortString;
  418. var
  419. L: Integer;
  420. Buf: array[0..255] of Char;
  421. begin
  422. L := GetLocaleInfo(LID, LT, Buf, SizeOf(Buf));
  423. if L > 0 then
  424. SetString(Result, @Buf[0], L - 1)
  425. else
  426. Result := Def;
  427. end;
  428. function GetLocaleChar(LID, LT: Longint; Def: Char): Char;
  429. var
  430. Buf: array[0..1] of Char;
  431. begin
  432. if GetLocaleInfo(LID, LT, Buf, 2) > 0 then
  433. Result := Buf[0]
  434. else
  435. Result := Def;
  436. end;
  437. Function GetLocaleInt(LID,TP,Def: LongInt): LongInt;
  438. Var
  439. S: String;
  440. C: Integer;
  441. Begin
  442. S:=GetLocaleStr(LID,TP,'0');
  443. Val(S,Result,C);
  444. If C<>0 Then
  445. Result:=Def;
  446. End;
  447. procedure GetFormatSettings;
  448. var
  449. HF : Shortstring;
  450. LID : LCID;
  451. I,Day,DateOrder : longint;
  452. begin
  453. LID := GetThreadLocale;
  454. { Date stuff }
  455. for I := 1 to 12 do
  456. begin
  457. ShortMonthNames[I]:=GetLocaleStr(LID,LOCALE_SABBREVMONTHNAME1+I-1,ShortMonthNames[i]);
  458. LongMonthNames[I]:=GetLocaleStr(LID,LOCALE_SMONTHNAME1+I-1,LongMonthNames[i]);
  459. end;
  460. for I := 1 to 7 do
  461. begin
  462. Day := (I + 5) mod 7;
  463. ShortDayNames[I]:=GetLocaleStr(LID,LOCALE_SABBREVDAYNAME1+Day,ShortDayNames[i]);
  464. LongDayNames[I]:=GetLocaleStr(LID,LOCALE_SDAYNAME1+Day,LongDayNames[i]);
  465. end;
  466. DateSeparator := GetLocaleChar(LID, LOCALE_SDATE, '/');
  467. DateOrder := GetLocaleInt(LID, LOCALE_IDate, 0);
  468. Case DateOrder Of
  469. 1: Begin
  470. ShortDateFormat := 'dd/mm/yyyy';
  471. LongDateFormat := 'dddd, d. mmmm yyyy';
  472. End;
  473. 2: Begin
  474. ShortDateFormat := 'yyyy/mm/dd';
  475. LongDateFormat := 'dddd, yyyy mmmm d.';
  476. End;
  477. else
  478. // Default american settings...
  479. ShortDateFormat := 'mm/dd/yyyy';
  480. LongDateFormat := 'dddd, mmmm d. yyyy';
  481. End;
  482. { Time stuff }
  483. TimeSeparator := GetLocaleChar(LID, LOCALE_STIME, ':');
  484. TimeAMString := GetLocaleStr(LID, LOCALE_S1159, 'AM');
  485. TimePMString := GetLocaleStr(LID, LOCALE_S2359, 'PM');
  486. if StrToIntDef(GetLocaleStr(LID, LOCALE_ITLZERO, '0'), 0) = 0 then
  487. HF:='h'
  488. else
  489. HF:='hh';
  490. // No support for 12 hour stuff at the moment...
  491. ShortTimeFormat := HF+':nn';
  492. LongTimeFormat := HF + ':nn:ss';
  493. { Currency stuff }
  494. CurrencyString:=GetLocaleStr(LID, LOCALE_SCURRENCY, '');
  495. CurrencyFormat:=StrToIntDef(GetLocaleStr(LID, LOCALE_ICURRENCY, '0'), 0);
  496. NegCurrFormat:=StrToIntDef(GetLocaleStr(LID, LOCALE_INEGCURR, '0'), 0);
  497. { Number stuff }
  498. ThousandSeparator:=GetLocaleChar(LID, LOCALE_STHOUSAND, ',');
  499. DecimalSeparator:=GetLocaleChar(LID, LOCALE_SDECIMAL, '.');
  500. CurrencyDecimals:=StrToIntDef(GetLocaleStr(LID, LOCALE_ICURRDIGITS, '0'), 0);
  501. end;
  502. Procedure InitInternational;
  503. begin
  504. InitAnsi;
  505. GetFormatSettings;
  506. end;
  507. {****************************************************************************
  508. Target Dependent
  509. ****************************************************************************}
  510. function FormatMessageA(dwFlags : DWORD;
  511. lpSource : Pointer;
  512. dwMessageId : DWORD;
  513. dwLanguageId: DWORD;
  514. lpBuffer : PCHAR;
  515. nSize : DWORD;
  516. Arguments : Pointer): DWORD; stdcall;external 'kernel32' name 'FormatMessageA';
  517. function SysErrorMessage(ErrorCode: Integer): String;
  518. const
  519. MaxMsgSize = Format_Message_Max_Width_Mask;
  520. var
  521. MsgBuffer: pChar;
  522. begin
  523. GetMem(MsgBuffer, MaxMsgSize);
  524. FillChar(MsgBuffer^, MaxMsgSize, #0);
  525. FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
  526. nil,
  527. ErrorCode,
  528. MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
  529. MsgBuffer, { This function allocs the memory }
  530. MaxMsgSize, { Maximum message size }
  531. nil);
  532. SysErrorMessage := StrPas(MsgBuffer);
  533. FreeMem(MsgBuffer, MaxMsgSize);
  534. end;
  535. {****************************************************************************
  536. Initialization code
  537. ****************************************************************************}
  538. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  539. var
  540. s : string;
  541. i : longint;
  542. hp,p : pchar;
  543. begin
  544. Result:='';
  545. p:=GetEnvironmentStrings;
  546. hp:=p;
  547. while hp^<>#0 do
  548. begin
  549. s:=strpas(hp);
  550. i:=pos('=',s);
  551. if uppercase(copy(s,1,i-1))=upcase(envvar) then
  552. begin
  553. Result:=copy(s,i+1,length(s)-i);
  554. break;
  555. end;
  556. { next string entry}
  557. hp:=hp+strlen(hp)+1;
  558. end;
  559. FreeEnvironmentStrings(p);
  560. end;
  561. {****************************************************************************
  562. Initialization code
  563. ****************************************************************************}
  564. var
  565. kernel32dll : THandle;
  566. Procedure LoadVersionInfo;
  567. // and getfreespaceex
  568. Var
  569. versioninfo : TOSVERSIONINFO;
  570. i : Integer;
  571. begin
  572. kernel32dll:=0;
  573. GetDiskFreeSpaceEx:=nil;
  574. versioninfo.dwOSVersionInfoSize:=sizeof(versioninfo);
  575. GetVersionEx(versioninfo);
  576. Win32Platform:=versionInfo.dwPlatformId;
  577. Win32MajorVersion:=versionInfo.dwMajorVersion;
  578. Win32MinorVersion:=versionInfo.dwMinorVersion;
  579. Win32BuildNumber:=versionInfo.dwBuildNumber;
  580. Move (versioninfo.szCSDVersion ,Win32CSDVersion[1],128);
  581. win32CSDVersion[0]:=chr(strlen(pchar(@versioninfo.szCSDVersion)));
  582. if ((versioninfo.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS) and
  583. (versioninfo.dwBuildNUmber>=1000)) or
  584. (versioninfo.dwPlatformId=VER_PLATFORM_WIN32_NT) then
  585. begin
  586. kernel32dll:=LoadLibrary('kernel32');
  587. if kernel32dll<>0 then
  588. {$IFDEF VIRTUALPASCAL}
  589. @GetDiskFreeSpaceEx:=GetProcAddress(0,'GetDiskFreeSpaceExA');
  590. {$ELSE}
  591. GetDiskFreeSpaceEx:=TGetDiskFreeSpaceEx(GetProcAddress(kernel32dll,'GetDiskFreeSpaceExA'));
  592. {$ENDIF}
  593. end;
  594. end;
  595. function FreeLibrary(hLibModule : THANDLE) : longbool;
  596. stdcall;external 'kernel32' name 'FreeLibrary';
  597. function GetVersionEx(var VersionInformation:TOSVERSIONINFO) : longbool;
  598. stdcall;external 'kernel32' name 'GetVersionExA';
  599. function LoadLibrary(lpLibFileName : pchar):THandle;
  600. stdcall;external 'kernel32' name 'LoadLibraryA';
  601. function GetProcAddress(hModule : THandle;lpProcName : pchar) : pointer;
  602. stdcall;external 'kernel32' name 'GetProcAddress';
  603. Initialization
  604. InitExceptions; { Initialize exceptions. OS independent }
  605. InitInternational; { Initialize internationalization settings }
  606. LoadVersionInfo;
  607. Finalization
  608. DoneExceptions;
  609. if kernel32dll<>0 then
  610. FreeLibrary(kernel32dll);
  611. end.
  612. {
  613. $Log$
  614. Revision 1.26 2003-11-06 22:25:10 marco
  615. * added some more of win32* delphi pseudo constants
  616. Revision 1.25 2003/10/25 23:44:33 hajny
  617. * THandle in sysutils common using System.THandle
  618. Revision 1.24 2003/09/17 15:06:36 peter
  619. * stdcall patch
  620. Revision 1.23 2003/09/06 22:23:35 marco
  621. * VP fixes.
  622. Revision 1.22 2003/04/01 15:57:41 peter
  623. * made THandle platform dependent and unique type
  624. Revision 1.21 2003/03/29 18:21:42 hajny
  625. * DirectoryExists declaration changed to that one from fixes branch
  626. Revision 1.20 2003/03/28 19:06:59 peter
  627. * directoryexists added
  628. Revision 1.19 2003/01/03 20:41:04 peter
  629. * FileCreate(string,mode) overload added
  630. Revision 1.18 2003/01/01 20:56:57 florian
  631. + added invalid instruction exception
  632. Revision 1.17 2002/12/15 20:24:17 peter
  633. * some more C style functions
  634. Revision 1.16 2002/10/02 21:17:03 florian
  635. * we've to reimport TSystemTime time from the windows unit
  636. Revision 1.15 2002/09/07 16:01:29 peter
  637. * old logs removed and tabs fixed
  638. Revision 1.14 2002/05/09 08:28:23 carl
  639. * Merges from Fixes branch
  640. Revision 1.13 2002/03/24 19:26:49 marco
  641. * Added win32platform
  642. Revision 1.12 2002/01/25 16:23:04 peter
  643. * merged filesearch() fix
  644. }