nikif
asked on
Save data in dll
Hi,
I am trying to make a resource only dll, load its data, modify it in runtime, finally save it back in dll.
What I've managed so far is:
I made a file abcDLL.rc with content:
nickname RCDATA abcData.txt
(file abcData.txt contains some ascii data)
I compiled it with: brcc32 abcDLL.rc
Produced: abcDLL.RES
I created DLLtest.dpr as resource only dll (code follows) and compiled:
library DLLtest;
uses
SysUtils, Classes;
{$R abcDLL.RES}
begin
end.
I added a button to load ascii data from dll into a TMemo. It works fine.
procedure TForm1.btLoadRCClick(Sende r: TObject);
var
h : THandle;
RS: TResourceStream;
begin
h := LoadLibrary ('DLLtest.DLL');
if h <> 0 then
begin
RS := TResourceStream.Create (h, 'nickname', RT_RCDATA);
Memo1.Lines.LoadFromStream (RS);
end;
FreeLibrary (h);
end;
Then, during runtime the user modifies text in Memo1.
The question is how could I save new content of Memo1 to DLLtest.dll?
I tried the following code. Could anyone complete it?
procedure TForm1.btSaveRCClick(Sende r: TObject); // Click button
var
h : THandle;
RS: TResourceStream;
begin
// Save new text in dll
RS := TResourceStream.Create (h, PChar ('nickname'), RT_RCDATA);
//------------------------ ---------- ---------- ---------- ----
// Error: Resource "nickname" not found
// RS.... need to load Memo1.Lines to RS. How?
//------------------------ ---------- ---------- ---------- ----
RS.SaveToFile ( 'DLLtest.DLL');
// Will it work? Do I need the analogous of h := LoadLibrary ('DLLtest.DLL'); ?
RS.Free;
end;
I use D6
Thank you for your assistance
Nikif
I am trying to make a resource only dll, load its data, modify it in runtime, finally save it back in dll.
What I've managed so far is:
I made a file abcDLL.rc with content:
nickname RCDATA abcData.txt
(file abcData.txt contains some ascii data)
I compiled it with: brcc32 abcDLL.rc
Produced: abcDLL.RES
I created DLLtest.dpr as resource only dll (code follows) and compiled:
library DLLtest;
uses
SysUtils, Classes;
{$R abcDLL.RES}
begin
end.
I added a button to load ascii data from dll into a TMemo. It works fine.
procedure TForm1.btLoadRCClick(Sende
var
h : THandle;
RS: TResourceStream;
begin
h := LoadLibrary ('DLLtest.DLL');
if h <> 0 then
begin
RS := TResourceStream.Create (h, 'nickname', RT_RCDATA);
Memo1.Lines.LoadFromStream
end;
FreeLibrary (h);
end;
Then, during runtime the user modifies text in Memo1.
The question is how could I save new content of Memo1 to DLLtest.dll?
I tried the following code. Could anyone complete it?
procedure TForm1.btSaveRCClick(Sende
var
h : THandle;
RS: TResourceStream;
begin
// Save new text in dll
RS := TResourceStream.Create (h, PChar ('nickname'), RT_RCDATA);
//------------------------
// Error: Resource "nickname" not found
// RS.... need to load Memo1.Lines to RS. How?
//------------------------
RS.SaveToFile ( 'DLLtest.DLL');
// Will it work? Do I need the analogous of h := LoadLibrary ('DLLtest.DLL'); ?
RS.Free;
end;
I use D6
Thank you for your assistance
Nikif
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect!!!!
Thanks a lot
Nikiforos
Thanks a lot
Nikiforos
This will not work:
RS.SaveToFile ( 'DLLtest.DLL');
SaveToFile might create a file called DLLtest.DLL, but that will never be a new generated DLL with the updated text.
You get the text resource in RS from the DLL, that you load by handle:
RS := TResourceStream.Create (h, 'nickname', RT_RCDATA);
Memo1.Lines.LoadFromStream
Calling RS.SaveToFile does not make any sense.
Compiled DLL is wrapped around the included resources, you can not inject the text afterward.