sysutils.pp 19 KB

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