Loading Bitmap image from ATL COM dll to MFC Client

Posted on 2006-06-02
Last Modified: 2013-12-14
Dear Experts,

We have a ATL COM dll which populates its control over remote MFC Client.
MFC Client passes RemoteHandle to COM dll for this job.

Now we have to load a bitmap image from dll over the dialog of MFC Client.
We have tried to it  in OnPaint handler of dll but loading bitmap  by LoadBitmap api requires Handle to the instance of the module whose executable file contains the bitmap to be loaded which i think is not possible to retreive.

Kindly let us know how can we do it.
Question by:HanuSoftware
    LVL 86

    Expert Comment

    >>loading bitmap  by LoadBitmap api requires Handle to the instance of the module whose executable file
    >>contains the bitmap

    Not a big deal, just use

    HINSTANCE hInst = GetModuleHandle("AtlComDll.dll");

    LVL 86

    Accepted Solution

    Sorry, that should be either



    LVL 8

    Assisted Solution

    You could:

    1. pack this bitmap in DLL into VARIANT structure and pass it as binary to client if you need OLE Automation

    BITMAPINFO (if any palette entries follows)
    bitmap bits

    IYourInterface::GetBitmapMethod([out] VARIANT *pvBitmap)

    2. turn bitmap into header & bitmap bits and pass it directly to client through (local or non-local) custom interface (no OLE automation)

    IYourInterface::GetBitmapMethod([out] LPBITMAPINFO *pbih, [out] BYTE *pbtBitmap)

    I think that above is a little bit more correct from COM point of view
    LVL 8

    Expert Comment

    Sorry it should be

    IYourInterface::GetBitmapMethod([out] LPBITMAPINFO **pbih, [out] BYTE **pbtBitmap)
    LVL 86

    Expert Comment

    Why would one pass the bitmap via a function call if you can just load it??
    LVL 8

    Expert Comment

    "Why would one pass the bitmap via a function call if you can just load it?"

    1. To follow COM rules (bending them a little if necessary).
    Accessing COM object through properties & methods.

    Alternatively HBITMAP handler could be passed as a method parameter (can be only used as local object).

    IYourInterface::GetBitmap([out] HBITMAP *phBmp)
       // _Module.m_hInstance - DLL instance handle kwown to COM object in ATL

    2. From COM point of view implementing DLL is hidden - there's only CLSID & object instance and no COM method of knowing DLL or instance handle.

    LVL 86

    Expert Comment

    You have a point there, but I'd rather pass the module name to keep that transparent, but not the whole resource.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
    For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now