views:

19

answers:

1

Hi all,

I have a case where I need to load bitmap from a resource dll and release handle to it. The update mechanism may update the dll, and having it open will fail overwriting it.

So lets say I have something like this:

HINSTANCE hInst = LoadLibraryEx(resourceDll, NULL, LOAD_LIBRARY_AS_DATAFILE);
HBITMAP hBitmap = LoadBitmap(hInst, "some.bmp")
FreeLibrary(hInst);

is it valid to use hBitmap after calling FreeLibrary ?

Thanks in advance.

A: 

Yes, it's valid to release the DLL.

LoadBitmap does the equivalent of CreateCompatibleBitmap, which creates a new bitmap for your process. The bitmap image is initialized with the data from the DLLs resource. That is, the pixel information is copied to the bitmap. The bitmap does not hold a pointer to the resource data. Once created, you can release the DLL.

Adrian McCarthy
Thank a lot Adrian, will try it.What made me think it's not valid is what is written here: http://msdn.microsoft.com/en-us/library/ms648006(VS.85).aspxEspecially " After an application loads a resource by using LoadResource, the system will unload the associated memory only when all references to its module are freed through **FreeLibrary**"
Jack Juiceson