473,395 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SendMessage WM_COPYDATA on 64bit System

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
1 6222
><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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: g.franzkowiak | last post by:
Hello everybody, I've tryed to use an interprocess communication via SendMessage on Windows. Unfortunately, nothing goes on ...
2
by: Erik | last post by:
I am having trouble getting this to work so hopefully someone can provide some insite. I have a structure that I store in a CopyDataStruct which is then send to another application via...
2
by: James Burrow | last post by:
Hi, I am trying to write a 2 .net programs that can communicate via windows messages. I have achieved this but only just passing ints. When i try and pass a string, i get junk out. I guess this...
0
by: Augie | last post by:
Dear All, I came across this piece of code to send a message. I have this setup and running... getting all the WM_COPYDATA messages on the client side. However I can't see the contexts of the...
1
by: Daniel Halan | last post by:
Hello, I want to send a SendMessage(hwnd,...) to an another application containing eighter a "String" or a PIDL... I know that the pointer lives in its own process so the other app will have...
4
by: Sean | last post by:
I am trying to send a WM_COPYDATA message to another application in C#, ..NET 2.0. The other application receives the message, but only seems to see the first character of the string, does...
1
by: alexwhitman | last post by:
Hi, I'm trying to port a c++ class to c# and in the c++ class I have a struct defined as: struct SNARLSTRUCT { SNARL_COMMANDS cmd; long id; long timeout; long lngData2; char title;
14
by: Kerem Gümrükcü | last post by:
Hi, i want to emulate a (synchronous) BroadCastSystemMessage with EnumWindows and SendMessage. I dont want to use the BroadcastSystemMessage because it needs the SE_TCB_NAME Privilege (you...
1
by: xMetalDetectorx | last post by:
I have two C# Applications. The first application has to send 2 strings to the other application. The first string is just a simple string "abc", while the 2nd string contains a path...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.