Link to home
Start Free TrialLog in
Avatar of perkley
perkley

asked on

Reading/Writing Resource File?

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.
Avatar of inthe
inthe

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:
http://www.wilsonc.demon.co.uk/Delphi%20Components/Dred/dred.zip

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. "

Avatar of perkley

ASKER

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?
This site has lots of info:

http://www.gnomehome.demon.nl/uddf/

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

Eps.
Avatar of perkley

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hell, why not just use the registry?
Avatar of simonet
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.

Yours,

Alex
Athena's Place: http://www.bhnet.com.br/~simonet
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...
Avatar of perkley

ASKER

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.  
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.

Yours,

Alex






Avatar of perkley

ASKER

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?
>what would you want in turn for the code to manipulate (snip)

The code I have is not for sale. Sorry.

Alex
Avatar of perkley

ASKER

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.
Avatar of perkley

ASKER

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