-
Jul 13th, 2014, 11:35 PM
#1
Thread Starter
Frenzied Member
How do I use OleCreatePictureIndirect?
I've heard that it can create an StdPicture or IPictureDisp object, when given the handle to a Bitmap. Unfortunately I don't have the slightest clue how to use this API call. It sounds like it could be a very powerful tool in graphics programming, but I don't have the slightest clue how to use it. It would be very helpful if someone would show me how to use it. I'm using VB6, so please don't give any code samples for VB.net or newer.
The MS description of the parameters is very cryptic:
lpPictDesc [in]
Pointer to a caller-allocated structure containing the initial state of the picture. The specified structure can be NULL to create an uninitialized object, in the event the picture needs to initialize via IPersistStream::Load.
riid [in]
Reference to the identifier of the interface describing the type of interface pointer to return in lplpvObj.
fOwn [in]
If TRUE, the picture object is to destroy its picture when the object is destroyed. If FALSE, the caller is responsible for destroying the picture.
lplpvObj [out]
Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, this parameter contains the requested interface pointer on the newly created object. If the call is successful, the caller is responsible for calling Release through this interface pointer when the new object is no longer needed. If the call fails, the value is set to NULL.
The only parameter I understand is the fOwn parameter. If I set it to FALSE, I'll have to separately destroy the Bitmap object with the DeleteObject API call. If I set it to TRUE, the Bitmap object will completely part of the StdPicture object created, and will therefore be destroyed when I use
Code:
Set MyStdPic = Nothing
to destroy my StdPicture object.
The other parameters I don't know about. I don't even know how to send the output of this API call to a given StdPicture object (such as MyStdPic in the above example code).
Please help me out here.
Thanks in advance.
-
Jul 20th, 2014, 05:11 AM
#2
Re: How do I use OleCreatePictureIndirect?
here is an example:
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" _
(PicDesc As PICTDESC, RefIID As GUID, _
ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Type PICTDESC
cbSizeofStruct As Long
picType As Long
hImage As Long
xExt As Long
yExt As Long
End Type
Public Function DibToPicture(HandleDIB As Long) As StdPicture
'Converts a DIB into a StdPicture.
'Note that no DeleteObject is required for the inputed hDib after conversion.
Dim vIDispatch As GUID
Dim vPic As PICTDESC
With vIDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
With vPic
.cbSizeofStruct = Len(vPic)
.picType = vbPicTypeBitmap
.hImage = HandleDIB
End With
Call OleCreatePictureIndirect(vPic, vIDispatch, 1, DibToPicture) ' Convert image to OLE picture
End Function
-
Jul 24th, 2014, 06:57 AM
#3
Re: How do I use OleCreatePictureIndirect?
An hBitmap is not a DIB, its a DDB.
-
Jan 10th, 2017, 02:37 PM
#4
Thread Starter
Frenzied Member
Re: How do I use OleCreatePictureIndirect?
Originally Posted by digitalShaman
here is an example:
I have a question about the GUID you used with OleCreatePictureIndirect in the example you gave. You used {00020400-0000-0000-C000-000000000046}. That's the Interface ID for IDispatch (I looked it up in the registery using RegEdit). Why did you use that CLSID? That has nothing to do with images. Why didn't you instead use IPicture {7BF80980-BF32-101A-8BBB-00AA00300CAB}, or IPictureDisp {7BF80981-BF32-101A-8BBB-00AA00300CAB}?
Last edited by Ben321; Jan 10th, 2017 at 04:05 PM.
-
Jan 11th, 2017, 11:36 AM
#5
Re: How do I use OleCreatePictureIndirect?
Originally Posted by Ben321
I have a question about the GUID you used with OleCreatePictureIndirect in the example you gave. You used {00020400-0000-0000-C000-000000000046}. That's the Interface ID for IDispatch (I looked it up in the registery using RegEdit). Why did you use that CLSID? That has nothing to do with images. Why didn't you instead use IPicture {7BF80980-BF32-101A-8BBB-00AA00300CAB}, or IPictureDisp {7BF80981-BF32-101A-8BBB-00AA00300CAB}?
Been a while since I digged around in COM but if I remember correctly, many COM interfaces are derived from IDispatch. Similar to how all COM interfaces are derived from IUknown. The StdPicture class implements the IPicture interface which derives from IDispatch.
-
Jan 11th, 2017, 03:47 PM
#6
Thread Starter
Frenzied Member
Re: How do I use OleCreatePictureIndirect?
Originally Posted by Niya
Been a while since I digged around in COM but if I remember correctly, many COM interfaces are derived from IDispatch. Similar to how all COM interfaces are derived from IUknown. The StdPicture class implements the IPicture interface which derives from IDispatch.
So, does that mean that it's required to use IDispatch, instead of IPicture or IPictureDisp, when creating an StdPicture object?
Since IUnknown is the base of all of those, would it be even better to use IUnknown for this?
-
Jan 14th, 2017, 05:48 PM
#7
Re: How do I use OleCreatePictureIndirect?
Originally Posted by Ben321
So, does that mean that it's required to use IDispatch, instead of IPicture or IPictureDisp, when creating an StdPicture object?
Since IUnknown is the base of all of those, would it be even better to use IUnknown for this?
I get the impression that they used IDispatch since they are interested in it's members for the purposes of that code. OleCreatePictureIndirect seems to want something from IDispatch, not IUnknown or IPicture. Doesn't mean that those interfaces won't work. They are after all, just interfaces and don't change what the actual object is but it does make the code clearer and more to the point.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|