Solved

Creating/Using a Cbitmap from a resource only DLL

Posted on 1998-02-06
3
307 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:gunn
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 70 total points
ID: 1315698
Are you absolutely sure that the name of the resource is a string called IDB_P38_1024? My guess is that there is a resource identifier with that name but it really is a number. Then in that case, you should use

  LoadBitmap(h_library, MAKEINTRESOURCE(number));


0
 

Author Comment

by:gunn
ID: 1315699
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

0
 

Author Comment

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

Tom
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question