views:

863

answers:

3

I have a C++ DLL including bitmap resources created by Visual Studio.

Though I can load the DLL in VB6 using LoadLibrary, I cannot load the image resources either by using LoadImage or by using LoadBitmap. When I try to get the error using GetLastError(), it doesnot return any errors.

I have tried using LoadImage and LoadBitmap in another C++ program with the same DLL and they work without any problems.

Is there any other way of accessing the resource bitmaps in C++ DLLs using VB6?

A: 

You've got the right idea. You probably have the call wrong. Perhaps you could show a bit of code as I can't guess as to what you're passing.

Joel Lucsy
A: 

In VB6:

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long

Private Declare Function LoadBitmap Lib "user32" Alias "LoadBitmapA" (ByVal hInstance As Long, ByVal lpBitmapName As String) As Long

DLLHandle = LoadLibrary("Mydll.dll")

myimage = LoadBitmap(DLLHandle, "101")

comes with myimage as 0 even though DLLHandle is nonzero,However, in C++:

imagehandle = LoadBitmap(DLLHandle,LPCSTR(101));

works!

Thanks a lot

+1  A: 

Since you are using the numeric ID of the bitmap as a string, you have to add a "#" in front of it:

DLLHandle = LoadLibrary("Mydll.dll")
myimage = LoadBitmap(DLLHandle, "#101")  ' note the "#"

In C++ you could also use the MAKEINTRESOURCE macro, which is simply a cast to LPCTSTR:

imagehandle = LoadBitmap(DLLHandle, MAKEINTRESOURCE(101));
efotinis