Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C实现Java自动化的WindowsAccessBridge_C#_Java Access Bridge - Fatal编程技术网

C# 使用C实现Java自动化的WindowsAccessBridge

C# 使用C实现Java自动化的WindowsAccessBridge,c#,java-access-bridge,C#,Java Access Bridge,我尝试使用WindowsAccessBridge.dll自动化java应用程序 我可以获取窗口句柄,但调用函数isJavaWindowSystem.IntPtr hWnd总是返回false 请在下面找到我的代码: static void Main() { System.Int32 vmID = 0; System.Int64 _acParent = 0; string WndName = "GLOBUS EDU";

我尝试使用WindowsAccessBridge.dll自动化java应用程序

我可以获取窗口句柄,但调用函数isJavaWindowSystem.IntPtr hWnd总是返回false

请在下面找到我的代码:

    static void Main()
    {
        System.Int32 vmID = 0;
        System.Int64 _acParent = 0;
        string WndName = "GLOBUS EDU";
        string ClassName = "SunAwtFrame";

        Windows_run();
        System.IntPtr hWnd = System.IntPtr.Zero;
        hWnd = (System.IntPtr)FindWindow(ClassName, WndName);
        bool Found = isJavaWindow(hWnd);

        if (!Found) { throw new System.Exception("ERROR: Unable to find window by classname " + ClassName + " and " + WndName + "!"); }

        System.Console.WriteLine("Application is finished. Press ENTER to exit...");
        System.Console.ReadKey();
    }
互操作:

    [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
    [System.Runtime.InteropServices.DllImport("WindowsAccessBridge-64.dll", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
    private extern static bool getAccessibleContextFromHWNDFct(System.IntPtr hwnd, out System.Int32 vmID, out System.Int32 _acParent);
    private static bool getAccesibleContextFromHWND(System.IntPtr hWnd, out System.Int32 vmID, out System.Int64 acParent)
    {
        System.Int32 ac = -1;
        bool retVal = false;

        getAccessibleContextFromHWNDFct(hWnd, out vmID, out ac);
        acParent = ac;

        return retVal;
    }

    [System.Runtime.InteropServices.DllImport("WindowsAccessBridge-64.dll", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
    private extern static bool getAccessibleContextInfo(int vmID, System.IntPtr ac, out AccessibleContextInfo textInfo);

    [System.Runtime.InteropServices.DllImport("WindowsAccessBridge-64.dll", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, ThrowOnUnmappableChar = true, CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
    private extern static void Windows_run();

    [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
    private static extern System.IntPtr FindWindow(string lpClassName, string lpWindowName);

    [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
    private static extern System.IntPtr FindWindowByCaptionFct(System.IntPtr ZeroOnly, string lpWindowName);
    private static System.IntPtr FindWindowByCaption(string WindowTitle) { return FindWindowByCaptionFct(System.IntPtr.Zero, WindowTitle); }

    [System.Runtime.InteropServices.DllImport("WindowsAccessBridge-64.dll", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, ThrowOnUnmappableChar = true, CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
    private extern static System.Boolean isJavaWindow(System.IntPtr hwnd);
函数findwindows工作得很好,我得到了Spy++显示的窗口句柄。Spy++说,类名是sunawtframe

我的Java应用程序以64位运行,但我尝试了所有的库-32,-64,还将VS配置管理器从x86切换到x64,然后再切换回来

AccessBridge本身运行良好-Java-Monkey-64.exe可以监视我正在运行的Java应用程序

有人有想法吗,为什么这不起作用

问候,,

几天来我一直在努力解决你的问题

我创建了一个枚举窗口的程序,该窗口是java应用程序,当然是在控制台应用程序上编写的,并捕获和您相同的问题。 然后,我在WPF应用程序上重写它,枚举所有窗口,然后认识到:除了正常窗口,我还看到一个奇怪的窗口,名为:java access bridge,问题显然是:

Windows_运行功能需要有一个活动的Windows消息泵。 另一种方法是,您必须将其放在WPF应用程序的构造函数或类似的东西上

如果有结果!=假的{ 而GetMessage&msg,NULL,0,0{ 翻译信息&msg; DispatchMessage&msg; } 关停桥; } Java Monkey应用程序中的代码

创建隐藏窗口后,它将使用已注册的消息执行PostMessage。响应此消息,并向创建的窗口发回另一条消息。因此,他们通过这种方式交流。 而且,只有在消息泵能够处理消息之后,才能调用JAB函数。
这就是java monkey需要在其业务中使用回调的原因。

将类名传递为null,如下代码所示:

IntPtr hWnd = FindWindow(null, "GLOBUS EDU"); //cast to IntPtr is redundant
bool Found = isJavaWindow(hWnd);
参考是在这里的文件,它为我工作