Java JNA FindWindow() - Error looking up function 'FindWindow': The specified procedure could not be found

StackOverflow https://stackoverflow.com/questions/21962086

  •  15-10-2022
  •  | 
  •  

Question

I'm trying to bring to front a window named MyWindowTitle, using JNA.

import com.sun.jna.Native;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.platform.win32.WinDef.HWND;

public class ToFront {

public static interface User32 extends StdCallLibrary {
    final User32 instance = (User32) Native.loadLibrary ("user32", User32.class);
    HWND FindWindow(String winClass, String title); 
    boolean ShowWindow(HWND hWnd, int nCmdShow);
    boolean SetForegroundWindow(HWND hWnd);

}


public static void main(String[] args) {
    HWND hwnd = User32.instance.FindWindow(null, "MyWindowTitle"); 
    User32.instance.ShowWindow(hwnd, 9); 
    User32.instance.SetForegroundWindow(hwnd); 
}

}

I'm getting the following exception java.lang.UnsatisfiedLinkError: Error looking up function 'FindWindow': The specified procedure could not be found.

Était-ce utile?

La solution

Check the spelling of your function. You can use dependency walker to see if that function exists in your dll.

Ps : when I opened user32.dll those are the functions I found

:FindWindowA,FindWindowExA,FindWindowExW,FindWindowW 

Autres conseils

You can use the following code that calls FindWindowEx. Note that FindFindow does not search child windows according to this article http://msdn.microsoft.com/en-us/library/windows/desktop/ms633499(v=vs.85).aspx

import com.sun.jna.Native;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.win32.StdCallLibrary;

public class SomeClass 
{
    public static interface User32 extends StdCallLibrary
    {
         final User32 instance = (User32) Native.loadLibrary ("user32", User32.class);
         HWND FindWindowExA(HWND hwndParent, HWND childAfter, String className, String windowName);
         HWND FindWindowA(String className, String windowName);
    }

    public static void main(String[] args)
    {
        HWND hwndShell = User32.instance.FindWindowExA(null, null, "Shell_TrayWnd", null);
        HWND hWnd = User32.instance.FindWindowExA(hwndShell, null, "Start", "Start");     
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top