Link to home
Start Free TrialLog in
Avatar of gunn
gunn

asked on

Creating/Using a Cbitmap from a resource only DLL

Using MSVC++ 5.0, Windows95

I created a Resource Only DLL following the instructions in the online help (pretty easy). I have a bitmap in that DLL called "IDB_P38_1024".

In my application, I load the DLL and I get a valid handle back. I then try to load the bitmap with LoadBitmap(), but the handle comes back NULL. I call GetLastError() and it returns 120, which means that this function is not supported on the platform. Huh??!  Here is the code I am trying to use:


      DWORD err;

      HINSTANCE h_library = LoadLibrary( "GSviews.dll" );

      HBITMAP h_p38_1024 = LoadBitmap( h_library, "IDB_P38_1024" );
 
      if( h_p38_1024 == NULL )
      {
            err = GetLastError();
      }

      CBitmap m_Bitmap_P38_1024.FromHandle( h_p38_1024 );

At the end here, I want to attach the HBITMAP handle I got from the DLL (when I get it to work) to a CBitmap object so I can manipulate it the way I have been (I used to have the bitmap right with the application). Is this the way to do it right? It was the only function I could find that used HBITMAP and CBitmap together ;)

Thanks,

Tom
ASKER CERTIFIED SOLUTION
Avatar of Tommy Hui
Tommy Hui

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gunn
gunn

ASKER

Ok, thanks a lot; I looked in resource.h for the DLL and found that there was a #define IDB_P38_1024 101 , so I used 101 with your code and that did it.

Now though, what about the end of my question? Is using .FromHandle( h_P38_1024 ) the way to get a CBitmap object from the handle ?

Thanks again.
Tom

Avatar of gunn

ASKER

I think I figured it out. I used the member function .Attach() to attach the handle to a CBitmap object. Seems to work.

Tom