Solved

Reading/Writing Resource File?

Posted on 2000-03-25
14
293 Views
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.
0
Comment
Question by:perkley
[X]
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
14 Comments
 
LVL 17

Expert Comment

by:inthe
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:
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. "

0
 

Author Comment

by:perkley
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?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2657263
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.
0
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

by:perkley
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?
0
 
LVL 17

Accepted Solution

by:
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..
see:
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10317488 
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 ..
0
 
LVL 3

Expert Comment

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

Expert Comment

by:simonet
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.

Yours,

Alex
Athena's Place: http://www.bhnet.com.br/~simonet
0
 
LVL 13

Expert Comment

by:Epsylon
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...
0
 

Author Comment

by:perkley
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.  
0
 
LVL 15

Expert Comment

by:simonet
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.

Yours,

Alex






0
 

Author Comment

by:perkley
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?
0
 
LVL 15

Expert Comment

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

The code I have is not for sale. Sorry.

Alex
0
 

Author Comment

by:perkley
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.
0
 

Author Comment

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

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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