View unanswered posts | View active topics It is currently Sun Dec 21, 2014 9:30 pm



Reply to topic  [ 3 posts ] 
 Help - custom resources loading question. 
Author Message

Joined: Sat Apr 21, 2001 7:01 am
Posts: 53
Location: Lexington, MA, USA
Post Help - custom resources loading question.
You could call tmpfile(), which returns a FILE* pointer to a temporary file, and then write the buffer returned by your function to that temporary file. That function opens the file in "w+b" mode, i.e. binary read/write mode. When the file is closed via fclose() or your program terminates, the file is automatically deleted.


Sat Oct 26, 2002 9:06 pm
Profile ICQ
User avatar

Joined: Fri Oct 25, 2002 7:01 am
Posts: 16
Location: Canada
Post Help - custom resources loading question.
I am writing a computer game and wish to switch to "custom resources" from using external files. I got the following code to load a custom resource:

char* LoadCustomResource(int resID, HINSTANCE hinstance)
{
HRSRC hResInfo;
HGLOBAL hResource;

// first find the resource info block
if ((hResInfo = FindResource(hinstance,
MAKEINTRESOURCE(resID),
"TEXTFILE")) == NULL)
return(NULL);

// now get a handle to the resource
if ((hResource = LoadResource(hinstance, hResInfo)) == NULL)
return(NULL);

// finally get and return a pointer to the resource
return ((char*)LockResource(hResource));
}

The problem is some of my files - especially my "level" file types are quite complex. I already have a loader for it using a file pointer (FILE *fp). My understanding of external resources is that you have a big array of data and u know the size of the array from SizeofResource(hResource). This is quite different from my file pointer from which I can call fread and frwite and such...

Is there some way I can get a "filename" of my custom resource and handle it exactly as a file so I dont have to rewrite my complex loaders? Any help or thoughts would be appreciated.

Check out my project:
web page


Sun Oct 27, 2002 6:57 am
Profile ICQ
User avatar

Joined: Fri Oct 25, 2002 7:01 am
Posts: 16
Location: Canada
Post Help - custom resources loading question.
Thanks Aprosenf. I didnt know about this stuff.. actually some of my interfaces use the name of a file (char *) and some used file pointer... so I use tmpnam() to generate random file names... write out my resource ... process the new temp file with my old loaders.. then close the file. Works great! Thank man!


Mon Oct 28, 2002 10:25 pm
Profile ICQ
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.