sysutils.pp 19 KB

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