Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

Pass Bitmap from VB to VC++

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
smegghead
Asked:
smegghead
  • 4
  • 2
  • 2
1 Solution
 
smeggheadAuthor Commented:
Sorry, forgot to mention, the bitmap is coming from VB.
0
 
clockwatcherCommented:
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
 
smeggheadAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
DrDelphiCommented:
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
 
smeggheadAuthor Commented:
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
 
DrDelphiCommented:
LPUNKNOWN. Again, to the best of my knowledge and experience.


Good luck!!
0
 
clockwatcherCommented:
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
 
smeggheadAuthor Commented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now