给一点思路 仅供参考
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function ExtractDFM(ApplicationName, FormClassName: string): string;
var
AppHandle: THandle;
ResStream: TResourceStream;
ResultStream: TStringStream;
begin
Result := '';
AppHandle := LoadLibraryEx(PChar(ApplicationName), 0, LOAD_LIBRARY_AS_DATAFILE);
if AppHandle = 0 then
raise Exception.Create('Could not load application');
ResStream := nil;
ResultStream := nil;
try
ResStream := TResourceStream.Create(AppHandle, FormClassName, RT_RCDATA);
ResultStream := TStringStream.Create('');
ObjectBinaryToText(ResStream, ResultStream);
Result := ResultStream.DataString;
finally
ResultStream.Free;
ResStream.Free;
FreeLibrary(AppHandle);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Add(ExtractDFM('D:/aaa.exe', 'TForm1'));
end;
end.