MATLAB的External Functions接口允许以各种语言调用函数,其中包括Java.如本回答所述,与Windows API交互的流行Java库是Java Native Access(JNA).
在这个答案中演示了如何利用JNA发送WM_GETTEXT
消息.针对此问题的特定需求进行了调整并转换为static
方法,所需的Java-JNA代码如下所示:
package hack.graphic.devil
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinDef.LRESULT;
import com.sun.jna.win32.StdCallLibrary;
public class User32Util {
interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
int WM_GETTEXT = 0x000D;
LRESULT SendMessageA(HWND editHwnd, int wmGettext, long l, byte[] lParamStr);
}
public static String getStringFromHexHWND(String args0) {
User32 user32 = User32.INSTANCE;
HWND target = new HWND(new Pointer(Long.decode(args0)));
byte[] lParamStr = new byte[512];
user32.SendMessageA(target, User32.WM_GETTEXT, 512, lParamStr);
return Native.toString(lParamStr);
}
}
上面的代码导入了在JNA的旧分支(特别是其/src/com/sun/jna/
文件夹)中找到的类.打包.jar
后,可以使用以下方法从MATLAB调用:
javaaddpath(fullfile(pwd,'User32Util.jar'));
...
str = char(hack.graphic.devil.User32Util.getStringFromHexHWND(['0x' dec2hex(hTmp(5))]));
str
然后将包含所需的String
.优质教育基金
MATLAB的External Functions接口允许以各种语言调用函数,其中包括Java.如本回答所述,与Windows API交互的流行Java库是Java Native Access(JNA).
在这个答案中演示了如何利用JNA发送WM_GETTEXT
消息.针对此问题的特定需求进行了调整并转换为static
方法,所需的Java-JNA代码如下所示:
package hack.graphic.devil
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinDef.LRESULT;
import com.sun.jna.win32.StdCallLibrary;
public class User32Util {
interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
int WM_GETTEXT = 0x000D;
LRESULT SendMessageA(HWND editHwnd, int wmGettext, long l, byte[] lParamStr);
}
public static String getStringFromHexHWND(String args0) {
User32 user32 = User32.INSTANCE;
HWND target = new HWND(new Pointer(Long.decode(args0)));
byte[] lParamStr = new byte[512];
user32.SendMessageA(target, User32.WM_GETTEXT, 512, lParamStr);
return Native.toString(lParamStr);
}
}
上面的代码导入了在JNA的旧分支(特别是其/src/com/sun/jna/
文件夹)中找到的类.打包.jar
后,可以使用以下方法从MATLAB调用:
javaaddpath(fullfile(pwd,'User32Util.jar'));
...
str = char(hack.graphic.devil.User32Util.getStringFromHexHWND(['0x' dec2hex(hTmp(5))]));
str
然后将包含所需的String
.优质教育基金