Save data in dll

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;
  SysUtils, Classes;
{$R abcDLL.RES}

I added a button to load ascii data from dll into a TMemo. It works fine.
procedure TForm1.btLoadRCClick(Sender: TObject);
  h : THandle;
  RS: TResourceStream;
  h := LoadLibrary ('DLLtest.DLL');
  if h <> 0 then
    RS := TResourceStream.Create (h, 'nickname', RT_RCDATA);
    Memo1.Lines.LoadFromStream (RS);
  FreeLibrary (h);

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(Sender: TObject); // Click button
  h : THandle;
  RS: TResourceStream;
// 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'); ?

I use D6

Thank you for your assistance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

That's not possible. You could use ini file, simple DB (SQLite?) or other alternative solution.

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 (RS);

Calling RS.SaveToFile does not make any sense.

Compiled DLL is wrapped around the included resources, you can not inject the text afterward.
Sinisa VukSoftware architectCommented:
you can use function like this:
function WriteTextToRes(sDllFile: String; sTextToWrite: String): Boolean;
  hResourceHandle: Cardinal;
  hResourceHandle := BeginUpdateResource(PChar(sDllFile), True);
    Result := UpdateResource(hResourceHandle, RT_RCDATA, 'nickname', LANG_NEUTRAL, PChar(sTextToWrite), Length(sTextToWrite));
    EndUpdateResource(hResourceHandle, False);

Open in new window

note: dll file must not be in use (opened)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nikifAuthor Commented:
Thanks a lot

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.