Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Resource files.

Author
Message
Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 22nd May 2008 21:26
This question is realy more to do with VC2008 rather than darkGDK.

What I want to do is to include a text file as part of my compiled exe. Then at runtime load/read it. I believe from some searching I need to make a 'resource file' and include it that way. But I'm such a c++ noob that I have never used a resource file before.

What I need to know is how do I:
Include a plain text file in my compiled exe.
Access the data in it at run time.

Thankyou


The word "Gullible" cannot be found in any English Dictionary.
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 22nd May 2008 21:57
Resource files are how Windows does it, but they are compiled by the resource compiler, and become an integral part of the application. There are functions that load the resource, depending on the type of resource you are using, but those are menus, dialogs, strings, icons, etc. To load an icon, for example, it would be LoadIcon.

If that is what you are referring to, then you need to have a file that contains the resource definitions named resource.h, and another text file, properly formatted with an extension of .rc The name is the project name by convention, although I'm not certain if that is required.
Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 23rd May 2008 00:30
jinzani thanks for answer, but I'm still unsure of specificaly what I need to do.

To include a text file, eg: "abc.txt" and access it during run time:

What do I write in the resource.h file?
How do I format and write the .rc file?
How do I load and use the data in the file "abc.txt"?

Could anyone give me specifics on how I would do this?

Thanks.


The word "Gullible" cannot be found in any English Dictionary.
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 23rd May 2008 08:00 Edited at: 23rd May 2008 08:02
You have not said specifically what you are wanting to do.

I am not trying to be trite here; If you want to add Windows resources, then I can show you how those files work, but...

...if you want to add game assets, for example...that is not the way to do it; you'd open the text file, parse it, and create the assets yourself. There are many options in that case, as well, but Windows resources will not work, since Windows does not know about game assets per se, and Windows resources refers to things that Windows knows about, and uses itself. (Again, like menus, string tables, icons, bitmaps, version information, etc.)

In the file resource.h go the ID definitions of your resources. They are numbers that are used by your program and Windows to manage the assets. There is a naming convention at work already, but you are free to create your own, although I see no value in that. Let's start with strings as an example.

// resource.h
//
#define IDS_STRING101 101


//appname.rc
//
STRINGTABLE
BEGIN
IDS_STRING101 "This is my string."
END

Add them to the project in the Solution Explorer pane. Add resource.h by right clicking on the folder "Header Files". Add appname.rc by right clicking on the folder "Resource Files". In both cases...select "Add"/"Add Existing Item". They should be in the project folder, with the other files in the project.

Like other assets, strings have resource management functions dedicated to them. LoadString is the function that will load a string resource into a buffer that you supply.

That's enough to get you started in the offhand event that this is what you want to do, and not so much that I'll regret typing it up...again.

Personally, I think that VS is crippled without the resource editor. Adding assets is trivial, but dialogs and menus would be a pain to use that way, because they require access to the message handler, and GDK hides that by default...for good reason, it seems.
Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 23rd May 2008 13:25
Maybe resource file is not what I need to use.

This is specificaly what I want:

There is data stored in a text file. I want to open this text file, read and use the data, then close it. But I want to include this text file as part of my exe. My program is working ok, loading and using the data, but I wish for the data to be part of the exe.
Can I do this?

Thanks for your help.


The word "Gullible" cannot be found in any English Dictionary.
tneva82
16
Years of Service
User Offline
Joined: 7th May 2008
Location:
Posted: 23rd May 2008 14:13
Why don't you want it to be separate file? Would make altering program lot easier if data would be available in separate file. Then if you need to alter values you don't need to recompile whole thing again.
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 23rd May 2008 15:57
i think he does not want it as a seperate file to make sure no one can change it.

in that case, why not drop the text file idea and have it embedded as code directly ?
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 23rd May 2008 15:59
Jinzai, any tips how to include program version/author information as resources?

I have been searching a lot but I did not come across clean solutions yet, like the one where you tipped how to make your own icon. that was very simple and clean!
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 23rd May 2008 16:08
Frankly, if you just have a text file with data and want it in your EXE, than first learn how to include a string resource in your EXE, than use the text file as a "big" string resource and parse it in memory.

If security is your concern, just do some XOR'ing of the text file to give it a cheap excryption and forget resources altogether.

Many ways to skin this cat depending on your specific needs. More than one option for sure and a string resource should work if that's your requirement (embedding it).

Frankly... You could just embed it in your source code itself... as a long char Textfile[CharCount]; That's how I made a test image in my JGC lib, just wrote a tool to load a image, and save the Pixel values (DWORDS)... then hardcoded that in an array.. and when you init the lib, it reads the info into a memblock and makes an image from it. dbMakeImageFromMemblock etc.

Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 23rd May 2008 18:02
The text file is an encrypted mesh.
I did:
object->mesh->memblock->encrypt->save data to text file.
Now at runtime I do:
read text file->memblock->decrypt-mesh->object.
I did write the text file with 30 bytes per line and seperated by commas so I could just copy & paste direct to IDE and hard code an array like so:

Trouble is the data is 4mb long. I hit build, went for a bath, had my tea, watched some TV, came back and it was still compiling.

I'm probably just going to keep as seperate file for now.


The word "Gullible" cannot be found in any English Dictionary.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 23rd May 2008 18:15
makes sense.... but note, it it's in its OWN header file, you should only have to do that rarely... because when it compiles, there will be a MyBigText.obj made from your MyBigText.h file. (In theory)

So unless you "REBUILD", the compiler will only recompile source code you modified since the last "link" and will then just link the data.

Either way makes perfect sense - I hope this project works out as planned for you!

jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 23rd May 2008 18:20 Edited at: 24th May 2008 04:22
@Flashing Blade...that's what I suspected, but I wanted to be sure. In 16-bit windows, it was somewhat easier, although for the life of me I don't remember exactly how we did it. Probably the very best way to do it the way you want is with a specialized array. The STL has a class that GDK programmers should use : valarray. It might be the ticket for your situation. In the meantime, I can provide you with a utility to make your text file into a flat byte array, but I have a couple of questions. Is it comma-delimited bytes, or what? If it is, you can make a byte array, and use the address to access it any way that you want, but...iirc, a mesh has a header, and consists of floats and maybe also dwords, and depends on many things for its actual format. If you have simply saved the memblock as an encrypted series of bytes...I have a tool that will let you insert it into your data, and you can compile that once, which will take some time, but it will produce an object file that will simply be linked in thereafter. Do you want that?

@bjadams - My bad, you had asked me about that, and I've dropped the ball. Here is a more useful apology, from one of my projects. It goes into the .rc file and you can simply replace your info for mine (only the second strings in the VALUE portion need changes.):

Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 24th May 2008 12:50
Thanks for the input.

For now I'm just going to keep the file seperate - the data is encrypted and I don't think anyone is desperate enough to spend time trying to decrypt it just to steal my crappy media.

I think I need to study coding in c++ with vc2008 thoroughly. I may get myself a good book to take away with me on my holidays in August - a month of camping in France, which should give me ample reading time - hopefuly the wine won't put my brain to sleep.

Anyway thanks for help all.


The word "Gullible" cannot be found in any English Dictionary.
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 24th May 2008 16:44
Jinzai unfortunately I couldn't get the version info to show in the icon properties. I guess I'm too stupid!

Do you think I need to embed an icon with any special properties?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 24th May 2008 19:07
Quote: "I guess I'm too stupid!
"
Come on man... Don't be down on your self - this stuff can be thick!

jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 24th May 2008 22:35 Edited at: 24th May 2008 22:36
The icon version is a different matter. That is the program version. There are functions to get any type of resource out of the executable image, and into the program (Yes, I know..they are the same thing, but....), just like LoadIcon does. There's a function for each type of resource...even functions to get resources by type.

In the case of version information, they are string resources, and if you examine the resource, they look a lot like registry keys, don't they?

Unfortunately, my machine does not like VS2008 at all. I am having to learn alternative ways of modifying project settings because .NET is pretty messed up on my machine. Installing new things like VS2008 just makes matters worse until I get it sorted. I have traced it to the Forms Designer grid control, which is pretty much a database type connection for a drop list. Too much control for what it does, and...its broken, to boot. Great. Reinstalling VS fixes it until a try to edit the project settings, which sometimes just kills the thing...other times I can make the changes I need to make.

I will work on an application to use each resource type, and I will post it up when I am done. Hopefully, it will illustrate how to use them in working code. The help available for VS2008 is really horrible, and by default, it wants to go online. I think that it would help alot to run VS setup and install the full help file locally, and set the preference to use local help whenever possible.

There are two resource types that can be used for binary data:
RCDATA and a User-Defined one, too. I will include at least one of those for your use, if you decide later to do that. I think perhaps a textured mesh logo of some sort. That would make sense to attach to the executable in this way. It would be guranteed to be readily available, and also safe from casual pilfering.

Again, VS2008 does not want you editing resources in the IDE, but you can open the .rc file as a text file. It will eventually catch you red-handed and tell you that you are not supposed to edit them. So, I will edit them in VS2003, or in Notepad. I'd advise anyone that does not have a visual resource editor to use Notepad, or your favorite text editor. Just remember not to change the extensions, or you will break the file.
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 25th May 2008 07:47
yes I ended up installing all the help locally, it's simpler that way

Login to post a reply

Server time is: 2024-09-29 21:22:53
Your offset time is: 2024-09-29 21:22:53