Results 1 to 9 of 9

Thread: Querying an image control for the IPicture Interface

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Querying an image control for the IPicture Interface

    Hi,

    Can anybody tell me what I am doing wrong ,

    The following code is supposed to give me pointer to the IPicture interface from an Image control in my userform but fails ...

    BTW, i am using the low level DispCallFunc api in the vtblCall routine .

    I have also tried getting the IPictureDisp interface but without any luck.



    Code:
    Sub Test()
    
        Const CC_STDCALL As Long = 4
        Const S_OK As Long = 0
        Const IUnknownQueryInterface = 0
        Const IUnknownRelease = 8
        Const IPicture_interface = "{7bf80980-bf32-101a-8bbb-00aa00300cab}" 'IPicture uuid
        'Const IPictureDisp_interface = "{7bf80981-bf32-101a-8bbb-00aa00300cab}" ' IPictureDisp uuid
    
        Dim uGUID(0 To 3) As Long
        Dim pUnk As Long, pPicInterFace As Long
        
    
        If IIDFromString(StrPtr(IPicture_interface), VarPtr(uGUID(0))) = S_OK Then
            pUnk = ObjPtr(Me.Image1)
            If vtblCall(pUnk, IUnknownQueryInterface, vbLong, CC_STDCALL, VarPtr(uGUID(0)), VarPtr(pPicInterFace)) = S_OK Then
                MsgBox pPicInterFace  '<== code never reaches this point !!
                vtblCall pPicInterFace, IUnknownRelease, vbLong, CC_STDCALL
            End If
        End If
     
    End Sub
    I get -2147467262 "No such interface supported" however, I know the Image control DOES implement the IPicture interface ... I am confused !
    Last edited by JAAFAR; Mar 3rd, 2021 at 05:07 AM.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Querying an image control for the IPicture Interface

    Controls don't normally implement this sort of interface. Typically many expose an internal StdPicture object reference as a property. Such objects themselves implement IPicture and IPictureDisp interfaces.

    So you are querying the wrong object.

    Using Office VBA and MS Forms 2.0 has its limitations.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: Querying an image control for the IPicture Interface

    Quote Originally Posted by dilettante View Post
    Controls don't normally implement this sort of interface. Typically many expose an internal StdPicture object reference as a property. Such objects themselves implement IPicture and IPictureDisp interfaces.

    So you are querying the wrong object.

    Using Office VBA and MS Forms 2.0 has its limitations.

    I see ... I should have queried the actual Picture Property like :
    pUnk = ObjPtr(Me.Image1.Picture)

    Thanks.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,943

    Re: Querying an image control for the IPicture Interface

    Is this VBA?
    My usual boring signature: Nothing

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Querying an image control for the IPicture Interface

    In VB6 all you have to do is:

    Code:
        Dim IPicture As stdole.IPicture
    
        Set IPicture = Image1.Picture
    QueryInterface is built-in, part of data type coercion.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: Querying an image control for the IPicture Interface

    Quote Originally Posted by dilettante View Post
    In VB6 all you have to do is:

    Code:
        Dim IPicture As stdole.IPicture
    
        Set IPicture = Image1.Picture
    QueryInterface is built-in, part of data type coercion.
    I know. BTW, I can do The same in vba ... Just wanted to experiment a bit with the low level DispCallFunc api to achieve the same.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: Querying an image control for the IPicture Interface

    Quote Originally Posted by Shaggy Hiker View Post
    Is this VBA?
    Yes vba.... but, it is an API based question which applies to vba and vb6 in the same fashion.

    Posting these types of questions in the vba forum will very likely remain unanswered.

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Querying an image control for the IPicture Interface

    Quote Originally Posted by JAAFAR View Post
    Posting these types of questions in the vba forum will very likely remain unanswered.
    Good point. For even more eyeballs I suggest you spam the VB.Net forum too.

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,943

    Re: Querying an image control for the IPicture Interface

    If some sub-forum is not frequented, it is largely because people don't post there. Naturally, that's a self-fulfilling feedback loop. If people are posting incorrectly because there are fewer posts in some sub-forum, then there are fewer posts in that sub-forum and fewer people will visit there, and so on until everything runs down to just VB.NET, Classic, and Chit-Chat, all of which are packed with misplaced threads. Therefore, we move threads to where they belong, but leave a link for a time.
    My usual boring signature: Nothing

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