By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,417 Members | 1,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,417 IT Pros & Developers. It's quick & easy.

SendMessage WM_COPYDATA on 64bit System

P: n/a
Hello.

I use the fallowing Functions to send Message from one Application to
another. This is working correct on a 32bit System. But on a 64Bit System,
the Target-Application will no received anything. Can somebody help me, what
I am doing wrong?

Private Const _messageID As Integer = -11678085939
Public Const WM_COPYDATA As Integer = &H4A
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal
lParam As COPYDATASTRUCT) As Integer

<StructLayout(LayoutKind.Sequential)_
Private Class COPYDATASTRUCT
Public dwData As Integer = 0 '32 bit int to passed. Not used.
Public cbData As Integer = 0 'length of string. Will be one greater
because of null termination.
Public lpData As String 'string to be passed.

Public Sub New()
End Sub

Public Sub New(ByVal Data As String)
lpData = Data + Convert.ToChar(0) 'add null termination
cbData = lpData.Length 'length includes null chr so will be one
greater
End Sub
End Class

' For Sending:
Private Shared Sub SendCommandLine(ByVal hWnd As IntPtr, ByVal CommandLine
As String)
SendMessage(hWnd, WM_COPYDATA, _messageID, New
COPYDATASTRUCT(CommandLine))
End Sub

' For Receiving in the Target-Application
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = AppMessager.WM_COPYDATA Then
' ... do something ... this will no be called on a 64bit-Machine - on
32bit its working right
Return
End If
MyBase.WndProc(m)
End Sub

Thank all for their help!

Thomas
Apr 7 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
><StructLayout(LayoutKind.Sequential)_
Private Class COPYDATASTRUCT
Public dwData As Integer = 0 '32 bit int to passed. Not used.
Public cbData As Integer = 0 'length of string. Will be one greater
because of null termination.
Public lpData As String 'string to be passed.
dwData must be an IntPtr.

>
Public Sub New()
End Sub

Public Sub New(ByVal Data As String)
lpData = Data + Convert.ToChar(0) 'add null termination
Strings are automatically null terminated so you don't really have to
do this.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 8 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.