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();
}
}
}
助けてください。前もって感謝します。