Results 1 to 10 of 10

Thread: ConnectToConnectionPoint shlwapi.dll API on Win11?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    940

    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

  2. #2
    Hyperactive Member -Franky-'s Avatar
    Join Date
    Dec 2022
    Location
    Bremen Germany
    Posts
    373

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    940

    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.

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,784

    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>

  5. #5
    Hyperactive Member -Franky-'s Avatar
    Join Date
    Dec 2022
    Location
    Bremen Germany
    Posts
    373

    Re: ConnectToConnectionPoint shlwapi.dll API on Win11?

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

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    940

    Re: ConnectToConnectionPoint shlwapi.dll API on Win11?

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

  7. #7
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,042

    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.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    940

    Re: ConnectToConnectionPoint shlwapi.dll API on Win11?

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

  9. #9
    Junior Member anycoder's Avatar
    Join Date
    Jan 2025
    Posts
    21

    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

  10. #10
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,784

    Re: ConnectToConnectionPoint shlwapi.dll API on Win11?

    Quote Originally Posted by anycoder View Post
    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
  •  



Click Here to Expand Forum to Full Width