Results 1 to 7 of 7

Thread: How do I use OleCreatePictureIndirect?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    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.

  2. #2
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    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

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: How do I use OleCreatePictureIndirect?

    An hBitmap is not a DIB, its a DDB.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: How do I use OleCreatePictureIndirect?

    Quote Originally Posted by digitalShaman View Post
    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.

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: How do I use OleCreatePictureIndirect?

    Quote Originally Posted by Ben321 View Post
    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: How do I use OleCreatePictureIndirect?

    Quote Originally Posted by Niya View Post
    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?

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: How do I use OleCreatePictureIndirect?

    Quote Originally Posted by Ben321 View Post
    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width