user1433205
user1433205

Reputation: 33

DLL resource (png) to SDL_Surface

I have a function to get a SDL_Surface to an openGL texture, but I seem to be stuck at loading the image from a dll. I can load a DLL, im just confused as to how I would go about getting the image out of it, and creating a SDL surface out of it.

Upvotes: 2

Views: 204

Answers (1)

Viktor Latypov
Viktor Latypov

Reputation: 14467

On Windows it is possible to get the raw pointer to the resources located in DLL. The FindResource/LoadResource/LockResource functions do the job.

Use the following code to get the pointer to resource ResourceID (look for it in the .rc file) and of type ResourceType (BITMAP in your case):

HMODULE Handle = /// GetModuleHandle( NULL or .dll handle here);  - for current .exe file or .dll

HRSRC hResInfo;
HGLOBAL hResource;

// first find the resource info block
if ( ( hResInfo = ::FindResource( Handle, MAKEINTRESOURCE(ResourceID), ResourceType ) ) == NULL )
{
    return( NULL );
}

// determine resource size
int BufSize = SizeofResource( Handle, hResInfo );

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

// finally get and return a pointer to the resource
void* BufPtr = LockResource( hResource );

    /// Do whatever you need with BufSize/BufPtr

Upvotes: 1

Related Questions