Solved

Pass Bitmap from VB to VC++

Posted on 2002-04-28
8
315 Views
Last Modified: 2013-12-03
Hi,

I've written an MFC ActiveX control.

I want to be able to pass a bitmap into this control.

What is the 'type' of the property I need to create in order to receive the bitmap ??

I've tried creating an LPDISPATCH property, and put the following...

CBitmap MyBMP;
MyBMP=(CBitmap)m_bitmapfromvb;

But the compiler says that it can't translate from one to the other. )-:

Smg.
0
Comment
Question by:smegghead
  • 4
  • 2
  • 2
8 Comments
 
LVL 10

Author Comment

by:smegghead
ID: 6974878
Sorry, forgot to mention, the bitmap is coming from VB.
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 6975333
When you say the bitmap is coming from VB, what format is it in VB and how are you trying to pass it?  Is it an array of bytes or is it a COM object supporting IPicture (like a StdPicture or the Image property of an Image Control or a PictureBox) or is it a handle to a bitmap?
0
 
LVL 10

Author Comment

by:smegghead
ID: 6976504
Hi,

Probably either using LoadPicture or LoadResPicture.

But if there's a different way, which makes it easier to pass into VC++ then I'm quite flexible on that.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:DrDelphi
ID: 6977034
I'm fairly sure that you'll have to use IPictureDisp. At least my experience sending bitmap from my Delphi/BCB libaries to VB has always entailed using it.I've no reason to believe that it would be any different going the other way.




Good luck!!
0
 
LVL 10

Author Comment

by:smegghead
ID: 6977262
OK, but do you know what OLE type I should be expecting in the C++ program ?? should I use LPUKNOWN or LPDISPATCH ?? (just a guess)
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6977585
LPUNKNOWN. Again, to the best of my knowledge and experience.


Good luck!!
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 50 total points
ID: 6977896
The following works for me with ATL.  I don't know MFC so probably can't help much with creating a CBitmap from an IPictureDisp.

C++ code--

STDMETHODIMP CTesting::DrawImage(LPDISPATCH image)
{

   IPicture* picture;

   if (SUCCEEDED(image->QueryInterface(IID_IPicture, reinterpret_cast<void**>(&picture))))
   {
      HDC hdc = GetDC(NULL);

      OLE_YSIZE_HIMETRIC height;
      OLE_XSIZE_HIMETRIC width;


      picture->get_Height(&height);
      picture->get_Width(&width);

      picture->Render(hdc, 1, 1, 100, 100, 0, 0, width, height, NULL);
         
      picture->Release();

      ReleaseDC(NULL, hdc);
   }

   return S_OK;
}


VB code --

Sub TESTING()

    Dim myATL As Object
    Dim myPic As StdPicture
   
    Set myATL = CreateObject("VBPIC.TESTING")
    Set myPic = LoadPicture("c:\testing123.bmp")
    myATL.drawimage myPic
   
End Sub
0
 
LVL 10

Author Comment

by:smegghead
ID: 6980010
Hi,

I was being stupid... there is actually a parameter type called LPPICTUREDISP.

This accepts the return value from a LoadPicture, or LoadResPicture in VB.

Once in C++ it is coded as follows...

CPictureHolder MyPic;
MyPic.SetPictureDispatch(InPicture);

Where InPicture is of type LPPICTUREDISP.

So, it's all sorted.

I will give these points to clockwatcher, as he/she gave some other useful advice.

Thanks all
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

821 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