Reading/Writing Resource File?

Posted on 2000-03-25
Last Modified: 2010-04-04
I can tell you my entire project, since it is of nothing of importance:  I am wanting to create a form that shows maximized and shows some text on it, like "Happy Birthday" or "Merry Christmas".  Now, this is not a problem, but I want to be able to change the message, font, color, date and time that it should popup on someones computer screen.

What I need answered is how to store a resource file within the EXE file, and read the values for the color, font, size, date, etc.  (Don't get me wrong, I know how to create and include a resource file).  I just need to know how to read those values once having included the resource file.

This is the most important part.  I want to have another form (part of the same exe file), that you can choose your color, your message, font, size, etc.  Once you are done, then it will write the new values into the EXE file.

I can easily do this with an INI file, but I do not want to have to distribute an INI and the EXE.  I just want to change the values of a few items, send the EXE to someone, and they have the new values.  This should make sense.
Question by:perkley
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +2
LVL 17

Expert Comment

ID: 2657210
hi perkley ,
just thought it better to mention you can only use the updateresource() etc api's on nt so your app wont work on win9* pc's if you do above.

if you stil ant it you can get great example of reading ,writing resources in apps on nt from here:

about above file:
" Delphi Resource Editor

NEW!!!  Delphi Resource Editor and Components.  This Beta version allows you to create and edit .RES resource files, and edit resources in existing applications and modules (.EXE, .DLL, etc.)  Supports 256 Colour Icons.  Supports Message Resources - essential for logging messages to the NT event log.  Full source included.
For Windows 95/98 and NT.  You can only edit resources in applications in NT. "


Author Comment

ID: 2657260
If I run the exe that came with that file, it says it cannot find the VCL40.bpl, probably because I am using Delphi 5.

When I try to open the code and recompile it, it needs a TResourceEditor comp, which didn't come with the package.

I do need to do this in Windows95/98 or NT.  So, this option probably won't work for me then.  Any ideas of a way to pass one file, and edit that one file to change it's attributes without using the registry and additional files?
LVL 13

Expert Comment

ID: 2657263
This site has lots of info:

Search the left frame for 'resource' and you'll find some articles about it.

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 2657271
If the first idea is not possible in Windows 95 or 98, then is it possible to do the following?

Have a separate program that you can set all of the settings, and then you create the file, which basically extracts the program to run with the new settings.  Is this possible?
LVL 17

Accepted Solution

inthe earned 100 total points
ID: 2657445
i not sure i understand your comment about second file but you can extract an exe from inside another exe if that is what you mean..
it is for .ico but exact same applies for exe.

why not like ini?
you could encrypt it easy enough and rename to settings.dat etc ..

Expert Comment

ID: 2657772
Hell, why not just use the registry?
LVL 15

Expert Comment

ID: 2657841
In my first comment, I suggested the Registry, but it seems that Perkley didn't read it.

Let me say one more thing about what you want to do:

Your main concern is not to deploy more than one file, right? Well, if you want to update the resources in your EXE, you will NECESSARILY NEED a second executable for that. A PROGRAM CANNOT EDIT ITS OWN RESOURCES. Period.

Your best shot here is to use the Registry. If you go for the Resources solution, not matter what method you use (and I know most of them, believe me), you'll end up having to write a lot more code to do a very simple and trivial task, which is to hide configuration information from the user.


Athena's Place:
LVL 13

Expert Comment

ID: 2659777
Alex, what first comment are you talking about? I don't see only 1 comment from you here...

Though I agree with you about editing resources...

Author Comment

ID: 2661367
I only see one comment from you [simonet] and you never mentioned the registry before.

Listen then, if you [simonet] know most of the ways, then tell me how I can have EXE A extract a file and update the resource file inside the newly created EXE B.  This way, EXE A is not writing to itself, but editing a resource inside of EXE B that was extracted?

All I want is code on how to edit a String Table in an .exe.  This is possible, I know it.

All the examples I have been given in this forum show how to create a resource and load the string, which I already knew.  I want to know how to update even another programs Resource File.  
LVL 15

Expert Comment

ID: 2662346
If you don't want to deploy a simple INI file, what's the point in deploying a second EXE? Doesn't sound nice to me.

If your target is WinNT, then you can use BeginUpdateResource, UpdateResource and EndUpdateResource to add/modify/delete resources in ANOTHER file that is NOT LOADED at the time.

However, that seems too much trouble just to keep config data, which is the most trivial and simple task for one to achieve: use the Registry or an encripted binary file, if you have no problems in deploying a second file.

Now, an even smarter thing would be to store EVERYTHING in a single Registry key, in a long encripted (or just ROTated) string.

About other ways to update resources in executables for Win95: yes, I know how to do them, but 100 isn't enough... 1000 points wouldn't be enough! It's code I simply don't wanna make publicly available just yet.

>This is possible, I know it

Hehehe! So do I! As I said, if you're targeting WinNT, use the 4(Begin/   /End)UpdateResource API calls, all of them very well documented in the Win32.hlp file. Other than the one I am developing exclusivel for Resource Explorer, there's no publicly/freely available code for Win9x that will let you update resources in an EXE. Even if someone other than me here had that code, 100 points wouldn't cover it.

It seems like you're very much decided about keeping config data as resources, and not willing to receive advice for better coding techniques. The Registry, INI files, encripted file, etc, are all much better than updating a resource. Just wonder what would happen if there were 2 instances of your program running if a user decided to save config data (lie "Save settings" from Instance 1 , that wouldn't be possible, because Win32 locks an executable (EXE, DLL, etc) file when it's lodad into memory. Just think about that.

About my reference to a previous comment of mine, there really was one, right after you posted your Q, however, since I had too many open browser windows at the time, I misplaced the comment to you in another thread.

I just want to know what are the advantages of having config data in the executable. I see none.




Author Comment

ID: 2662419
Thanks for your comments.  About distributing a second .exe file is not a question, because my computer would set the settings, I would just send out the second EXE.  If I wanted to make changes, then I make changes on my computer, send out a new EXE.  In other words, whoever I give it to, they only have one file.  I don't care how many files I have, I just don't want to send out more than one file.

To tell you the truth, it is not a big deal, but I was just hoping that I could get it answered for future reference, but as I can see, it is not an easy thing.

Question though, what would you want in turn for the code to manipulate the resource files on a Windows95/98 platform?
LVL 15

Expert Comment

ID: 2662665
>what would you want in turn for the code to manipulate (snip)

The code I have is not for sale. Sorry.


Author Comment

ID: 2662895
Well, seeing how I cannot get the code to do what I want, inthe gave the answer that is most feasible first.  I am going to give him the points unless someone else rejects to this with a good reason.

I will wait 1 day and then he gets it if nobody else has responded.

Author Comment

ID: 2670007
It was good answers, but didn't quite give me what I was looking for.  Thanks for the help anyway.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 124
Multiple image collision 13 106
Firemonkey android show image from resource ? 1 71
Delphi: sending SMS on android platform 1 99
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question