开发者

How to test if an application (.exe) is built with runtime package

开发者 https://www.devze.com 2022-12-30 10:26 出处:网络
How may I test in coding if my .exe Delphi application is built with 开发者_StackOverflow中文版runtime package or is single .exe?Another possibility:

How may I test in coding if my .exe Delphi application is built with 开发者_StackOverflow中文版runtime package or is single .exe?


Another possibility:

function UsesRuntimePackages: Boolean;
begin
  Result := FindClassHInstance(TObject) <> HInstance;
end;


Another possibility, in case you need this for an external executable (without running it):

procedure InfoProc(const Name: string; NameType: TNameType; Flags: Byte; Param: Pointer);
begin
  case NameType of
    ntContainsUnit:
      if Name = 'System' then
        PBoolean(Param)^ := False;
  end;
end;

function UsesRuntimePackages(const ExeName: TFileName): Boolean;
var
  Module: HMODULE;
  Flags: Integer;
begin
  Result := True;

  Module := LoadLibraryEx(PChar(ExeName), 0, LOAD_LIBRARY_AS_DATAFILE);
  try
    Flags := 0;
    GetPackageInfo(Module, @Result, Flags, InfoProc);
  finally
    FreeLibrary(Module);
  end;
end;


Use could use the EnumModules() procedure, like so:

function EnumModuleProc(HInstance: Integer; Data: Pointer): Boolean;
begin
  Result := True;
  if HInstance <> MainInstance then begin
    Inc(PInteger(Data)^);
    Result := False;
  end;
end;

function UsesRuntimePackages: boolean;
var
  PckgCount: integer;
begin
  PckgCount := 0;
  EnumModules(EnumModuleProc, @PckgCount);
  Result := PckgCount > 0;
end;


Did you try "Islibrary" ?

0

精彩评论

暂无评论...
验证码 换一张
取 消