Micro Focus QTP (UFT) Forums
MicWpfWindow from .NET AOM - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: MicWpfWindow from .NET AOM (/Thread-MicWpfWindow-from-NET-AOM)



MicWpfWindow from .NET AOM - JozinSBazin - 08-08-2011

Dear all,

I'm trying to load a basic object repository into .NET Visual Basic
code. Mercury.ObjectRepositoryUtil is not available for some reason
(I have QTP 10.00). There is, however
REPOSITORYUTILLIb.ObjectRepositoryUtil, so I tried to use that.

I need to do things like

Code:
Window("windowName").Activate
from within .NET VisualBasic.

Apparently, MicWpfWindow class has all the right methods. This may or may
not be the thing to look for, I don't know.

But obtaining a reference to a MicWpfWindow from the object repository is
a bit problematic. It appears that the repository util contains a bunch of
__ComObject's.
But none of them casts to a MicWpfWindow or a WpfWindow interface.

Could somebody advise me, please? Thanks!

PS.

I have imported
QTAutomationAgent.exe
REPOSITORYUTILLIb.dll
Mercury.WpfPackage.Interop.dll
WpfPackage.dll
QTApplicationObj.dll
QTApplicationObjLib.dll


I have tried the following:

Code:
Dim orep As REPOSITORYUTILLib.ObjectRepositoryUtilClass
        orep = New ObjectRepositoryUtil()
        Dim orepType As Type = orep.GetType
        orep.Load(repoPath)


        '' Just a simple call to GetAllObjects doesn't work
        Dim children As Object = _
             orepType.InvokeMember("GetAllObjects", Reflection.BindingFlags.InvokeMethod, _
                                    Nothing, orep, New Object() {Nothing})

        Dim childrenType As Type = children.GetType
        Dim cnt As Integer

        '' Retrieve count ''''''''''''''''''''''''''''''''''''''''''''
        cnt = CInt(childrenType.InvokeMember("Count", _
                    Reflection.BindingFlags.InvokeMethod, Nothing, children, Nothing))



        For i As Integer = 0 To cnt - 1
            ' obj.GetType is telling me that this is a __ComObject
            Dim obj As Object = childrenType.InvokeMember("Item", Reflection.BindingFlags.InvokeMethod, _
                                                          Nothing, children, New String() {i.ToString})
            Dim logName As String = orep.GetLogicalName(obj)

            If logName = "Notepad" Then
                '' Unable to cast COM object Exception
                Dim win As Mercury.WpfPackage.Interop.WpfWindow = obj
            End If
        Next i