Solved

Reading/Writing Resource File?

Posted on 2000-03-25
14
275 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
  • 6
  • 3
  • 2
  • +2
14 Comments
 
LVL 17

Expert Comment

by:inthe
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:perkley
Comment Utility
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
Comment Utility
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
Comment Utility
Hell, why not just use the registry?
0
 
LVL 15

Expert Comment

by:simonet
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>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
Comment Utility
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
Comment Utility
It was good answers, but didn't quite give me what I was looking for.  Thanks for the help anyway.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now