Solved

Pass Bitmap from VB to VC++

Posted on 2002-04-28
8
302 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

708 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

15 Experts available now in Live!

Get 1:1 Help Now