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

家住魔仙堡 提交于 2019-12-11 13:18:41

问题


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.


回答1:


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 



回答2:


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");     
    }
}


来源:https://stackoverflow.com/questions/21962086/java-jna-findwindow-error-looking-up-function-findwindow-the-specified-pr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!