I'm aware of several existing questions on this topic, but they either don't have answers, or the answers don't work for me, so I'm trying again here.
I am attempting to use the Java Access Bridge API in a WinForms C# project. Both Java Ferret and Java Monkey work fine, which tells me that the bridge is installed and at least capable of functioning. However, when I try to run isJavaWindow() in my own code, it always returns false. I've tried other solutions that have recommended placing the Windows_run() code in the form constructor, but this has no effect for me.
It's worth noting that the code below DOES work for me on my home PC, but does not work on my work PC. It also works for a coworker, but only if he runs the executable directly - if he tries to run it from Visual Studio, it doesn't work there either.
Any help would be appreciated. I've been pulling my hair out over this for several days now, and have exhausted every possibility that I've come across in Google or elsewhere.
JabApi.Windows_run();
Application.DoEvents();
string windowName = "SwingSet2";
string className = "SunAwtFrame";
IntPtr hWnd = JabApi.FindWindow(className, windowName);
//This always returns false (0), even though it's pointing to a valid Java window
if (JabApi.isJavaWindow(hWnd)==1)
{
MessageBox.Show("Java window found!");
}
I'll answer my own question here.
The issue turned out to be that I was running Visual Studio as Administrator. When I tried running VS with normal privileges, the Java Access Bridge code immediately began working as expected.
The executable itself was running into a similar issue. When I previously ran the executable outside of VS, it turned out I was running it from a location with elevated privileges. When I moved the executable to a normal location, it worked as expected.