![](/img/trans.png)
[英]com.sun.jna.Pointer cannot be cast to com.sun.jna.platform.win32.WinDef.LPARAM
[英]Pointer(long) is not public in com.sun.jna.Pointer; Cannot be accessed from outside package
我正在創建一個程序,使我獲得焦點的窗口標題和特定窗口標題的處理ID。 一切正常。 但是在行
Pointer zero=new Pointer(0);
有一條警告顯示“ Pointer(long)在com.sun.jna.Pointer中不是公共的;無法從外部程序包訪問”。 。 我沒有任何解決方案來解決它。 請幫幫我。
public class Main extends SecurityManager
{
public static int brojac = 0;
public interface User32 extends StdCallLibrary
{
User32 instance = (User32) Native.loadLibrary("user32", User32.class);
HWND GetForegroundWindow(); // add this
int GetWindowTextA (HWND hWnd, byte[] lpString, int nMaxCount);
boolean EnumWindows(WinUser.WNDENUMPROC lpEnumFunc, Pointer arg);
int GetWindowThreadProcessId(HWND hwnd, IntByReference pid);
}
public interface Kernel32 extends StdCallLibrary
{
Kernel32 INSTANCE = (Kernel32)Native.loadLibrary("kernel32", Kernel32.class);
public Pointer OpenProcess(int dwDesiredAccess, boolean bInheritHandle, int dwProcessId);
public int GetTickCount();
};
public interface psapi extends StdCallLibrary
{
psapi INSTANCE = (psapi)Native.loadLibrary("psapi", psapi.class);
int GetModuleFileNameExA (Pointer process, Pointer hModule, byte[] lpString, int nMaxCount);
};
public static String getModuleFilename(HWND hwnd)
{
byte[] exePathname = new byte[512];
Pointer zero = new Pointer(0);
IntByReference pid = new IntByReference();
User32.instance.GetWindowThreadProcessId(hwnd, pid);
System.out.println("PID is " + pid.getValue());
Pointer process = Kernel32.INSTANCE.OpenProcess(1040, false, pid.getValue());
int result = psapi.INSTANCE.GetModuleFileNameExA(process, zero, exePathname, 512);
System.out.println("===========module is " + result);
String text = Native.toString(exePathname).substring(0, result);
return text;
}
public static void main(String[] args) throws InterruptedException
{
final User32 user32 = User32.instance;
user32.EnumWindows(new WNDENUMPROC() {
int count = 0;
@Override
public boolean callback(HWND hWnd, Pointer arg1)
{
byte[] windowText = new byte[512];
HWND hwnd = User32.instance.GetForegroundWindow(); // then you can call it!
User32.instance.GetWindowTextA(hwnd, windowText, 1024);
String wtext=(Native.toString(windowText));
System.out.println("Found window with text===" + hWnd + ", total=== " + ++count
+ " Text:== " + wtext);
wtext = getModuleFilename(hWnd);
System.out.println("############## " + wtext);
return true;
} }, null);
}
}
我無法重現您的警告; 使用JNA 4.1.0版,代碼可以正常工作。 盡管(隱式地)在倒數第二條以“找到帶有文本的窗口”開頭的消息中調用hWnd.toString()
並不是很有意義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.