-
Mar 2nd, 2021, 09:56 PM
#1
Thread Starter
Fanatic Member
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.
-
Mar 3rd, 2021, 12:52 AM
#2
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.
-
Mar 3rd, 2021, 05:12 AM
#3
Thread Starter
Fanatic Member
Re: Querying an image control for the IPicture Interface
Originally Posted by dilettante
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.
-
Mar 3rd, 2021, 10:17 AM
#4
Re: Querying an image control for the IPicture Interface
My usual boring signature: Nothing
-
Mar 3rd, 2021, 10:19 AM
#5
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.
-
Mar 3rd, 2021, 10:39 AM
#6
Thread Starter
Fanatic Member
Re: Querying an image control for the IPicture Interface
Originally Posted by dilettante
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.
-
Mar 3rd, 2021, 10:42 AM
#7
Thread Starter
Fanatic Member
Re: Querying an image control for the IPicture Interface
Originally Posted by Shaggy Hiker
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.
-
Mar 3rd, 2021, 11:05 AM
#8
Re: Querying an image control for the IPicture Interface
Originally Posted by JAAFAR
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.
-
Mar 3rd, 2021, 12:16 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|