Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7160329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:22:53+00:00 2026-05-28T13:22:53+00:00

I’m trying to get a System.Drawing.Image (generated in a .NET dll) into a picture

  • 0

I’m trying to get a System.Drawing.Image (generated in a .NET dll) into a picture control in a Visual C++/MFC application. I’m new to COM/Interop, but I have interop’ing working. However I’m not sure how to pass the bitmap data from C# to C++.

The basic process is:
1. C++/MFC calls on COM server (interop)
2. C# COM server calls .NET DLL
3. Generate System.Drawing.Image in .NET dll
4. C# COM server returns bitmap data in some form (interop)
5. C++/MFC displays bitmap

In the C# COM Server, I have:

Bitmap bm = new Bitmap(img);
IntPtr hbm = bm.GetHbitmap();
return hbm;

Where img is the System.Drawing.Image I want to send over. The method returns an IntPtr, which gets marshaled to a long*

In my MFC C++ Test application, I have:

long pOutHB;

pQRCodePtr->Generate(m_sQRText.AllocSysString(), 50, 50, &pOutHB);

HBITMAP hb = (HBITMAP) pOutHB;
m_QRCodePicture.SetBitmap(hb);
m_QRCodePicture.Invalidate();
m_QRCodePicture.UpdateData();

But nothing gets put in the picture control. I also tried creating a CBitmap using the HBITMAP, but that was unsuccessful as well. I have verified the .NET dll/COM server is generating a valid image.

Most of my research on this issue uncovered taking a C++ bitmap and making a System.Drawing.Image, not going the other direction (like this question:
Safety of passing HBITMAP handle from unmanaged to managed code for created a System.Drawing.Bitmap)

Am I going down the right path here? I realize that my code may be completely wrong. I’m looking for something to point me in the right direction here. My first try was to pass a byte[] array, but some reading pointed me in the direction of passing the HBitmap pointer as being more efficient.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:22:54+00:00Added an answer on May 28, 2026 at 1:22 pm

    For future reference, it turns out I was doing it correctly. The HBITMAP handle is valid and persists even after the return from the .NET function and pass through COM interop. According to MSDN, you need to cleanup the object.

    Adding some cleanup, this works. Generate is a call to the COM wrapper service which returns an IntPtr which is marshaled to a long.

    long pOutHB;
    
    pQRCodePtr->Generate(m_sQRText.AllocSysString(), 200, 200, &pOutHB);
    
    HBITMAP hb1 = (HBITMAP) pOutHB;
    
    HBITMAP oldHB = m_QRCodePicture.SetBitmap(hb1);
    if (oldHB)
    {
        DeleteObject(oldHB);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.