简体   繁体   中英

Accessing ComInterface to VB6 OCX Control with win32 handle in c#

I'm at the moment automating the test for a legacy application developed in vb6, which uses a GridEx2000b Control from Janus Systems.

For doing this I'm using Ranorex as my favorite tool for developing the test automation, so that I can develop the test code using c#.

My problem now is to automate the GridEx 2000b control, which Ranorex out of-the-box don't have any support for. Therefore I'm trying to figure out a solution where I can reference the GrixEx control using the Win32 handle I can find for the control, so I can use the ComInterface from the component to navigate the automate the control.

I have an idea of a solution but I cannot figure out how to do it, where I hope that you guys would be able help me.

The pseudo code for the problem:

using GridEX20;

class GridExWrapper
{
    public GridEX20.GridEXClass Instance;

    public GridExWrapper(IntPtr win32handle)
    {
        Instance = (GridEX20.GridEXClass)Win32ControlUtilities.GetControlReference(win32Handle);
    }
}


class Win32ControlUtilities
{
    public static SomeKindOfHandle GetControlReference(IntPtr win32Handle)
    {
        ...
        ...
        ...
    }
}

I'll get the win32handle from Ranorex or some other spy tool. Then I can use the GridExWrapper like this.

using NUnit.Framework;

class Program
{
    [Test]
    public void control_should_have_9_items()
    {
        /// Get win32 handle from Ranorex
        IntPtr win32handle = XXXXXX;
        int expectedItemCount = 9;

        GridEXClass control = new GridExWrapper(win32handle);
        Assert.AreEqual(expectedItemCount, control.ItemCount);
    }

}

You could try the Microsoft UI Automation library (System.Windows.Automation) for identifying the properties of the control. Sometimes even if Ranorex fails, MSUIA manages to recognize the control as it looks into native properties of a control for identification. Not guaranteed but worth a try. Here is a link to a tutorial on using MSUIA.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM