Solved

Read/Write resources...

Posted on 1998-05-11
4
177 Views
Last Modified: 2010-04-10
Hello guys,

I used to develop on Mac and I remember it was possible to Read&Write resources. Applications have a
resource fork and a data fork. I would like now to do the same under windoz so I know how to read a
resource (ex String) but I am not sure it is possible to write it (after modification) and if yes, how to do that.

Can you help me ??

Thanks a lot,
WW
0
Comment
Question by:wwalschaerts
  • 3
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 1175665
Answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175666
The Mac OS was built from the ground up to support a GUI.  So they could think ahead and designed files with two forks.  The Windows OS has its roots in DOS (which really came from CP/M) so it doesn't support two forks.  The windows resources are imbedded into the EXE file or DLL file by the linker and they are static.  You could actually go an change the information, if you were carefule, but the format of the information is complex and you have to be careful not to overwrite other resources and/or code.  The other think that makes it tough is that when a EXE or DLL is loaded, the file is open read-only.  So you can change the resources if a file, but only from a seperate program.  That is a EXE can change another EXE or DLL, but not its self.  If you really needed to modify resources, the  best way would be to modify ones in a DLL and then load the DLL with LoadLibrary to access the new resources in it.  However, there is usually no need to modify resources in windows.  Especially now that there is the registry.  I hope this helps.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1175667
Win95 does not support updating resources of an exe or dll.  You can only do this under WinNT.

Win32 (on NT) has quite good APIs for updating resources.

The BeginUpdateResource function creates an update handle for the executable file whose resources are to be changed. You must have write access to the executable, so it cannot be already executing.  The UpdateResource function uses this handle to add, delete, or replace a resource in the executable file. The EndUpdateResource function closes the handle.

After an update handle to an executable file is created by BeginUpdateResource, an application can use UpdateResource repeatedly to make changes to the resource data. Each call to UpdateResource contributes to an internal list of additions, deletions, and replacements but does not actually write the data to the executable file. Immediately before closing the update handle, EndUpdateResource writes the accumulated changes to the executable file.

However, as I pointed, you CANNOT do this in Win95 .. the APIS's aren't supported.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1175668
That's good to know.

The big problem then (besides the no 95 support) is that the application can't be running.  However you can write to an unloaded DLL and then load the DLL.  When you want to make changes, unload the DLL, write, and load again.  However, as I pointed out, you probably don't need this.  The registry works well for most tasks where you would have written to the resources on the MAC.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

776 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