⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clx_windows.pas

📁 内存管理程序
💻 PAS
字号:
unit CLX_Windows;
{$D-}


interface

{$IFDEF LINUX}



uses IdGlobal, Libc, Sysutils;



type

  BOOL = boolean;

  PDWORD = ^integer;
{$ELSE}



uses Windows, Sysutils;



const

  MAX_PATH = 260;//Windows.MAX_PATH;

  MAX_COMPUTERNAME_LENGTH = 15;//windows.MAX_COMPUTERNAME_LENGTH;

  Error_Not_Ready = 21;//Windows.ERROR_NOT_READY;



{$ENDIF}



type

  TCLXCriticalSection = TRTLCriticalSection;

  DWORD = cardinal;



function InitializeCriticalSection(var sect: TCLXCriticalSection): Integer;stdcall;

function EnterCriticalSection(var sect: TCLXCriticalSection): Integer;stdcall;

function LeaveCriticalSection(var sect: TCLXCriticalSection): Integer;stdcall;

function TryEnterCriticalSection(var sect: TCLXCriticalSection): Boolean;stdcall;

function DeleteCriticalSection(var sect: TCLXCriticalSection): Integer;stdcall;

function GetCurrentThreadID: cardinal;stdcall;

function GetTickCount: cardinal;stdcall;

procedure Beep(Freq, Duration: integer);stdcall;

procedure Sleep(ms: integer);stdcall;

function FileGetAttr(sFileName: string): integer;stdcall;

procedure FileSetAttr(sFileName: string; Attr: integer);stdcall;

function GetModuleFileName(hModule: HINST; lpFilename: PChar; nSize: DWORD): DWORD; stdcall;

function GetTempPath(nBufferLength: DWORD; lpBuffer: PChar): DWORD; stdcall;
function GetComputerName(lpBuffer: PChar; var nSize: DWORD): BOOL; stdcall;
function GetLogicalDrives: DWORD; stdcall;
function GetVolumeInformation(lpRootPathName: PChar;
  lpVolumeNameBuffer: PChar; nVolumeNameSize: DWORD; lpVolumeSerialNumber: PDWORD;
  var lpMaximumComponentLength, lpFileSystemFlags: DWORD;
  lpFileSystemNameBuffer: PChar; nFileSystemNameSize: DWORD): BOOL; stdcall;


function GetLastError: cardinal;stdcall;



implementation



function GetTickCount: cardinal;stdcall;

begin

  {$IFDEF LINUX}

  result := IdGlobal.GetTickCount;

  {$ELSE}

  result := windows.GetTickCount;

  {$ENDIF}

end;



function GetCurrentThreadID: cardinal;

begin

  {$IFDEF LINUX}

  result := Libc.GetCurrentThreadID;

  {$ELSE}

  result := windows.GetCurrentThreadID;

  {$ENDIF}

end;



function InitializeCriticalSection(var sect: TCLXCriticalSection): Integer;

begin

  {$IFDEF LINUX}

  result := Libc.InitializeCriticalSection(sect);

  {$ELSE}

  Windows.InitializeCriticalSection(sect);

  result := 0;

  {$ENDIF}



end;



function EnterCriticalSection(var sect: TCLXCriticalSection): Integer;

begin

  {$IFDEF LINUX}

  result := Libc.EnterCriticalSection(sect);

  {$ELSE}

  Windows.EnterCriticalSection(sect);

  result := 0;

  {$ENDIF}

end;



function LeaveCriticalSection(var sect: TCLXCriticalSection): Integer;

begin

  {$IFDEF LINUX}

  result := Libc.LeaveCriticalSection(sect);

  {$ELSE}

  Windows.LeaveCriticalSection(sect);



  result := 0;

  {$ENDIF}

end;



function TryEnterCriticalSection(var sect: TCLXCriticalSection): Boolean;

begin

  {$IFDEF LINUX}

  result := Libc.TryEnterCriticalSection(sect);

  {$ELSE}

  result := Windows.TryEnterCriticalSection(sect);

  {$ENDIF}

end;



function DeleteCriticalSection(var sect: TCLXCriticalSection): Integer;

begin

  {$IFDEF LINUX}

  result := Libc.DeleteCriticalSection(sect);

  {$ELSE}

  Windows.DeleteCriticalSection(sect);

  result := 0;

  {$ENDIF}

end;



procedure Beep(Freq, Duration: integer);

begin

  {$IFDEF LINUX}

  {$ELSE}

  Windows.Beep(Freq, Duration);

  {$ENDIF}



end;





procedure Sleep(ms: integer);

begin

  {$IFDEF LINUX}

  SysUtils.Sleep(ms);

  {$ELSE}

  Windows.Sleep(ms);

  {$ENDIF}



end;



function FileGetAttr(sFileName: string): integer;

begin

  {$IFDEF LINUX}

  result := 0;

  {$ELSE}

  result := Sysutils.FileGetAttr(sFileName);

  {$ENDIF}



end;



procedure FileSetAttr(sFileName: string; Attr: integer);

begin

  {$IFDEF LINUX}

  {$ELSE}

  Sysutils.FileSetAttr(sFileName, Attr);

  {$ENDIF}



end;



function GetModuleFileName(hModule: HINST; lpFilename: PChar; nSize: DWORD): DWORD; stdcall;

begin

  {$IFDEF LINUX}

  result := 0;

  {$ELSE}

  result := Windows.GetModuleFileName(hModule, lpFileName, nSize)

  {$ENDIF}



end;



function GetTempPath(nBufferLength: DWORD; lpBuffer: PChar): DWORD; stdcall;

begin

  {$IFDEF LINUX}

  result := 0;

  {$ELSE}

  result := Windows.GetTempPath(nBufferLength, lpBuffer);

  {$ENDIF}



end;



function GetComputerName(lpBuffer: PChar; var nSize: DWORD): BOOL; stdcall;

begin

  {$IFDEF LINUX}

  result := false;

  {$ELSE}

  result := Windows.GetComputerName(lpBuffer, nSize);

  {$ENDIF}

end;



function GetLogicalDrives: DWORD; stdcall;

begin
  {$IFDEF LINUX}
  result := 0;

  {$ELSE}

  result := Windows.GetLogicalDrives;

  {$ENDIF}

end;


function GetVolumeInformation(lpRootPathName: PChar;

  lpVolumeNameBuffer: PChar; nVolumeNameSize: DWORD; lpVolumeSerialNumber: PDWORD;
  var lpMaximumComponentLength, lpFileSystemFlags: DWORD;
  lpFileSystemNameBuffer: PChar; nFileSystemNameSize: DWORD): BOOL; stdcall;
begin



  {$IFDEF LINUX}

  result := false;



  {$ELSE}

  result := Windows.GetVolumeInformation(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNamebuffer, nFileSystemNameSize);

  {$ENDIF}

end;


function GetLastError: cardinal;

begin

  {$IFDEF LINUX}

  result := 0;

  {$ELSE}

  result := Windows.GetLastError;

  {$ENDIF}

end;






end.



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -