VBA Code:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Class1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Declare PtrSafe Function IIDFromString Lib "ole32.dll" (ByVal lpsz As LongPtr, lpiid As GUID) As Long
Private Declare PtrSafe Function ConnectToConnectionPoint _
Lib "shlwapi" Alias "#168" _
(ByVal punk As stdole.IUnknown, _
ByRef riidEvent As GUID, _
ByVal fConnect As Long, _
ByVal punkTarget As stdole.IUnknown, _
ByRef pdwCookie As Long, _
Optional ByVal ppcpOut As LongPtr) As Long
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private cookie As Long
Private iid As GUID
Private cls2 As Class2
Private Sub Class_Initialize()
'OLEObjects Events
Const s = "{00024410-0000-0000-C000-000000000046}"
Dim hr As Long
hr = IIDFromString(StrPtr(s), iid)
Debug.Print hr
Set cls2 = New Class2
hr = ConnectToConnectionPoint(cls2, iid, 1, ie, cookie)
Debug.Print Hex(hr), cookie '[B][COLOR=rgb(226, 80, 65)]Error code: hr = 80004005, and cookie = 0[/COLOR][/B]
If hr <> 0 Then Exit Sub
End Sub
Private Sub Class_Terminate()
Dim hr As Long
hr = ConnectToConnectionPoint(Nothing, iid, 0, ie, cookie)
Debug.Print Hex(hr), cookie
If hr <> 0 Then Exit Sub
End Sub
VBA Code:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Class2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Public Sub DocumentComplete(ByVal pDisp As Object, URL As Variant) 'the original event has no parameters
Attribute DocumentComplete.VB_UserMemId = 259
Debug.Print "DocumentComplete"
End Sub
Public Sub myGotFocus()
Attribute myGotFocus.VB_UserMemId = 1541
Debug.Print "myGotFocus"
End Sub
Public Sub myLostFocus()
Attribute myLostFocus.VB_UserMemId = 1542
Debug.Print "myLostFocus"
End Sub
when i call it like this, i get an error code of 80004005, in Class1_Initialize
VBA Code:
Private cls As Class1
Sub start_()
Set cls = New Class1
End Sub
Sub end_()
Set cls = Nothing
End Sub