Solved

Pass Bitmap from VB to VC++

Posted on 2002-04-28
8
309 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
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.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web browser fonts have gone wild. 8 118
Should CArray be used for a list of pointers in C++? 19 102
gdb doesn't stop on breakpoint 2 67
c++, dynamic object by json 1 41
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

815 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

12 Experts available now in Live!

Get 1:1 Help Now