2
votes

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.

1
How do you get an image into a DLL? DLLs usually contain source code, not images. - Nicol Bolas
Windows executables and DLLs also contain resources which can be accessed as raw memory blocks using the LockResource API. - Viktor Latypov

1 Answers

1
votes

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