How to use GetLParam?

  • Thread starter Thread starter Mark T..
  • Start date Start date
M

Mark T..

I need to send a byte array or a string passed in the LParam from MY
application to ANOTHER MY application.
I read the MSDN and found no samples.


I made several tries and did not succeed to receive a byte array or a
string.

I am using the GetLParam like this:

Private Structure MyType
...
End Structure

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
....
Dim MyVar As MyType

MyVar = GetLParam(GetType(MyType))
....

End Sub

Always got an error when retrieving MyVar.


Thanks for your support


MT
 
Hi,

When passing strings or pointer to any data or arrays accross process
boundries that data needs to be marshalled. In .NET the common solution is
to use remoting for this, if you abosolutely want to do it via the windows
procedure and are prepared to rely on some interop you can use the Win32
SendMessage API to send WM_COPYDATA messages from one application to the
other, this is a specialized message which takes care of marhsalling the
data from one process to the other.

Hope this helps
 
Chris said:
Hi,

When passing strings or pointer to any data or arrays accross process
boundries that data needs to be marshalled. In .NET the common solution is

I tried lot's of MarshalAs and none worked.
to use remoting for this, if you abosolutely want to do it via the windows
procedure and are prepared to rely on some interop you can use the Win32
SendMessage API to send WM_COPYDATA messages from one application to the

I need to send a WM_USER message
other, this is a specialized message which takes care of marhsalling the
data from one process to the other.

Hope this helps

Thanks for your answer

MT
 
Hi Mark,

Yes, MarshalAs will not do the trick for you. However if you must send
WM_USER, then I would recommend you look at the following post on my blog
http://dotnetjunkies.com/WebLog/chris.taylor/archive/2004/05/31/14828.aspx.
This describes what you will need to do marshal pointers accross processes
boundries. The code is for the LVM_GETITEM message, but you can adapt it to
work for anything as long as you have some control over the environment.

Hope this helps
 
Chris said:
Hi Mark,

Yes, MarshalAs will not do the trick for you. However if you must send
WM_USER, then I would recommend you look at the following post on my blog
http://dotnetjunkies.com/WebLog/chris.taylor/archive/2004/05/31/14828.aspx.
This describes what you will need to do marshal pointers accross processes
boundries. The code is for the LVM_GETITEM message, but you can adapt it to
work for anything as long as you have some control over the environment.

Hope this helps

Thank you for your sample

here is the string receiver test that works:


Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = UserMsgs.WM_UserMess Then
MyBase.Text = Marshal.PtrToStringAuto(m.LParam)
Return
End If
MyBase.WndProc(m)
End Sub
 
Thank you for your sample
here is the string receiver test that works:


Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = UserMsgs.WM_UserMess Then
MyBase.Text = Marshal.PtrToStringAuto(m.LParam)
Return
End If
MyBase.WndProc(m)
End Sub

Unfortunately this test only works if the sender and the receiver is the
same exe, does not work for different applications ;(

MT
 
Hi Mark,

Yes, that is because the pointers are within the same physical process. You
will have to go the route described in my
post for it to work.
 
Chris said:
Hi Mark,

Yes, that is because the pointers are within the same physical process. You
will have to go the route described in my
post for it to work.
Thank you again
 
Back
Top