Einzelnen Beitrag anzeigen

Kas Ob.

Registriert seit: 3. Sep 2023
346 Beiträge
 
#19

AW: Windows 2022 Server, mit Delphi erstelltes exe hat Fehler

  Alt 6. Sep 2024, 13:29
On my XE8, an empty VCL project does in fact call RegisterClass only once for TMenuItem, so OutputDebugString might be enough as the list might be short.

Here is a full hooking unit
Delphi-Quellcode:
unit lcHookRegisterClass;

interface

uses
  Classes, Windows, DDetours;

//procedure InstallHook;

type
  TRegisterClassProc = procedure(AClass: TPersistentClass);

var
  TrampolineRegisterClass: TRegisterClassProc;

implementation

procedure InterceptRegisterClass(AClass: TPersistentClass);
begin
  TrampolineRegisterClass(AClass); // call the original to register, we don't break the application

  // AClass.ClassName to log , file or OutputDebugString ...
  OutputDebugString(PChar(AClass.ClassName)); // OutputDebugString need Windows in uses clause
end;

procedure InstallHook;
begin
  // Classes.RegisterClass , we use full name and path to the proc if possible to prevent confusion as there is Windows API as RegisterClass
  if not Assigned(TrampolineRegisterClass) then
    TrampolineRegisterClass := InterceptCreate(@Classes.RegisterClass, @InterceptRegisterClass);
end;

initialization
  InstallHook;


finalization
  if Assigned(TrampolineRegisterClass) then
    InterceptRemove(@TrampolineRegisterClass);

end.
lcHookRegisterClass should be the first in in the uses clauses in the dpr file, or the second if there is Memory Manger unit is used, something like this
Delphi-Quellcode:
program Project10;

uses
  lcHookRegisterClass in 'lcHookRegisterClass.pas',
  Vcl.Forms,
  uMain in 'uMain.pas{Form10};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm10, Form10);
  Application.Run;
end.
Kas
  Mit Zitat antworten Zitat