简体   繁体   English

在C#中使用Win32句柄访问ComInterface到VB6 OCX控件

[英]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. 目前,我正在自动测试在vb6中开发的旧版应用程序,该应用程序使用了Janus Systems的GridEx2000b控件。

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#. 为此,我将Ranorex用作开发测试自动化的最喜欢的工具,以便可以使用c#开发测试代码。

My problem now is to automate the GridEx 2000b control, which Ranorex out of-the-box don't have any support for. 我现在的问题是自动化GridEx 2000b控件,Ranorex开箱即用不提供任何支持。 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. 因此,我试图找到一种解决方案,在该解决方案中,我可以使用为控件找到的Win32句柄引用GrixEx控件,以便可以使用组件中的ComInterface来导航控件的自动化。

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. 我将从Ranorex或其他间谍工具获得win32handle。 Then I can use the GridExWrapper like this. 然后,我可以像这样使用GridExWrapper。

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. 您可以尝试使用Microsoft UI自动化库(System.Windows.Automation)来标识控件的属性。 Sometimes even if Ranorex fails, MSUIA manages to recognize the control as it looks into native properties of a control for identification. 有时,即使Ranorex失败了,MSUIA也会设法识别控件,因为它会查看控件的本机属性以进行识别。 Not guaranteed but worth a try. 无法保证,但值得一试。 Here is a link to a tutorial on using MSUIA. 这是有关使用MSUIA的教程的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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