Windows functions v3.07

DeepSeek V4稀疏注意力与百万上下文实战指南 大语言模型的长上下文处理能力,核心在于注意力机制的计算效率与内存管理。稀疏注意力(Sparse Attention)通过动态筛选关键token区域,突破传统Transformer O(n²)复杂度瓶颈,使百万级上下文在有限显存下成为可能。DeepSeek V4采用DSA(DeepSeek Sparse Attention)架构,在代码理解、多跳推理等任务中实现高信息密度压缩与低延迟响应,兼顾推理质量与部署成本。其技术价值不仅体现于1M上下文标称值,更在于对chunk语义分组、跨块路由和KV缓存淘汰的工程级优 阅读详情
$INCLUDE ../cDefines.inc}
unit cWindows;

{                                                                              }
{                          Windows functions v3.07                             }
{                                                                              }
{             This unit is copyright ?2000-2004 by David J Butler             }
{                                                                              }
{                  This unit is part of Delphi Fundamentals.                   }
{                    Its original file name is cWindows.pas                    }
{       The latest version is available from the Fundamentals home page        }
{                     http://fundementals.sourceforge.net/                     }
{                                                                              }
{                I invite you to use this unit, free of charge.                }
{        I invite you to distibute this unit, but it must be for free.         }
{             I also invite you to contribute to its development,              }
{             but do not distribute a modified copy of this file.              }
{                                                                              }
{          A forum is available on SourceForge for general discussion          }
{             http://sourceforge.net/forum/forum.php?forum_id=2117             }
{                                                                              }
{ Description:                                                                 }
{   MS Windows specific functions.                                             }
{                                                                              }
{ Revision history:                                                            }
{   2000/10/01  1.01  Initial version created from cUtils.                     }
{   2001/12/12  2.02  Added AWindowHandle.                                     }
{   2002/03/15  2.03  Added GetWinOSType.                                      }
{   2002/06/26  3.04  Refactored for Fundamentals 3.                           }
{   2002/09/22  3.05  Moved Registry functions to unit cRegistry.              }
{   2003/01/04  3.06  Added Reboot function.                                   }
{   2003/10/01  3.07  Updated GetWindowsVersion function.                      }
{                                                                              }

interface

uses
  { Delphi }
  Windows,
  Messages,
  SysUtils,
  Classes,

  { Fundamentals }
  cUtils;



{                                                                              }
{ Windows Version                                                              }
{                                                                              }
type
  TWindowsVersion = (
      // 16-bit Windows
      Win16_31,
      // 32-bit Windows Win32_95, Win32_95R2, Win32_98, Win32_98SE, Win32_ME, Win32_Future, // Windows NT 3
      WinNT_31, WinNT_35, WinNT_351,
      // Windows NT 4
      WinNT_40,
      // Windows NT 5
      WinNT5_2000, WinNT5_XP, WinNT5_2003, WinNT5_Future,
      // Windows NT 6+
      WinNT_Future,
      // Windows Post-NT
      Win_Future);
  TWindowsVersions = Set of TWindowsVersion;

function  GetWindowsVersion: TWindowsVersion;
function  IsWinPlatform95: Boolean;
function  IsWinPlatformNT: Boolean;
function  GetWindowsProductID: String;



{                                                                              }
{ Windows Paths                                                                }
{                                                                              }
function  GetWindowsTemporaryPath: String;
function  GetWindowsPath: String;
function  GetWindowsSystemPath: String;
function  GetProgramFilesPath: String;
function  GetCommonFilesPath: String;
function  GetApplicationPath: String;



{                                                                              }
{ Identification                                                               }
{                                                                              }
function  GetUserName: String;
function  GetLocalComputerName: String;
function  GetLocalHostName: String;



{                                                                              }
{ Application Version Info                                                     }
{                                                                              }
type
  TVersionInfo = (viFileVersion, viFileDescription, viLegalCopyright,
                  viComments, viCompanyName, viInternalName,
                  viLegalTrademarks, viOriginalFilename, viProductName,
                  viProductVersion);

function  GetAppVersionInfo(const VersionInfo: TVersionInfo): String;



{                                                                              }
{ Windows Processes                                                            }
{                                                                              }
function  WinExecute(const ExeName, Params: String;
          const ShowWin: Word = SW_SHOWNORMAL;
          const Wait: Boolean = True): Boolean;



{                                                                              }
{ Exit Windows                                                                 }
{                                                                              }
{$IFNDEF FREEPASCAL}
type
  TExitWindowsType = (exitLogOff, exitPowerOff, exitReboot, exitShutDown);

function  ExitWindows(const ExitType: TExitWindowsType;
          const Force: Boolean = False): Boolean;

function  LogOff(const Force: Boolean = False): Boolean;
function  PowerOff(const Force: Boolean = False): Boolean;
function  Reboot(const Force: Boolean = False): Boolean;
function  ShutDown(const Force: Boolean = False): Boolean;
{$ENDIF}



{                                                                              }
{ Windows Fibers                                                               }
{   These functions are redeclared because Delphi 7's Windows.pas declare      }
{   them incorrectly.                                                          }
{                                                                              }
{$IFDEF FREEPASCAL}
type
  TFNFiberStartRoutine = TFarProc;
{$ENDIF}

function  ConvertThreadToFiber(lpParameter: Pointer): Pointer; stdcall;
function  CreateFiber(dwStackSize: DWORD; lpStartAddress: TFNFiberStartRoutine;
          lpParameter: Pointer): Pointer; stdcall;



{                                                                              }
{ Miscelleaneous Windows API                                                   }
{                                                                              }
function  GetEnvironmentStrings: StringArray;

function  ContentTypeFromExtention(const Extention: String): String;
function  FileClassFromExtention(const Extention: String): String;
function  GetFileClass(const FileName: String): String;
function  GetFileAssociation(const FileName: String): String;

function  IsApplicationAutoRun(const Name: String): Boolean;
procedure SetApplicationAutoRun(const Name: String; const AutoRun: Boolean);

{$IFNDEF FREEPASCAL}
function  GetWinPortNames: StringArray;
{$ENDIF}

function  GetKeyPressed(const VKeyCode: Integer): Boolean;

function  GetHardDiskSerialNumber(const DriveLetter: Char): String;



{                                                                              }
{ WinInet API                                                                  }
{                                                                              }
type
  TIEProxy = (iepHTTP, iepHTTPS, iepFTP, iepGOPHER, iepSOCKS);

{$IFNDEF FREEPASCAL}
function  GetIEProxy(const Protocol: TIEProxy): String;
{$ENDIF}



{                                                                              }
{ Window Handle                                                                }
{   Base class for allocation of a new Window handle that can process its own  }
{   messages.                                                                  }
{                                                                              }
type
  TWindowHandleMessageEvent = function (const Msg: Cardinal; const wParam, lParam: Integer;
      var Handled: Boolean): Integer of object;
  TWindowHandle = class;
  TWindowHandleEvent = procedure (const Sender: TWindowHandle) of object;
  TWindowHandleErrorEvent = procedure (const Sender: TWindowHandle;
      const E: Exception) of object;
  TWindowHandle = class(TComponent)
  protected
    FWindowHandle    : HWND;
    FTerminated      : Boolean;
    FOnMessage       : TWindowHandleMessageEvent;
    FOnException     : TWindowHandleErrorEvent;
    FOnBeforeMessage : TWindowHandleEvent;
    FOnAfterMessage  : TWindowHandleEvent;

    procedure RaiseError(const Msg: String);
    function  AllocateWindowHandle: HWND; virtual;
    function  MessageProc(const Msg: Cardinal; const wParam, lParam: Integer): Integer;
    function  HandleWM(const Msg: Cardinal; const wParam, lParam: Integer): Integer; virtual;

  public
    destructor Destroy; override;

    procedure DestroyWindowHandle; virtual;
    property  WindowHandle: HWND read FWindowHandle;
    function  GetWindowHandle: HWND;

    function  ProcessMessage: Boolean;
    procedure ProcessMessages;
    function  HandleMessage: Boolean;
    procedure MessageLoop;

    property  OnMessage: TWindowHandleMessageEvent read FOnMessage write FOnMessage;
    property  OnException: TWindowHandleErrorEvent read FOnException write FOnException;
    property  OnBeforeMessage: TWindowHandleEvent read FOnBeforeMessage write FOnBeforeMessage;
    property  OnAfterMessage: TWindowHandleEvent read FOnAfterMessage write FOnAfterMessage;

    property  Terminated: Boolean read FTerminated;
    procedure Terminate; virtual;
  end;
  EWindowHandle = class(Exception);

  { TfndWindowHandle                                                           }
  {   Published Window Handle component.                                       }
  TfndWindowHandle = class(TWindowHandle)
  published
    property  OnMessage;
    property  OnException;
  end;



{                                                                              }
{ TTimerHandle                                                                 }
{                                                                              }
type
  TTimerHandle = class;
  TTimerEvent = procedure (const Sender: TTimerHandle) of object;
  TTimerHandle = class(TWindowHandle)
  protected
    FTimerInterval : Integer;
    FTimerActive   : Boolean;
    FOnTimer       : TTimerEvent;

    function  HandleWM(const Msg: Cardinal; const wParam, lParam: Integer): Integer; override;
    function  DoSetTimer: Boolean;
    procedure TriggerTimer; virtual;
    procedure SetTimerActive(const TimerActive: Boolean); virtual;
    procedure Loaded; override;

  public
    constructor Create(AOwner: TComponent); override;
    procedure DestroyWindowHandle; override;

    property  TimerInterval: Integer read FTimerInterval write FTimerInterval default 1000;
    property  TimerActive: Boolean read FTimerActive write SetTimerActive default False;
    property  OnTimer: TTimerEvent read FOnTimer write FOnTimer;
  end;

  { TfndTimerHandle                                                            }
  {   Published Timer Handle component.                                        }
  TfndTimerHandle = class(TTimerHandle)
  published
    property  OnMessage;
    property  OnException;
    property  TimerInterval;
    property  TimerActive;
    property  OnTimer;
  end;



{$IFNDEF DELPHI6_UP}
{                                                                              }
{ RaiseLastOSError                                                             }
{                                                                              }
procedure RaiseLastOSError;
{$ENDIF}



implementation

uses
  { Delphi }
  WinSock,
  {$IFNDEF FREEPASCAL}
  WinSpool,
  WinInet,
  {$ENDIF}

  { Fundamentals }
  cStrings,
  cRegistry;



{$IFNDEF DELPHI6_UP}
{                                                                              }
{ RaiseLastOSError                                                             }
{                                                                              }
procedure RaiseLastOSError;
begin
  {$IFDEF FREEPASCAL}
  raise Exception.Create('OS Error');
  {$ELSE}
  RaiseLastWin32Error;
  {$ENDIF}
end;
{$ENDIF}



{                                                                              }
{ Windows Version Info                                                         }
{                                                                              }
{$IFDEF FREEPASCAL}
var
  Win32Platform     : Integer;
  Win32MajorVersion : Integer;
  Win32MinorVersion : Integer;
  Win32CSDVersion   : String;

procedure InitPlatformId;
var OSVersionInfo : TOSVersionInfo;
begin
  OSVersionInfo.dwOSVersionInfoSize := SizeOf(OSVersionInfo);
  if GetVersionEx(OSVersionInfo) then
    with OSVersionInfo do
      begin
        Win32Platform := dwPlatformId;
        Win32MajorVersion := dwMajorVersion;
        Win32MinorVersion := dwMinorVersion;
        Win32CSDVersion := szCSDVersion;
      end;
end;
{$ENDIF}

function GetWindowsVersion: TWindowsVersion;
begin
  Case Win32Platform of
    VER_PLATFORM_WIN32s :
      Result := Win16_31;
    VER_PLATFORM_WIN32_WINDOWS :
      if Win32MajorVersion <= 4 then
        Case Win32MinorVersion of
          0..9   : if Trim(Win32CSDVersion, csWhiteSpace) = 'B' then
                     Result := Win32_95R2 else
                     Result := Win32_95;
          10..89 : if Trim(Win32CSDVersion, csWhiteSpace) = 'A' then
                     Result := Win32_98SE else
                     Result := Win32_98;
          90..99 : Result := Win32_ME;
        else
          Result := Win32_Future;
        end
      else
        Result := Win32_Future;
    VER_PLATFORM_WIN32_NT :
      Case Win32MajorVersion of
        3 : Case Win32MinorVersion of
              1, 10..19 : Result := WinNT_31;
              5, 50     : Result := WinNT_35;
              51..99    : Result := WinNT_351;
            else
              Result := WinNT_31;
            end;
        4 : Result := WinNT_40;
        5 : Case Win32MinorVersion of
               0 : Result := WinNT5_2000;
               1 : Result := WinNT5_XP;
               2 : Result := WinNT5_2003;
            else
              Result := WinNT5_Future;
            end;
      else
        Result := WinNT_Future;
      end;
  else
    Result := Win_Future;
  end;
end;

function IsWinPlatform95: Boolean;
begin
  Result := Win32Platform = VER_PLATFORM_WIN32_WINDOWS;
end;

function IsWinPlatformNT: Boolean;
begin
  Result := Win32Platform = VER_PLATFORM_WIN32_NT;
end;

function GetWindowsProductID: String;
begin
  Result := GetRegistryString(HKEY_LOCAL_MACHINE,
         'Software/Microsoft/Windows/CurrentVersion', 'ProductId');
end;



{                                                                              }
{ Windows Paths                                                                }
{                                                                              }
function GetWindowsTemporaryPath: String;
const MaxTempPathLen = MAX_PATH + 1;
var I : LongWord;
begin
  SetLength(Result, MaxTempPathLen);
  I := GetTempPath(MaxTempPathLen, PChar(Result));
  if I > 0 then
    SetLength(Result, I) else
    Result := '';
end;

function GetWindowsPath: String;
const MaxWinPathLen = MAX_PATH + 1;
var I : LongWord;
begin
  SetLength(Result, MaxWinPathLen);
  I := GetWindowsDirectory(PChar(Result), MaxWinPathLen);
  if I > 0 then
    SetLength(Result, I) else
    Result := '';
end;

function GetWindowsSystemPath: String;
const MaxWinSysPathLen = MAX_PATH + 1;
var I : LongWord;
begin
  SetLength(Result, MaxWinSysPathLen);
  I := GetSystemDirectory(PChar(Result), MaxWinSysPathLen);
  if I > 0 then
    SetLength(Result, I) else
    Result := '';
end;

const
  CurrentVersionRegistryKey = 'SOFTWARE/Microsoft/Windows/CurrentVersion';

function GetProgramFilesPath: String;
begin
  Result := GetRegistryString(HKEY_LOCAL_MACHINE, CurrentVersionRegistryKey,
      'ProgramFilesDir');
end;

function GetCommonFilesPath: String;
begin
  Result := GetRegistryString(HKEY_LOCAL_MACHINE, CurrentVersionRegistryKey,
      'CommonFilesDir');
end;

function GetApplicationPath: String;
begin
  Result := ExtractFilePath(ParamStr(0));
  StrEnsureSuffix(Result, '/');
end;



{                                                                              }
{ Identification                                                               }
{                                                                              }
function GetUserName: String;
const MAX_USERNAME_LENGTH = 256;
var L : LongWord;
begin
  L := MAX_USERNAME_LENGTH + 2;
  SetLength(Result, L);
  if Windows.GetUserName(PChar(Result), L) and (L > 0) then
    SetLength(Result, StrLen(PChar(Result))) else
    Result := '';
end;

function GetLocalComputerName: String;
var L : LongWord;
begin
  L := MAX_COMPUTERNAME_LENGTH + 2;
  SetLength(Result, L);
  if Windows.GetComputerName(PChar(Result), L) and (L > 0) then
    SetLength(Result, StrLen(PChar(Result))) else
    Result := '';
end;

function GetLocalHostName: String;
const MAX_HOST_LENGTH = MAX_PATH;
var WSAData : TWSAData;
    L       : LongWord;
begin
  if WSAStartup($0101, WSAData) = 0 then
    try
      L := MAX_HOST_LENGTH + 2;
      SetLengthAndZero(Result, L);
      if GetHostName(PChar(Result), L) = 0 then
        SetLength(Result, StrLen(PChar(Result))) else
        Result := '';
    finally
      WSACleanup;
    end;
end;



{                                                                              }
{ Application Version Info                                                     }
{                                                                              }
var
  VersionInfoBuf : Pointer = nil;
  VerTransStr    : String;

// Returns True if VersionInfo is available
function LoadAppVersionInfo: Boolean;
type TTransBuffer = Array [1..4] of SmallInt;
     PTransBuffer = ^TTransBuffer;
var InfoSize : Integer;
    Size, H  : LongWord;
    EXEName  : String;
    Trans    : PTransBuffer;
begin
  Result := Assigned(VersionInfoBuf);
  if Result then
    exit;
  EXEName := ParamStr(0);
  InfoSize := GetFileVersionInfoSize(PChar(EXEName), H);
  if InfoSize = 0 then
    exit;
  GetMem(VersionInfoBuf, InfoSize);
  if not GetFileVersionInfo(PChar(EXEName), H, InfoSize, VersionInfoBuf) then
    begin
      FreeMem(VersionInfoBuf);
      VersionInfoBuf := nil;
      exit;
    end;
  VerQueryValue(VersionInfoBuf, PChar('/VarFileInfo/Translation'),
                 Pointer(Trans), Size);
  VerTransStr := IntToHex(Trans^ [1], 4) + IntToHex(Trans^ [2], 4);
  Result := True;
end;

const
  VersionInfoStr: Array [TVersionInfo] of String =
    ('FileVersion', 'FileDescription', 'LegalCopyright', 'Comments',
     'CompanyName', 'InternalName', 'LegalTrademarks',
     'OriginalFilename', 'ProductName', 'ProductVersion');

function GetAppVersionInfo(const VersionInfo: TVersionInfo): String;
var S     : String;
    Size  : LongWord;
    Value : PChar;
begin
  Result := '';
  if not LoadAppVersionInfo then
    exit;
  S := 'StringFileInfo/' + VerTransStr + '/' + VersionInfoStr[VersionInfo];
  if VerQueryvalue(VersionInfoBuf, PChar(S), Pointer(Value), Size) then
    Result := Value;
end;



{                                                                              }
{ Windows Processes                                                            }
{                                                                              }
function WinExecute(const ExeName, Params: String; const ShowWin: Word;
    const Wait: Boolean): Boolean;
var StartUpInfo : TStartupInfo;
    ProcessInfo : TProcessInformation;
    Cmd         : String;
begin
  if Params = '' then
    Cmd := ExeName else
    Cmd := ExeName + ' ' + Params;
  FillChar(StartUpInfo, SizeOf(StartUpInfo), #0);
  StartUpInfo.cb := SizeOf(StartUpInfo);
  StartUpInfo.dwFlags := STARTF_USESHOWWINDOW; // STARTF_USESTDHANDLES
  StartUpInfo.wShowWindow := ShowWin;
  Result := CreateProcess(
           nil, PChar(Cmd), nil, nil, False,
           CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil,
           PChar(ExtractFilePath(ExeName)), StartUpInfo, ProcessInfo);
  if Wait then
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
end;



{                                                                              }
{ Exit Windows                                                                 }
{                                                                              }
{$IFNDEF FREEPASCAL}
function ExitWindows(const ExitType: TExitWindowsType; const Force: Boolean): Boolean;
const SE_SHUTDOWN_NAME = 'SeShutDownPrivilege';
      ExitTypeFlags : Array[TExitWindowsType] of Cardinal =
          (EWX_LOGOFF, EWX_POWEROFF, EWX_REBOOT, EWX_SHUTDOWN);
var hToken : Cardinal;
    tkp    : TTokenPrivileges;
    retval : Cardinal;
    uFlags : Cardinal;
begin
  if IsWinPlatformNT then
    if OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
      begin
        LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME, tkp.Privileges[0].Luid);
        tkp.PrivilegeCount := 1;
        tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
        AdjustTokenPrivileges(hToken, false, tkp, 0, tkp, retval);
      end;
  uFlags := ExitTypeFlags[ExitType];
  if Force then
    uFlags := uFlags or EWX_FORCE;
  Result := Windows.ExitWindowsEx(uFlags, 0);
end;

function LogOff(const Force: Boolean = False): Boolean;
begin
  Result := ExitWindows(exitLogOff, Force);
end;

function PowerOff(const Force: Boolean = False): Boolean;
begin
  Result := ExitWindows(exitPowerOff, Force);
end;

function Reboot(const Force: Boolean): Boolean;
begin
  Result := ExitWindows(exitReboot, Force);
end;

function ShutDown(const Force: Boolean = False): Boolean;
begin
  Result := ExitWindows(exitShutDown, Force);
end;
{$ENDIF}



{                                                                              }
{ Windows Fibers                                                               }
{                                                                              }
function ConvertThreadToFiber; external kernel32 name 'ConvertThreadToFiber';
function CreateFiber(dwStackSize: DWORD; lpStartAddress: TFNFiberStartRoutine;
         lpParameter: Pointer): Pointer; external kernel32 name 'CreateFiber';



{                                                                              }
{ Miscelleaneous Windows API                                                   }
{                                                                              }
function GetEnvironmentStrings: StringArray;
var P, Q : PChar;
    I : Integer;
    S : String;
begin
  P := PChar(Windows.GetEnvironmentStrings);
  try
    if P^ <> #0 then
      Repeat
        Q := P;
        I := 0;
        While Q^ <> #0 do
          begin
            Inc(Q);
            Inc(I);
          end;
        SetLength(S, I);
        if I > 0 then
          Move(P^, Pointer(S)^, I);
        Append(Result, S);
        P := Q;
        Inc(P);
      Until P^ = #0;
  finally
    FreeEnvironmentStrings(P);
  end;
end;

function ContentTypeFromExtention(const Extention: String): String;
begin
  Result := GetRegistryString(HKEY_CLASSES_ROOT, Extention, 'Content Type');
end;

function FileClassFromExtention(const Extention: String): String;
begin
  Result := GetRegistryString(HKEY_CLASSES_ROOT, Extention, '');
end;

function GetFileClass(const FileName: String): String;
begin
  Result := FileClassFromExtention(ExtractFileExt(FileName));
end;

function GetFileAssociation(const FileName: String): String;
var S : String;
begin
  S := FileClassFromExtention(ExtractFileExt(FileName));
  if S = '' then
    Result := ''
  else
    Result := GetRegistryString(HKEY_CLASSES_ROOT, S + '/Shell/Open/Command', '');
end;

const
  AutoRunRegistryKey = 'SOFTWARE/Microsoft/Windows/CurrentVersion/Run';

function IsApplicationAutoRun(const Name: String): Boolean;
var S : String;
begin
  S := ParamStr(0);
  Result := (S <> '') and (Name <> '') and
      StrEqualNoCase(GetRegistryString(HKEY_LOCAL_MACHINE, AutoRunRegistryKey, Name), S);
end;

procedure SetApplicationAutoRun(const Name: String; const AutoRun: Boolean);
begin
  if Name = '' then
    exit;
  if AutoRun then
    SetRegistryString(HKEY_LOCAL_MACHINE, AutoRunRegistryKey, Name, ParamStr(0)) else
    DeleteRegistryValue(HKEY_LOCAL_MACHINE, AutoRunRegistryKey, Name);
end;

{$IFNDEF FREEPASCAL}
function GetWinPortNames: StringArray;
var BytesNeeded, N, I : LongWord;
    Buf : Pointer;
    InfoPtr : PPortInfo1;
    TempStr : String;
begin
  Result := nil;
  if EnumPorts(nil, 1, nil, 0, BytesNeeded, N) then
    exit;
  if GetLastError <> ERROR_INSUFFICIENT_BUFFER then
    RaiseLastOSError;
  GetMem(Buf, BytesNeeded);
  try
    if not EnumPorts(nil, 1, Buf, BytesNeeded, BytesNeeded, N) then
      RaiseLastOSError;
    For I := 0 to N - 1 do
      begin
        InfoPtr := PPortInfo1(LongWord(Buf) + I * SizeOf(TPortInfo1));
        TempStr := InfoPtr^.pName;
        Append(Result, TempStr);
      end;
  finally
    FreeMem(Buf);
  end;
end;
{$ENDIF}

function GetKeyPressed(const VKeyCode: Integer): Boolean;
begin
  Result := GetKeyState(VKeyCode) and $80 <> 0;
end;



{                                                                              }
{ WinInet API                                                                  }
{                                                                              }
const
  IEProtoPrefix : Array[TIEProxy] of String =
      ('http=', 'https=', 'ftp=', 'gopher=', 'socks=');

{$IFNDEF FREEPASCAL}
function GetIEProxy(const Protocol: TIEProxy): String;
var ProxyInfo : PInternetProxyInfo;
    Len       : LongWord;
    Proxies   : StringArray;
    I         : Integer;
begin
  Proxies := nil;
  Result := '';
  Len := 4096;
  GetMem(ProxyInfo, Len);
  try
    if InternetQueryOption(nil, INTERNET_OPTION_PROXY, ProxyInfo, Len) then
      if ProxyInfo^.dwAccessType = INTERNET_OPEN_TYPE_PROXY then
        begin
          Result := ProxyInfo^.lpszProxy;
          if PosChar('=', Result) = 0 then // same proxy for all protocols
            exit;
          // Find proxy for Protocol
          Proxies := StrSplitChar(Result, ' ');
          For I := 0 to Length(Proxies) - 1 do
            if StrMatchLeft(Proxies[I], IEProtoPrefix[Protocol], False) then
              begin
                Result := StrAfterChar(Proxies[I], '=');
                exit;
              end;
          // No proxy for Protocol
          Result := '';
        end;
  finally
    FreeMem(ProxyInfo);
  end;
end;
{$ENDIF}

function GetHardDiskSerialNumber(const DriveLetter: Char): String;
var N, F, S : DWORD;
begin
  S := 0;
  GetVolumeInformation(PChar(DriveLetter + ':/'), nil, MAX_PATH + 1, @S,
      N, F, nil, 0);
  Result := LongWordToHex(S, 8);
end;



{                                                                              }
{ TWindowHandle                                                                }
{                                                                              }
function WindowHandleMessageProc(const WindowHandle: HWND; const Msg: Cardinal;
    const wParam, lParam: Integer): Integer; stdcall;
var V : TObject;
begin
  V := TObject(GetWindowLong(WindowHandle, 0)); // Get user data
  if V is TWindowHandle then
    Result := TWindowHandle(V).MessageProc(Msg, wParam, lParam) else
    Result := DefWindowProc(WindowHandle, Msg, wParam, lParam); // Default handler
end;

var
  WindowClass: TWndClass = (
      style         : 0;
      lpfnWndProc   : @WindowHandleMessageProc;
      cbClsExtra    : 0;
      cbWndExtra    : SizeOf(Pointer); // Size of extra user data
      hInstance     : 0;
      hIcon         : 0;
      hCursor       : 0;
      hbrBackground : 0;
      lpszMenuName  : nil;
      lpszClassName : 'FundamentalsWindowClass');

Destructor TWindowHandle.Destroy;
begin
  DestroyWindowHandle;
  inherited Destroy;
end;

procedure TWindowHandle.RaiseError(const Msg: String);
begin
  raise EWindowHandle.Create(Msg);
end;

function TWindowHandle.AllocateWindowHandle: HWND;
var C : TWndClass;
begin
  WindowClass.hInstance := HInstance;
  // Register class
  if not GetClassInfo(HInstance, WindowClass.lpszClassName, C) then
    if Windows.RegisterClass(WindowClass) = 0 then
      RaiseError('Window class registration failed: Windows error #' + IntToStr(GetLastError));

  // Allocate handle
  Result := CreateWindowEx(WS_EX_TOOLWINDOW,
                           WindowClass.lpszClassName,
                           '',        { Window name   }
                           WS_POPUP,  { Window Style  }
                           0, 0,      { X, Y          }
                           0, 0,      { Width, Height }
                           0,         { hWndParent    }
                           0,         { hMenu         }
                           HInstance, { hInstance     }
                           nil);      { CreateParam   }
  if Result = 0 then
    RaiseError('Window handle allocation failed: Windows error #' + IntToStr(GetLastError));

  // Set user data
  SetWindowLong(Result, 0, Integer(self));
end;

function TWindowHandle.HandleWM(const Msg: Cardinal; const wParam, lParam: Integer): Integer;
var Handled : Boolean;
begin
  Result := 0;
  Handled := False;
  if Assigned(FOnMessage) then
    Result := FOnMessage(Msg, wParam, lParam, Handled);
  if not Handled then
    Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam); // Default handler
end;

function TWindowHandle.MessageProc(const Msg: Cardinal; const wParam, lParam: Integer): Integer;
var R : Boolean;
begin
  if Assigned(FOnBeforeMessage) then
    FOnBeforeMessage(self);
  R := Assigned(FOnAfterMessage);
  try
    try
      Result := HandleWM(Msg, wParam, lParam);
    except
      on E : Exception do
        begin
          if Assigned(FOnException) then
            FOnException(self, E);
          Result := 0;
        end;
    end;
  finally
    if R then
      if Assigned(FOnAfterMessage) then
        FOnAfterMessage(self);
  end;
end;

function TWindowHandle.GetWindowHandle: HWND;
begin
  Result := FWindowHandle;
  if Result = 0 then
    begin
      FWindowHandle := AllocateWindowHandle;
      Result := FWindowHandle;
    end;
end;

procedure TWindowHandle.DestroyWindowHandle;
begin
  if FWindowHandle = 0 then
    exit;

  // Clear user data
  SetWindowLong(FWindowHandle, 0, 0);

  DestroyWindow(FWindowHandle);
  FWindowHandle := 0;
end;

function TWindowHandle.ProcessMessage: Boolean;
var Msg : Windows.TMsg;
begin
  if FTerminated then
    begin
      Result := False;
      exit;
    end;
  Result := PeekMessage(Msg, 0, 0, 0, PM_REMOVE);
  if Result then
    if Msg.Message = WM_QUIT then
      FTerminated := True else
      if FTerminated then
        Result := False else
        begin
          TranslateMessage(Msg);
          DispatchMessage(Msg);
        end;
end;

procedure TWindowHandle.ProcessMessages;
begin
  While ProcessMessage do ;
end;

function TWindowHandle.HandleMessage: Boolean;
var Msg : Windows.TMsg;
begin
  if FTerminated then
    begin
      Result := False;
      exit;
    end;
  Result := GetMessage(Msg, 0, 0, 0);
  if not Result then
    FTerminated := True else
    if FTerminated then
      Result := False else
      begin
        TranslateMessage(Msg);
        DispatchMessage(Msg)
      end;
end;

procedure TWindowHandle.MessageLoop;
begin
  While HandleMessage do ;
end;

procedure TWindowHandle.Terminate;
begin
  FTerminated := True;
end;



{                                                                              }
{ TTimerHandle                                                                 }
{                                                                              }
Constructor TTimerHandle.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FTimerInterval := 1000;
end;

procedure TTimerHandle.DestroyWindowHandle;
begin
  if not (csDesigning in ComponentState) and (FWindowHandle <> 0) and
      FTimerActive then
    KillTimer(FWindowHandle, 1);
  inherited DestroyWindowHandle;
end;

function TTimerHandle.DoSetTimer: Boolean;
begin
  if FTimerInterval <= 0 then
    Result := False
  else
    Result := SetTimer (GetWindowHandle, 1, FTimerInterval, nil) = 0;
end;

procedure TTimerHandle.Loaded;
begin
  inherited Loaded;
  if not (csDesigning in ComponentState) and FTimerActive then
    DoSetTimer;
end;

procedure TTimerHandle.TriggerTimer;
begin
  if Assigned(FOnTimer) then
    FOnTimer(self);
end;

procedure TTimerHandle.SetTimerActive(const TimerActive: Boolean);
begin
  if FTimerActive = TimerActive then
    exit;
  if [csDesigning, csLoading] * ComponentState = [] then
    if TimerActive then
      begin
        if not DoSetTimer then
          exit;
      end else
      KillTimer(FWindowHandle, 1);
  FTimerActive := TimerActive;
end;

function TTimerHandle.HandleWM(const Msg: Cardinal; const wParam, lParam: Integer): Integer;
begin
  if Msg = WM_TIMER then
    try
      Result := 0;
      TriggerTimer;
    except
      on E: Exception do
        begin
          Result := 0;
          if Assigned(FOnException) then
            FOnException(self, E);
          exit;
        end;
    end
  else
    Result := inherited HandleWM(Msg, wParam, lParam);
end;



initialization
finalization
  if Assigned(VersionInfoBuf) then
    FreeMem(VersionInfoBuf);
end.


瑞萨RZ系列MCU图形化引脚与DDR配置工具Smart Configurator V2.1.0实战指南 在嵌入式硬件开发中,引脚配置与DDR内存控制器设置是决定系统稳定性的关键环节,尤其对于瑞萨RZ这类引脚复用复杂的高性能微控制器。传统基于数据手册的手动配置方式,不仅效率低下,且极易因信息过载导致引脚冲突或功能分配错误。图形化配置工具通过将芯片硬件约束规则内化,实现了从“手工查表”到“可视化选择与自动校验”的转变,其核心价值在于提升设计的首次正确率与团队协作效率。这类工具在工程实践中,能显著加速从芯片选型到原理图设计的关键阶段。本次解析的Smart Configurator for RZ V2.1.0,其重要 阅读详情

相关推荐

Azure数据管道工程化实战:从脏数据处理到星型模型构建

数据管道是现代数据平台的核心基础设施,其本质是将原始、异构、不可信的数据,通过可编排、可监控、可回滚的批处理流程,转化为可信、一致、可分析的业务资产。核心原理在于分层治理(Bronze/Silver/Gold)、职责隔离与失败即状态的设计哲学。技术价值体现在提升数据可信度、降低运维成本、满足合规审计,并支撑下游BI与AI应用。典型应用场景包括零售销量预警、金融交易对账、IoT设备指标聚合等T+1分析需求。本项目以Azure Data Factory为编排中枢,结合Azure Functions做数据质量守门

weixin_30797199的博客 690

把荔枝派Zero玩成USB瑞士军刀:实战配置USB Gadget(串口、网卡、存储、HID)

本文详细介绍了如何将荔枝派Zero开发板配置为多功能USB Gadget设备,实现串口调试、网络共享、存储传输和HID输入模拟等功能。基于全志V3S处理器,通过Linux USB Gadget框架和ConfigFS接口,开发者可以灵活组合各种功能,打造嵌入式开发的瑞士军刀工具。文章包含完整的配置脚本和优化技巧,助力开发者充分发挥这块超小型开发板的潜力。

weixin_30530939的博客 409

Coding Plan:本地AI编码工作流的确定性革命

AI 编码工作流正从‘模型调用’迈向‘操作系统级集成’。其核心原理在于将大模型能力封装为稳定、可观测、可编排的服务原语,通过统一协议(如 OpenAI 兼容接口、MCP)解耦推理层与工具链,从而消除本地部署中的模型加载失败、工具胶水化、配置碎片化等典型痛点。技术价值体现在稳定性提升、调试成本归零、Token 精细度量与 ROI 可计算;典型应用场景覆盖 Git 自动化(如 openclaw hook)、ComfyUI 可视化编排、Rust/WASM 调试及多模态数据质量分析。本文聚焦千问 Coding Pl

weixin_34342207的博客 384

窗口函数window functions

Flink窗口函数window functions

weixin_45538732的博客 1339

别光看代码!用IDA Pro动态调试‘Hello CTF’,带你亲眼看见Flag如何生成

本文详细介绍了如何使用IDA Pro动态调试工具逆向分析'Hello CTF'程序,揭示flag生成的全过程。通过设置断点、单步执行和内存观察,读者将掌握动态调试的核心技巧,理解程序运行时行为,并学会逆向推导flag算法。文章还分享了CTF比赛中的实用策略和高级调试技巧,适合逆向工程初学者和进阶者学习。

weixin_30721077的博客 405

图嵌入算法在GAP系统中的优化与应用

图嵌入作为连接离散数学与连续几何的关键技术,通过将图结构映射到几何空间来揭示其内在特性。其核心原理是利用正交嵌入算法,将顶点表示为格点并满足特定内积条件。在代数图论与低维拓扑学中,这种技术能有效解决流形填充、拓扑不变量计算等基础问题。GAP系统的OrthogonalEmbeddings命令为此提供了强大支持,但传统方法存在无法自动区分标准/半标准嵌入、处理坏部分效率低下等局限。通过引入自动分类机制和扩展验证模块,结合Working Conditions约束条件集,显著提升了算法在三维流形研究中的实用性。该优

weixin_30617695的博客 425

算法学习 - Window Functions 窗函数

窗函数是为了改善窗效应。

甲客实验室 4888

(赛事-2022)[re:Invent 2018]-002:通过分析log多次迭代优化奖励函数后- 最快7.6s / 圈

Deepracer training 流程

Rainbow 4711

9.22. Window Functions

9.22窗口函数 窗口函数提供根据当前查询行进行行集计算的功能。更多信息,参见第3.5节。有关语法,参见第4.2.8节。 表9.60列出了所有的内置窗口函数。调用时需要使用窗口函数的语法,例如,需要有OVER子句。 ...

在路上 320

别再手动敲代码了!用STM32CubeMX+FreeRTOS图形化配置,5分钟搞定多任务通信框架

本文详细介绍了如何利用STM32CubeMX和FreeRTOS快速搭建多任务通信框架,大幅提升嵌入式开发效率。通过图形化配置工具,开发者可在5分钟内完成任务调度、时钟配置和内核对象生成,特别适合物联网设备开发。文章还提供了代码优化和调试技巧,帮助开发者轻松应对复杂应用场景。

weixin_30363285的博客 291

中兴问天 BE7200MAX SFP 光口用华为猫棒替代光猫完整配置教程

PPPoE 账号密码:若原光猫为 Route 模式,在宽带设置页可见用户名,密码需按 F12 打开浏览器开发者模式,点击密码输入框,查看代码中 “value=” 后的内容即为明文密码。若仍失败,核对 PON 类型是否与运营商网络匹配。PON 认证信息:LOID(逻辑 ID,部分地区含密码)、设备 SN 码(标签或设备信息页)、PON 类型(GPON/EPON,运营商网络类型)。电脑保持与路由器连接,访问路由器管理地址(默认通常为 192.168.5.1,可参考路由器说明书),登录后台。

Gulper_Eel的博客 3333

clickhouse--Window Functions 窗口函数概念讲解及实际使用示例

Window Functions 在clickhouse的需求和呼声很高,早期的版本需要借助array类函数【如`groupArray`, `arrayJoin`, `groupArrayMovingSum` , `groupArrayMovingAvg functions`】实现,在v21.3版本进行了开窗函数的初步支持,但只是实验版本,在v21.9版本正式支持,可以在生产中使用。 本文针对Window Functions 窗口函数概念、如何开启窗口函数的支持进行讲解,并提供实际使用的SQL示例

penriver的博客 9435

动态欧拉角与静态欧拉角:从理论到实践的深度解析

本文深度解析了动态欧拉角与静态欧拉角的核心区别与应用场景。静态欧拉角基于固定世界坐标系,适用于全局导航与三维场景编辑;而动态欧拉角基于物体自身坐标系,更符合飞行模拟、机器人控制等直觉操作,但需警惕其固有的万向节死锁问题。文章通过理论结合实战,帮助开发者在机器人、无人机及图形学项目中正确选用与处理旋转表示。

java5的博客 1073

Flink学习笔记-WindowsFunction(篇二)

Flink学习笔记-WindowsFunction(篇二)ProcessWindowFunctionProcessWindowFunction抽象类ProcessWindowFunction简单例子ProcessWindowFunction with Incremental AggregationAggregateFunction combined with ProcessWindowFuncti...

yangxiaobo118的博客 4341

PX4无人机offboard开发之旅

(慢慢更)无人机OFFBOARD开发

InTereSTingHE的博客 1078

怎样让你的论文看起来“像人写的”?只用三招直接去除AI味(附提示词)

当然如果你在实际使用中还有其他需求,比如降重润色、改写翻译等,也可以结合七哥的专业写作平台来辅助,这个高级学术平台已经内置了ChatGPT4o、ChatGPT4.1、Claude3.7、满血版DeepSeek-R1等AI大模型,帮你写文献综述、干课题申报、写论文等学术任务绝对每一点问题。比如我自己的一套学术写作平台,其中的“降重与润色”模块整合了多种GPTs应用,除了能帮助调整语言风格、避免雷同表达,还可以顺带降个重,对于提升学术文本的整体质量还是非常有用的。一、为什么用AI写出来的文章会有AI味?

智能AI让学术科研更容易 1685

基于Windows底层API的网络端口扫描与安全监控系统设计与实现

PortSentinel:基于Windows IPHelper API的轻量级端口扫描与安全监控工具 摘要 随着网络威胁的演进,开放端口成为勒索病毒(如WannaCry利用445端口)和远程漏洞(如BlueKeep攻击3389端口)的主要入侵途径。针对现有工具(如Nmap命令行复杂、netstat功能单一、商业方案成本高)的不足,本文设计并实现了PortSentinel —一款面向Windows平台的轻量化安全工具。

donoot的博客 506

黏菌优化算法(SMA)详解:从生物智能到优化引擎

黏菌优化算法(SMA)是一种新型生物启发式优化算法,模拟多头绒泡菌的智能觅食行为。该算法包含接近食物、包围食物和抓取食物三个阶段,通过数学模型将生物行为转化为优化过程。SMA采用权重自适应机制和参数振荡模型实现探索与开发的平衡,具有参数简单、收敛性好等优势。算法可通过MATLAB/Python实现,并应用于函数优化、工程设计和神经网络训练等领域。研究表明SMA在求解复杂优化问题时表现优异,未来可通过混沌增强、混合策略等方式进一步提升性能。

qq_42212808的博客 659

《超简单:用 Python 让 Excel 飞起来》读书笔记:9.1.1 在 Excel 中加载 xlwings 插件

本文介绍了如何在Excel中加载xlwings插件以实现Excel与Python的交互。主要内容包括: 加载xlwings插件的必要性:仅安装Python库无法实现Excel调用Python函数,需要插件作为桥梁 环境准备:确认Python可正常运行、正确安装xlwings、Excel启用宏功能 操作步骤:通过xlwings quickstart命令创建项目模板,配置Python路径,使用Import Functions导入自定义函数 核心价值:实现Excel界面与Python计算能力的结合,为复杂计算、批

分享 Windows 系统部署、镜像封装、终端管理、故障排查与运维自动化实践,涵盖 Sysinternals、PowerShell 和 AI 工具应用。以真实案例梳理排查思路与解决步骤,让运维经验清晰、可复用。 2万+

【论文汇总】Diffusion Models视频生成/视频编辑/可控视频生成/跨模态视频生成

本文总结了Diffusion Models视频生成领域相关的工作,目前共收录142篇,持续更新中。

沉迷单车的追风少年 1672

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

开源EMOS-简单嵌入式操作系统

EMOS 嵌入式操作系统继承于uCOS-ii v2.0 的改写。基于uCOS-ii 的核心思想和核心代码,进行了如下改写: (1) 所有核心代码基于商业代码常用风格进行重写。结合笔者多年嵌入式软件开发经验总结进行重写和归纳。 (2) 提供MinGW仿真平台环境,无需基于Borland C++或者实物CPU平台进行仿真。uCOS-ii提供了大量平台的移植件,这些移植件基于简单的修改即可提供给EMOS使用。MinGW仿真平台移植代码基于uCOS-ii 之Visual C++ 6.0 仿真平台代码修改获得。

TechEdu2026的博客 327

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

TUSB8020B USB 3.0集线器芯片:从核心原理到硬件设计实战

USB集线器作为计算机外设扩展的核心组件,其本质是一个复杂的协议转换与流量调度中心。它需要同时处理从SuperSpeed到Low-Speed的多速率数据流,并确保信号完整性与电源管理。在USB 3.0时代,**多事务转换器(MTT)架构**和**电池充电(BC1.2)协议**成为提升用户体验的关键技术。MTT通过为每个端口提供独立的事务转换器,解决了低速设备阻塞高速通信的经典问题,实现了真正的性能隔离。而集成的充电协议支持,则让集线器在扩展功能的同时,能智能识别连接设备并提供快速充电。这些特性通过高度集成的

weixin_30385925的博客 413

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Gemma 4本地部署实战:手机/PC/Chrome三端轻量大模型落地指南

轻量大模型本地部署是边缘AI落地的核心能力,其本质是模型量化、硬件适配与运行时调度的系统工程。Gemma 4作为面向资源受限场景优化的非官方精简变体,通过层数压缩、词表精简和LayerNorm替换,在4-bit量化下仍保持高推理稳定性,显著降低内存占用与推理延迟。该技术路径直击移动端内存碎片化、PC端CPU加速兼容性、浏览器WebGPU原子操作缺失等典型工程瓶颈,适用于离线合同审核、通勤语音纪要、跨设备轻量创作等真实业务场景。本文聚焦Gemma 4在Android WebView、Windows/macOS

weixin_30824479的博客 326

Claude Opus 4.7:可验证推理引擎的工程化落地

AI推理过程的可解释性与可控性,是大模型从实验走向生产的核心瓶颈。传统黑箱式输出难以调试、审计与优化,而结构化推理(reasoning_steps)通过显式暴露思考路径,使AI行为具备可追溯性、可干预性和可验证性。Claude Opus 4.7首次将该能力作为默认API特性交付,结合reasoning_effort调节、step tracing与动态缓存机制,真正实现从‘文本生成器’到‘可编程推理引擎’的范式升级。它适用于金融风控、合规审查、AI Agent编排等强确定性需求场景,尤其为需要代码可维护性、结

weixin_33716154的博客 399

微软技术周报 · 2026-08-11~2026-08-18

微软本周技术动态聚焦两大方向:AI体验整合与安全更新。AI方面,Copilot统一入口copilot.cloud.microsoft上线,Foundry Agent框架GA,MAI模型家族完成5线整合;开发者工具上,C# 14正式支持扩展成员、field关键字等特性,.NET 11 Preview 7优化异步分层编译和WASM支持。安全侧发布8月补丁日,修复421个CVE(含1个Lazarus组织利用的零日漏洞)。其他亮点包括VS Code接入MAI-Voice、Power Platform现代控件GA、T

海盗Sharp的博客 829

Pytest+YAML+Allure构建高效自动化测试报告方案

自动化测试是现代软件开发流程中的重要环节,其核心价值在于通过脚本替代人工执行重复测试任务。在Python技术栈中,Pytest框架凭借其灵活的Fixture机制和丰富的插件生态成为自动化测试的首选工具。结合YAML进行测试数据管理,可以实现测试逻辑与数据的有效分离,提升用例的可维护性。而Allure作为测试报告生成工具,通过可视化图表和详尽的步骤记录,将原始测试数据转化为直观的交互式报告。这套技术组合特别适用于需要频繁回归测试的电商、金融等领域,能显著提升测试结果的分析效率。其中Pytest的断言机制和Al

weixin_30385925的博客 368
上一篇: 死了都要爱
下一篇: Windows Registry functions v3.0
SafeF8
博客等级 码龄22年 10粉丝 104原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值