I am working on a DLL which contains a bitmap resource. I imported that bitmap through the Resource View in Visual Studio. The DLL also exports a class which has a function that tries to load the bitmap:
BOOL CMyExportedClass::Create(CWnd* pParentWnd /*= NULL*/)
{
if (!m_bitmap.LoadBitmap(IDB_BITMAP1))
return FALSE;
// ...
}
From an MFC application I load the DLL. Inside the applications InitInstance()
function I then invoke an exported function of the DLL which eventually calls CMyExportedClass::Create()
.
However, LoadBitmap()
always returns 0
, which according to the documentation indicates either insufficient memory (not the case) or that the resource does not exist.
The bitmap file is part of my DLL project and IDB_BITMAP1
is defined in the .rc file as well as in resource.h:
MyDLL.rc:
IDB_BITMAP1 BITMAP "res\\mybitmap.bmp"
resource.h:
#define IDB_BITMAP1 1034
I already checked that the ID has been defined only once. FWIW: At the time LoadBitmap()
is invoked, the DLLs InitiInstance()
function has already returned successfully.
What are possible reasons why LoadBitmap()
refuses to load the resource and how can I fix this?
Edit:
I can successfully load the resource if instead of
m_bitmap.LoadBitmap(IDB_BITMAP1)
I do the following:
HBITMAP hBitmap = (HBITMAP)LoadImage(hCurrentModule, MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 0, 0, 0);
if(hBitmap)
m_bitmap.Attach((HBITMAP)hBitmap);
So what's the difference between CBitmap::LoadBitmap()
and the LoadImage()
functions here?