Loading from File Resources

BlitzPlus Forums/BlitzPlus Programming/Loading from File Resources

Seldon(Posted 2003) [#1]
This is just an idea, since I haven't Blitz+ to try. I was wondering if someone tried to load an image (for example) from the .EXE resources. I think if you create an image (CreateImage) , got its bank-buffer (I think you need LockPixels command) , then you can use Win32 API calls to load an image from resources and storing it in the bank-buffer. Of course you need a program like ResHacker to add a resource to the final B+ .EXE . IF someone wants to try I can send the Win32 API commands to read a file from resource (I did in C and it works fine).


soja(Posted 2003) [#2]
Sure, go ahead and post them.


Seldon(Posted 2003) [#3]
static LPVOID lpData;
static HRSRC hr;
static HGLOBAL hg; //Gestione risorse

hr=FindResource(NULL,MAKEINTRESOURCE(249),RT_RCDATA);
if(hr)
{
hg=LoadResource(NULL,hr);
if(hg)
{
lpData=LockResource(hg);
if(lpData)
{
//lpData is the buffer where the resource data is
//stored.
}
}
}

Ok, this is the C part you should make in Blitz using the right userlibs definitions, etc.. LpData should be the buffer pointer returned by LockPixels() (I think) and of course you have to create an image before (CreateImage() ).

[...]

Then we have the Resource script to be compiled (using
the RC command).

249 RCDATA
BEGIN
#include "YourPicture.txt"
END

To make the "picture.txt" , first you must write a file with the raw data of a Blitz's Image buffer. Then you use a program called bin2txt (if you need I can send it) to produce a suitable .txt file to be included. Once you have such file, use the RC (resource compiler by Microsoft) to make a YourProgram.RES file. Run ResHacker and attach it to your Blitz .EXE .

It should work.. it's a bit of work (the DATA statement could also be used instead of resource, but it's a nightmare to have thousandd of DATA lines in your source).

Anyway... let me know. :-)