Java
0
Вклад в тег
2. Как научить JAVA отправлять в другое приложение команды посредством виндовых библиотек?
private static final WinDef.HWND HWND = User32Ext.USER32EXT.FindWindow("AIMP2_RemoteInfo", null);
private static final int WM_USER = 0x0400;
private static final int WM_AIMP_COMMAND = WM_USER + 0x75;
public static void main(String[] args) {
sendMsgToAimp(17);
}
public interface User32Ext extends User32 {
User32Ext USER32EXT = (User32Ext) Native.loadLibrary("user32",
User32Ext.class, W32APIOptions.DEFAULT_OPTIONS);
int SendMessage(HWND hWnd, int Msg, int wParam, int lParam);
}
private static WinDef.HWND getHandler() {
return HWND == null ? User32Ext.USER32EXT.FindWindow("AIMP2_RemoteInfo", null) : HWND;
}
private static void sendMsgToAimp(int cmdId) {
User32Ext.USER32EXT.SendMessage(getHandler(), WM_AIMP_COMMAND, cmdId, 0);
}
1. Как научить JAVA подключаться к mappingFile винды?
public static void main(String[] args) {
String nameFile = "AIMP2_RemoteInfo";
WinDef.HWND HWNDkernel = Kernel32Ext.KERNEL_INS.OpenFileMapping(WinNT.GENERIC_READ, true, nameFile);
Pointer pointer = Kernel32Ext.KERNEL_INS.MapViewOfFile(HWNDkernel, WinNT.SECTION_MAP_READ, 0, 0, 2048);
System.out.println("ERROR: " + Native.getLastError());
System.out.println("accept");
}
public interface Kernel32Ext extends Kernel32 {
Kernel32Ext KERNEL_INS = (Kernel32Ext) Native.loadLibrary("Kernel32",
Kernel32Ext.class, W32APIOptions.DEFAULT_OPTIONS);
HWND OpenFileMapping(int dwDesiredAccess, boolean bInheritHandle, String name);
}