07-08-2016
11:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
07-08-2016
11:32 AM
AccessibleObjectFromWindow out of scope means?
The developers didn't create in the Inventor API com component the logic required to make this work at all?
OR
The API help team doesn't support with this level of coding (com level that requires dll imports) because they are not paid to do so?
In short am I wasting my time attempting to convert this specific window handle (IntPtr) into the app object, because I am so close to solving this?
268620 Afx:00007FF789EB0000:8:0000000000010005:0000000000000000:0000000000080CE7 268620 Inventor.Application.MainFrameHWND
Private Declare Function AccessibleObjectFromWindow Lib "oleacc" (ByVal Hwnd As Int32, ByVal dwId As Int32, ByRef riid As Guid, <MarshalAs(UnmanagedType.IUnknown)> ByRef ppvObject As Object) As Int32
Dim FoundWindows As List(Of IntPtr)
Private Declare Function GetDesktopWindow Lib "user32" () As Integer
Private Declare Function EnumChildWindows Lib "user32.dll" (ByVal WindowHandle As IntPtr, ByVal Callback As EnumWindowsProc, ByVal lParam As IntPtr) As Boolean
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Int32) As Int32
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hWnd As IntPtr, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Int32
Private Delegate Function EnumWindowsProc(ByVal hwnd As IntPtr, ByVal lParam As Int32) As Boolean
Private Const OBJID_NATIVEOM = &HFFFFFFF0
Private Const OBJID_CLIENT = &HFFFFFFFC
Private Sub ListDebug()
'calling code
FoundWindows = New List(Of IntPtr)
Dim WindowHandle As IntPtr = GetDesktopWindow()
EnumChildWindows(WindowHandle, AddressOf ListInventorChildWindows, 0)
Dim guid As New Guid("{B6B5DC40-96E3-11d2-B774-0060B0F159EF}")
Dim InventorApplication As Inventor.Application
Dim InvObject As Object = Nothing
For i As Integer = 0 To FoundWindows.Count - 1
AccessibleObjectFromWindow(FoundWindows(i), OBJID_CLIENT, guid, InvObject)
If Not InvObject Is Nothing Then
InventorApplication = InvObject.Application
End If
Next
End Sub
Public Function ListInventorChildWindows(ByVal hwnd As IntPtr, ByVal lParam As Int32) As Boolean
Dim WindowTitle As String, Ret As Integer
Dim ClassName As String
ClassName = Space(255)
Ret = GetClassName(hwnd, ClassName, 255)
ClassName = ClassName.Substring(0, Ret)
Debug.Print("[" & hwnd.ToString & "] " & ClassName)
If ClassName.Contains("Afx:00007FF789EB0000:8:0000000000010005:0000000000000000:") Then
Ret = GetWindowTextLength(hwnd)
WindowTitle = Space(Ret)
GetWindowText(hwnd, WindowTitle, Ret + 1)
Debug.Print("Window Text: " & WindowTitle)
FoundWindows.Add(hwnd)
End If
Return True
End Function
jvj