我需要使用来自 Java 应用程序的 Window 消息传递与 C# 应用程序通信。从我的应用程序中,我注册了用于通信的消息。我能够成功获取 C# 应用程序的窗口句柄并注册消息。C# 应用程序通过发送 WM_COPYDATA 响应消息来响应消息。我可以达到收到 WM_COPYDATA 的程度。但我不确定如何从响应消息中提取消息内容。
如果我能获得一个示例代码,它使用 jniwrap 和 winpack 库从 java 应用程序的 WM_COPYDATA 消息中读取内容,这真的很有帮助。如果 lParam 的内容是 Structure 类型会更有帮助。
我必须编辑代码以删除敏感数据
以下代码通过窗口名称获取其他应用程序的窗口句柄,注册请求和响应消息,然后发送内容为空的请求消息。
private Library user32;
private long appHandle;
public void sendRequest() {
long requestMsgId = (int)this.registerWindowMessage("WM_TBD_SN_REQEST");
long responseMsgId = (int)this.registerWindowMessage("WM_TBD_SN_RESPONSE");
long tbdHandle = findWindow(null, "TestApp");
this.sendWindowsMessage(new Handle(tbdHandle), new Int(requestMsgId), new Handle(this.appHandle), new Pointer.Void());
}
public long sendWindowsMessage(final Parameter... args) {
final Function sendMessage = this.user32.getFunction("SendMessageA");
LongInt longInt = new LongInt();
sendMessage.invoke(longInt, args);
return longInt.getValue();
}
public long findWindow(final String classname, final String windowName) {
final Function findWindow = this.user32.getFunction("FindWindowA");
Parameter cName = null;
if (classname == null || classname.equals("")) {
cName = new Pointer.Void();
}
else {
cName = new AnsiString(classname);
}
LongInt longInt = new LongInt();
findWindow.invoke(longInt, cName, new AnsiString(windowName));
return longInt.getValue();
}
public long registerWindowMessage(String message) {
final Function findWindow = this.user32.getFunction("RegisterWindowMessageA");
LongInt longInt = new LongInt();
findWindow.invoke(longInt, new AnsiString(message));
return longInt.getValue();
}
这是自定义窗口过程,它将代替我的应用程序窗口的本机过程
public class MyWindowProc extends WindowProc {
@Override
public void callback() {
if (this._msg.getValue() == Msg.WM_COPYDATA) {
// I can get to this point, but not sure how I can get the information from the message
// The WM_TBD_SN_RESPONSE structure consists of four fields
// 1. hWnd Field --- window handle of the calling application...
// 2. msg Field --- WM_COPYDATA message code
// 3. wData Field --- TDB application's window handle
// 4. pData Field --- contains a CopyDataStruct
// CopyDataStruct.pData – contains the Serial Number ----> how to extract this?
// CopyDataStruct.dwData – contains the message code for WM_TBD_SN_RESPONSE (this should match responseMsgId)
}
else {
super.callback();
}
}
}
请帮忙。提前致谢。