sysutils.pp 18 KB

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