rashare
rashare

Reputation: 23

How do I call and initialize the Java Access Bridge API?

The Java Access Bridge API documentation states:

The Java Access Bridge API calls are contained in AccessBridgeCalls.h and to use them, you must also compile the file AccessBridgeCalls.c, which acts as the interface between your application and WindowsAccessBridge.dll.

But when I tried to create a dll out of AccessBridgeCalls.h & AccessBridgeCalls.c, it says missing AccessBridgeDebug.h file.

How do I call the initiateAccessBridge() method? I am looking to perform tasks similar to JavaMonkey.exe, such as identifying components in a Java Swing application.

When I call isJavaWindow(int) from the Access Bridge, it always returns false for all handlers.

Upvotes: 2

Views: 1411

Answers (1)

Stackia
Stackia

Reputation: 2151

JAB relies on the Windows Messaging mechanism to perform inter-process communications. You have to set up a thread to run message pump loop and call initiateAccessBridge() in that thread, otherwise some methods like isJavaWindow() will always return false.

Here is a C# reference:

            var accessBridge = new AccessBridge();
            // Use WPF UI thread if there is one
            var messageLoopDispatcher = Application.Current?.Dispatcher;
            if (messageLoopDispatcher == null)
            {
                var readyEvent = new ManualResetEvent(false);
                var messageLoopThread = new Thread(() =>
                {
                    messageLoopDispatcher = Dispatcher.CurrentDispatcher;
                    readyEvent.Set();
                    Dispatcher.Run();
                });
                messageLoopThread.SetApartmentState(ApartmentState.STA);
                messageLoopThread.Start();
                readyEvent.WaitOne();
            }
            messageLoopDispatcher.Invoke(() =>
            {
                accessBridge.Initialize();
            });

Upvotes: 0

Related Questions