PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

loading picture from resource

Why loading of a picture from resources does not work.
Code:

HINSTANCE hModule = GetModuleHandle(0);
E2DSurface sprite;


HRSRC hResource = FindResource( hModule, MAKEINTRESOURCE(IDB_BITMAP1), RT_BITMAP );
if (hResource)
{
DWORD size = SizeofResource( hModule, hResource );
HGLOBAL hMemory = LoadResource( hModule, hResource );
char* dataF = (char*)LockResource( hMemory );
if (display->CreateSurface(&sprite;, dataF,size ) != E_OK)
return(E_ERROR);
}


Please help.
Thanks.
Hi Relo,

Can you tell me where it goes wrong? What is the return value of CreateSurface?
if this:
rs=display->CreateSurface(&sprite;, hMemory, size );

E_UNSUPPORTED 3
if this:
char* dataF = (char*)LockResource( hMemory );
rs=display->CreateSurface(&sprite;, dataF,size )

E_NOTEXISTS 7
And dataF specifies on given, where the first byte "(" really should on "BM.... "
(format image BMP)
All has understood. If picture GIF, JPG and in a resource to be stored as simply given such code works:
Code:
HINSTANCE hModule = GetModuleHandle(NULL);
HRSRC hResource = FindResource( hModule , MAKEINTRESOURCE(IDR_HHH1),TEXT("HHH") ); //RT_BITMAP
if (hResource)
{
DWORD size = SizeofResource( hModule, hResource );
HGLOBAL hMemory = LoadResource( hModule, hResource );
rs=display->CreateSurface(&sprite;, hMemory, size );
}

If a picture in resources BMP, most likely it is necessary to use LoadBitmap.
Thanks.
Hi Relo,

Can you confirm that loading PNG and GIF files work, but BMP files don't? If it is, then you can probably load bitmaps by adding them to the "HHH" group, instead of bitmap.

We recommend loading PNG files anyway to reduce the size of your executable.
Thanks. Yes so probably will work too.