Чтобы иметь доступ к работающему объекту по GetObject(,"ProgID"), нужно, чтобы сервер зарегистрировал свой объект как активный. VB таких средств не предоставляет, но есть С-шные API RegisterActiveObject и RevokeActiveObject из oleaut32.dll.Antonariy писал(а):Потребовалось подключиться к работающему ActiveX EXE, но получил "ActiveX component can't create object", попробовал другие свои ActiveX EXE-проекты - то же самое.
Private Type GUIDs
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
'Declares needed to register object in the ROT (Run Object Table)
Private Const ACTIVEOBJECT_STRONG = 0
Private Const ACTIVEOBJECT_WEAK = 1
Private Declare Function CLSIDFromProgID Lib "ole32.dll" (ByVal ProgID As Long, rclsid As GUIDs) As Long
Private Declare Function CoDisconnectObject Lib "ole32.dll" (ByVal pUnk As IUnknown, pvReserved As Long) As Long
Private Declare Function RegisterActiveObject Lib "oleaut32.dll" (ByVal pUnk As IUnknown, rclsid As GUIDs, ByVal dwFlags As Long, pdwRegister As Long) As Long
Private Declare Function RevokeActiveObject Lib "oleaut32.dll" (ByVal dwRegister As Long, ByVal pvReserved As Long) As Long
Private OLEInstance As Long
Public Sub AddToROT()
Dim mGuid As GUIDs
Dim lp As Long
'The magic happens here
'This code is responsible for creating the entry in the ROT
'Make sure to insert the correct qualified object (class) that you want in the ROT.
OLEInstance = 0
lp = CLSIDFromProgID(StrPtr("YourActiveXServerName.YourClassName"), mGuid)
If lp = 0 Then lp = RegisterActiveObject(Me, mGuid, ACTIVEOBJECT_WEAK, OLEInstance)
End Sub
Public Sub RemoveFromROT()
'Once we are done with the main program, lets clean up the rot
'by removing the entry for our ActiveX Server/DLL
If OLEInstance <> 0 Then RevokeActiveObject OLEInstance, 0
CoDisconnectObject Me, 0
End Sub
Сейчас этот форум просматривают: Yandex-бот и гости: 15