sendmessage by WM_COPYDATA

20 views
Skip to first unread message

snsk...@163.com

unread,
Aug 22, 2013, 5:15:24 AM8/22/13
to jniwrapp...@teamdev.com
I want to know how to use the WM_COPYDATA property, in the sendMessage function 

      Wnd wnd = new Wnd(527750);
       Function sendMessage = User32.getInstance().getFunction(FUNCTION_SEND_MESSAGE.toString());   
        sendMessage.invoke(result,
                wnd,
                new UInt(Msg.WM_COPYDATA),
                new IntPtr(0),
              ??????  //what should I replace here?
          );

Pascal example :

   procedure TForm17.Button1Click(Sender: TObject);
    var
       s: String;
       SendData: tagCOPYDATASTRUCT;
     begin
     s := Edit2.Text;
   with SendData do
   begin
      cbData := length(s) * sizeof(char) + 2;
      GetMem(lpData, cbData);
      StrCopy(lpData, PChar(s));
  end;


  sendMessage(strtoint(Edit1.Text), WM_COPYDATA, 0, integer(@SendData));
  FreeMem(SendData.lpData);
end;


Sergei Piletsky

unread,
Aug 22, 2013, 7:46:52 AM8/22/13
to snsk...@163.com, jniwrapp...@teamdev.com
According to MSDN documentation for WM_COPYDATA message, lParam parameter should be a pointer to COPYDATASTRUCT structure. So, in order to pass such parameter to the SendMessage function, you can use the following construction:

new Pointer(new CopyDataStruct());

Here CopyDataStruct is the wrapper for COPYDATASTRUCT structure and it can be defined as following:

public class CopyDataStruct extends Structure {
    private Pointer.Void dwData = new Pointer.Void();
    private UInt32 cbData = new UInt32();
    private Pointer.Void lpData = new Pointer.Void();

    public CopyDataStruct() {
        init(new Parameter[]{dwData, cbData, lpData});
    }

    public Pointer.Void getDwData() {
        return dwData;
    }

    public UInt32 getCbData() {
        return cbData;
    }

    public Pointer.Void getLpData() {
        return lpData;
    }
}


-Serge


--
You received this message because you are subscribed to the Google Groups "JNIWrapper Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jniwrapper-for...@teamdev.com.
To post to this group, send email to jniwrapp...@teamdev.com.
Visit this group at http://groups.google.com/a/teamdev.com/group/jniwrapper-forum/.
For more options, visit https://groups.google.com/a/teamdev.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages