-
Feb 5th, 2025, 04:39 PM
#1
Thread Starter
Fanatic Member
ConnectToConnectionPoint shlwapi.dll API on Win11?
Im trying to get someting out of the ConnectToConnectionPoint API and I checked old examples but when I try it I always got the Com Error E_NOINTERFACE = &H80004002 so is it out of date?
Code:
Public Declare Function ConnectToConnectionPoint Lib "shlwapi" Alias "#168" (ByVal punk As Long, riidEvent As Any, _
ByVal fConnect As Long, ByVal pUnkTarget As Long, ByRef pdwCookie As Long, Optional ByVal ppcpOut As Long) As Long
Private Sub Command6_Click()
Dim pICP As IConnectionPoint
Dim ppICP As Long
Dim hr As Long
Dim dwCookie As Long
hr = ConnectToConnectionPoint(ObjPtr(Me), IID_IDispatch, 1, ObjPtr(Picture1), dwCookie, ppICP)
MsgBox Hex(hr)
End Sub
-
Feb 6th, 2025, 04:08 AM
#2
Re: ConnectToConnectionPoint shlwapi.dll API on Win11?
I only know this in connection with corresponding event sink interfaces. For example, if you want to connect the interface IFileSystemImage with the event sink interface DFileSystemImageEvents <- IConnectionPoint::Advise. According to my understanding, the API should not do anything other than Interface.QueryInterface(IID_IConnectionPointContainer) -> IConnectionPointContainer.FindConnectionPoint(IID_Interface) -> IConnectionPoint.Advise/Unadvise
Last edited by -Franky-; Feb 6th, 2025 at 04:21 AM.
-
Feb 6th, 2025, 08:30 AM
#3
Thread Starter
Fanatic Member
Re: ConnectToConnectionPoint shlwapi.dll API on Win11?
But before that step I need to get an instance of IConnectionPoint which this API shall provide with but as I wrote in #1 I only gets E_NOINTERFACE error.
-
Feb 6th, 2025, 09:27 AM
#4
Re: ConnectToConnectionPoint shlwapi.dll API on Win11?
PictureBox raises PictureBoxEvents so you need IID_PictureBoxEvents *and* you'll need to implement this interface on your target instance i.e. you'll need IPictureBoxEvents declared (in impl compatible way) in a typelib.
cheers,
</wqw>
-
Feb 6th, 2025, 01:15 PM
#5
Re: ConnectToConnectionPoint shlwapi.dll API on Win11?
 Originally Posted by nebeln
But before that step I need to get an instance of IConnectionPoint which this API shall provide with but as I wrote in #1 I only gets E_NOINTERFACE error.
wqweto gave you the right hint. But you don't have to call IConnectionPoint.Advise/Unadvise yourself. The API ConnectToConnectionPoint does that for you via the parameter fConnect.
-
Feb 6th, 2025, 03:32 PM
#6
Thread Starter
Fanatic Member
Re: ConnectToConnectionPoint shlwapi.dll API on Win11?
 Originally Posted by wqweto
PictureBox raises PictureBoxEvents so you need IID_PictureBoxEvents *and* you'll need to implement this interface on your target instance i.e. you'll need IPictureBoxEvents declared (in impl compatible way) in a typelib.
cheers,
</wqw>
I downloaded msvbvm60_3.tlb from the link you provided but I can't use it - Can't add reference to that specified file.
-
Feb 6th, 2025, 06:07 PM
#7
Re: ConnectToConnectionPoint shlwapi.dll API on Win11?
If you want to handle the events of some objects, you can use a generic solution for late binding processing. I don't think you can solve this problem directly.
-
Feb 6th, 2025, 06:22 PM
#8
Thread Starter
Fanatic Member
Re: ConnectToConnectionPoint shlwapi.dll API on Win11?
 Originally Posted by xiaoyao
If you want to handle the events of some objects, you can use a generic solution for late binding processing. I don't think you can solve this problem directly.
Yes, I know subclassing is the way to catch events.
But If I have understood this correct it about the client-server relation I’m out for.
Event responding on a remote client/server.
-
Feb 7th, 2025, 06:19 AM
#9
Junior Member
Re: ConnectToConnectionPoint shlwapi.dll API on Win11?
Just add "Implements PictureBoxEvents" and provide the IID of PictureBoxEvents you'll be asked to implement all interface methods.
This code with Timer since it only contains only a single event Timer, so easy to implement, in your case you need to place the code in a separate class .
Code:
Private Declare Function ConnectToConnectionPoint Lib "shlwapi" Alias "#168" (ByVal punk As Long, riidEvent As Any, _
ByVal fConnect As Long, ByVal punkTarget As Long, ByRef pdwCookie As Long, Optional ByVal ppcpOut As Long) As Long
Private Declare Function IIDFromString Lib "ole32.dll" (ByVal lpsz As Long, lpiid As Any) As Long
Implements TimerEvents
Private Sub Command1_Click()
Dim hr As Long
Dim dwCookie As Long
Dim IID(0 To 15) As Byte
IIDFromString StrPtr("{33AD4F2A-6699-11CF-B70C-00AA0060D393}"), IID(0) 'IDD Timer evens
hr = ConnectToConnectionPoint(ObjPtr(Me), IID(0), 1, ObjPtr(Timer1), dwCookie)
MsgBox Hex(hr)
End Sub
Private Sub TimerEvents_Timer()
Caption = Int(Rnd * 1000)
End Sub
-
Feb 7th, 2025, 08:58 AM
#10
Re: ConnectToConnectionPoint shlwapi.dll API on Win11?
 Originally Posted by anycoder
Just add "Implements PictureBoxEvents" and provide the IID of PictureBoxEvents you'll be asked to implement all interface methods.
This code with Timer since it only contains only a single event Timer, so easy to implement, in your case you need to place the code in a separate class .
Code:
Private Declare Function ConnectToConnectionPoint Lib "shlwapi" Alias "#168" (ByVal punk As Long, riidEvent As Any, _
ByVal fConnect As Long, ByVal punkTarget As Long, ByRef pdwCookie As Long, Optional ByVal ppcpOut As Long) As Long
Private Declare Function IIDFromString Lib "ole32.dll" (ByVal lpsz As Long, lpiid As Any) As Long
Implements TimerEvents
Private Sub Command1_Click()
Dim hr As Long
Dim dwCookie As Long
Dim IID(0 To 15) As Byte
IIDFromString StrPtr("{33AD4F2A-6699-11CF-B70C-00AA0060D393}"), IID(0) 'IDD Timer evens
hr = ConnectToConnectionPoint(ObjPtr(Me), IID(0), 1, ObjPtr(Timer1), dwCookie)
MsgBox Hex(hr)
End Sub
Private Sub TimerEvents_Timer()
Caption = Int(Rnd * 1000)
End Sub
Doh!
Yes, PictureBoxEvents interface *is* already available under VB typelib although deeply hidden (as a source interface of a coclass) i.e. Show Hidden Members menu in Object Browser does not unhide it but this compiles just fine:
Code:
Option Explicit
Implements VB.PictureBoxEvents
Private Sub PictureBoxEvents_Change()
End Sub
Private Sub PictureBoxEvents_Click()
End Sub
Private Sub PictureBoxEvents_DblClick()
End Sub
Private Sub PictureBoxEvents_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub PictureBoxEvents_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
End Sub
Private Sub PictureBoxEvents_GotFocus()
End Sub
Private Sub PictureBoxEvents_KeyDown(KeyCode As Integer, Shift As Integer)
End Sub
Private Sub PictureBoxEvents_KeyPress(KeyAscii As Integer)
End Sub
Private Sub PictureBoxEvents_KeyUp(KeyCode As Integer, Shift As Integer)
End Sub
Private Sub PictureBoxEvents_LinkClose()
End Sub
Private Sub PictureBoxEvents_LinkError(LinkErr As Integer)
End Sub
Private Sub PictureBoxEvents_LinkNotify()
End Sub
Private Sub PictureBoxEvents_LinkOpen(Cancel As Integer)
End Sub
Private Sub PictureBoxEvents_LostFocus()
End Sub
Private Sub PictureBoxEvents_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
End Sub
Private Sub PictureBoxEvents_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
End Sub
Private Sub PictureBoxEvents_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
End Sub
Private Sub PictureBoxEvents_OLECompleteDrag(Effect As Long)
End Sub
Private Sub PictureBoxEvents_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
End Sub
Private Sub PictureBoxEvents_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
End Sub
Private Sub PictureBoxEvents_OLEGiveFeedback(Effect As Long, DefaultCursors As Boolean)
End Sub
Private Sub PictureBoxEvents_OLESetData(Data As DataObject, DataFormat As Integer)
End Sub
Private Sub PictureBoxEvents_OLEStartDrag(Data As DataObject, AllowedEffects As Long)
End Sub
Private Sub PictureBoxEvents_Paint()
End Sub
Private Sub PictureBoxEvents_Resize()
End Sub
Private Sub PictureBoxEvents_Validate(Cancel As Boolean)
End Sub
IID_PictureBoxEvents is {33AD4ED2-6699-11CF-B70C-00AA0060D393} as already linked above.
cheers,
</wqw>
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
|