Originally Posted by
Aflatoon
In that case, assuming you can obtain the correct IDispatch ID, you would have to call AccessibleObjectFromWindow on every window of the relevant class to get an object and then apply your tests to see if it is the one you want.
Thank you! I will now attempt to AccessibleObjectFromWindow.......
Originally Posted by
Kenneth Hobs
I guess if you want to try, go into regedit and Find the class Reflection2.Session. Then expand the CLSID to get the value.
Does F29799A0-4B0C-101B-AC7B-04021C007002 seem like a valid IDispatch ID? And will this ID be the same accross all computers?
I am now trying to figure out this function. Can someone help me modify this code to work?
Option Explicit
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function IIDFromString Lib "ole32" _
(ByVal lpsz As Long, ByRef lpiid As GUID) As Long
Private Declare Function AccessibleObjectFromWindow Lib "oleacc" _
(ByVal hWnd As Long, ByVal dwId As Long, ByRef riid As GUID, _
ByRef ppvObject As Object) As Long
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Const RETURN_OK As Long = &H0
Private Const IID_IDispatch As String = "{F29799A0-4B0C-101B-AC7B-04021C007002}" ' Found this for Reflection2.Session
Private Const OBJID_NATIVEOM As Long = &HFFFFFFF0 '// This is supposed to go as the second input of AccessibleObjectFromWindow, _
'// but I think I need to change this, as this was originally written for Excel.
Sub ComplexTest()
Dim iCounter As Long
Dim hWndXL As Long
Dim oXLApp As Object
Dim oWB As Object
Dim oWS As Object
'// First the first Reflection Window
hWndXL = FindWindowEx(0&, 0&, "r2Window", vbNullString)
'// Got one, at least...?
Do While hWndXL > 0
'// Increment counter
iCounter = iCounter + 1
'// Print Instance & Handle to Debug window
Debug.Print "Instance #" & iCounter & ": "; "Handle: " & hWndXL
'// Get a reference to it
If GetReferenceToApp(hWndXL, oXLApp) Then
'// Check if this is the window I want
End If
'// Find the next Reflection Window
hWndXL = FindWindowEx(0, hWndXL, "r2Window", vbNullString)
Loop
End Sub
'// Returns a reference to a specific instance of Excel.
'// The Instance is defined by the Handle (hWndXL) passed
'// by the calling procedure
Function GetReferenceToApp(hWndXL As Long, oXLApp As Object) As Boolean
Dim hWinDesk As Long
Dim hWin7 As Long
Dim obj As Object
Dim iID As GUID
Call IIDFromString(StrPtr(IID_IDispatch), iID) ' Outputs iID as the GUID
If AccessibleObjectFromWindow(hWndXL, OBJID_NATIVEOM, iID, Session) = RETURN_OK Then
Set oXLApp = obj.Application
GetReferenceToXLApp = True
Session.Transmit "IT WORKS!!!!!!!!!!!!!!!!!!!!!!!!"
End If
End Function