Adding resources to application

Started by
3 comments, last by hydroo 16 years, 1 month ago
I wanted to add some binary data as a resource in my application. In windows I would use the following code:
#include <windows.h>
HANDLE hExe = GetModuleHandle(NULL);
HRSRC hRes = FindResource(hExe, MAKEINTRESOURCE(IDB_DATA), RT_RCDATA); 
HRSRC hDat = LoadResource(hExe, hRes);
The big problem is that requires windows.h. I can't find any information on loading attached resources in unix. I've successfully compiled my application and linked the resources in to it on my linux box, but I haven't a clue on how to load the data. Any help would be greatly appreciated!
Advertisement
I don't think it is customary to include data inside executable
programs on UNIX.

How did you link the resources into the binary? Are you using winelib or
some other cross platform API?

Thank you for your time,
Arrummzen
Quote:Original post by kimeko
I wanted to add some binary data as a resource in my application.

In windows I would use the following code:
#include <windows.h>HANDLE hExe = GetModuleHandle(NULL);HRSRC hRes = FindResource(hExe, MAKEINTRESOURCE(IDB_DATA), RT_RCDATA); HRSRC hDat = LoadResource(hExe, hRes);


The big problem is that requires windows.h. I can't find any information on loading attached resources in unix. I've successfully compiled my application and linked the resources in to it on my linux box, but I haven't a clue on how to load the data.

Any help would be greatly appreciated!


*NIX-like systems don't even share the same "executable" file format: a lot of them will use ELF, but others might use SOM, the old a.out or COFF, etc.

ELF is fairly common nowadays, even on non-*NIX systems (OpenVMS, Playstation, BeOS on x86, ...), but it isn't universal.

This page essentially explains how to embed a file in an ELF binary.

Hope this helps.

EDIT: link added.

[Edited by - let_bound on March 14, 2008 9:17:54 AM]
I know about the various formats different operating systems use, I was just told that I could add data to any executable using the .rc format, but that I'd need a different api for each operating system.

Thank you for the link on embedding a file in ELF, very useful.

I've read that I could append my binary to the end of most executable formats without it causing any problems. I think I might do that just so I don't want to worry about how the data is added and retrieved in my code.
QT is able to embed resources. (And it's cross-platform!)

It's pretty simple to use.
You add your files to the directory - point at them with an xml-config-file.
And point to the xml-config-file with your project file.

And inside the code you can use them easily via ":/images/bla.jpg" - special notation. I like it.

This topic is closed to new replies.

Advertisement