How to attach a resource file to an existing executable file?

前端 未结 3 1346
猫巷女王i
猫巷女王i 2021-01-02 06:33

I have a resource file(.RES) and i want to add it into an existing executable file without recompiling and using the IDE! is it possible?

Edit

3条回答
  •  自闭症患者
    2021-01-02 06:45

    You can use Colin Wilson's excellent Resource Utilities.

    I'm using this simple console application to add a resource to an executable using his tools:

    program AddResource; 
    
    {$APPTYPE CONSOLE}
    
    uses
      SysUtils,
      Classes,
      unitNtModule,
      unitResFile,
      unitResourceRCData;
    
      procedure AddRes(exeName, resName: string);
      var
        exeModule: TNTModule;
        resFile  : TResModule;
      begin
        if ExtractFileExt(exeName) = '' then
          exeName := ChangeFileExt(exeName, '.exe');
        exeModule := TNTModule.Create;
        try
          exeModule.LoadFromFile(exeName);
          resFile := TResModule.Create;
          resFile.LoadFromFile(resName);
          exeModule.AddResource(resFile.ResourceDetails[0]);
          exeModule.SaveToFile(exeName);
        finally FreeAndNil(exeModule); end;
      end; { AddRes }
    
    begin
      if ParamCount <> 2 then
        Writeln('Usage: AddResource  ')
      else
        AddRes(ParamStr(1), ParamStr(2));
    end.
    

提交回复
热议问题