S
S
Saliaz2016-03-31 11:36:04
Java
Saliaz, 2016-03-31 11:36:04

How to work with MappingFile of third party application in JAVA?

Good afternoon.
I decided to implement player control on a PC using a phone.
Now the server part is implemented in JAVA on sockets for receiving the command code, emulating the pressing of previously registered key combinations by the robot and responding to the client about the execution.
And an Android program was written to send commands and receive a response about execution.
Actually, I decided to make the recognition of the files being played and implement the work with AIMP through their API more flexibly.
But in the AIMP API itself, apart from the list of constants, there is nothing really.
Since all work is carried out by sending commands directly to the application, for example, through the standard Windows function sendMessage (kernel32.dll), and all information about the file being played is stored in MappingFile and stored as an array.
Actually there are several questions:
1. How to teach JAVA to connect to Windows mappingFile?
2. How to teach JAVA to send commands to another application using Windows libraries?
There is little information on the Internet.
Little is clear from the official JNA documentation, and there are not so many examples of working with JNA that would help me with my task.
I will be very grateful for your help. Upon completion of successful implementation, I will post the written programs for testing and / or for permanent use.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saliaz, 2016-04-10
@Saliaz

2. How to teach JAVA to send commands to another application using Windows libraries?

Understood this.
Example:
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);
    }

But with:
a little stalled >_>"
The problem is the following: I get a Pointer from the MapViewOfFile function.
If you look at the example for C # ( https://github.com/trofimchuk-t/AIMP.NET-Remote-AP... ) of the CurrentTrackInfo method, then you need bring the resulting Pointer to the file structure and read information from the file.But how to do this I have no idea T_T.Help me figure
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);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question