473,396 Members | 2,004 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,396 software developers and data experts.

WM_COPYDATA

Hi,

I am trying to find if there is a structure in VB.NET that uses
COPDATSTRUCT.
In interfacing to an existing application, the application uses WM_COPYDATA
message
extensively, between applications.
I was able to capture the message loop within a VB.Net application using
WndProc() method,
and was receiving message 74 for WM_COPYDATA message.
The issue I am running into is that the internal message I am looking for is
in the COPYDATASTRUCT
dwData.
So I am looking for a way to reference the message within the
COPYDATASTRUCT from
the WndProc() method.

Example of C++ application...

within message received function
Nov 20 '05 #1
1 9127

"James Kunicki" <ji***@snet.net> wrote in message
news:eW*************@TK2MSFTNGP10.phx.gbl...
Hi,

I am trying to find if there is a structure in VB.NET that uses
COPDATSTRUCT.
In interfacing to an existing application, the application uses WM_COPYDATA
message
extensively, between applications.
I was able to capture the message loop within a VB.Net application using
WndProc() method,
and was receiving message 74 for WM_COPYDATA message.
The issue I am running into is that the internal message I am looking for is
in the COPYDATASTRUCT
dwData.
So I am looking for a way to reference the message within the


Here is a simple example of using WM_COPYDATA that I cooked up a while back...
This is two separate applications, and these are the main forms for each one....

Application 1 - the receiver...

Imports System.Runtime.InteropServices

Public Class MainForm
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Messages As System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Messages = New System.Windows.Forms.ListBox()
Me.SuspendLayout()
'
'Messages
'
Me.Messages.Dock = System.Windows.Forms.DockStyle.Fill
Me.Messages.IntegralHeight = False
Me.Messages.Name = "Messages"
Me.Messages.Size = New System.Drawing.Size(292, 273)
Me.Messages.TabIndex = 0
'
'MainForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Messages})
Me.Name = "MainForm"
Me.Text = "Receive WM_COPYDATA"
Me.ResumeLayout(False)

End Sub

#End Region

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = MainForm.WM_COPYDATA Then
Dim data As CopyData
Dim message As String

' get the data...
data = CType(m.GetLParam(GetType(CopyData)), CopyData)
message = Marshal.PtrToStringAuto(data.lpData, data.cbData \
Marshal.SystemDefaultCharSize)

' add the message
Messages.Items.Add(String.Format("{0}: {1}",
DateTime.Now.ToShortTimeString(), message))

' let them know we processed the message...
m.Result = New IntPtr(1)
Else
MyBase.WndProc(m)
End If
End Sub

Private Const WM_COPYDATA As Integer = &H4A

<StructLayout(LayoutKind.Sequential)> _
Private Structure CopyData
Public dwData As IntPtr
Public cbData As Integer
Public lpData As IntPtr
End Structure
End Class
Application 2 - The sender....

Imports System.Runtime.InteropServices

Public Class MainForm
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MessageText As System.Windows.Forms.TextBox
Friend WithEvents Send As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MessageText = New System.Windows.Forms.TextBox()
Me.Send = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'MessageText
'
Me.MessageText.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me.MessageText.Name = "MessageText"
Me.MessageText.Size = New System.Drawing.Size(328, 20)
Me.MessageText.TabIndex = 0
Me.MessageText.Text = ""
'
'Send
'
Me.Send.Anchor = System.Windows.Forms.AnchorStyles.Top
Me.Send.Location = New System.Drawing.Point(127, 32)
Me.Send.Name = "Send"
Me.Send.TabIndex = 1
Me.Send.Text = "Send"
'
'MainForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(328, 61)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Send,
Me.MessageText})
Me.Name = "MainForm"
Me.Text = "Send Data To Client Using WM_COPYDATA"
Me.ResumeLayout(False)

End Sub

#End Region

Private Const WM_COPYDATA As Integer = &H4A
Private Const WindowName As String = "Receive WM_COPYDATA"

<StructLayout(LayoutKind.Sequential)> _
Private Structure CopyData
Public dwData As IntPtr
Public cbData As Integer
Public lpData As IntPtr
End Structure

Private Declare Auto Function SendMessage Lib "user32" _
(ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As IntPtr, _
ByRef lParam As CopyData) As Boolean

Private Declare Auto Function FindWindow Lib "user32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr

Private Sub Send_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Send.Click
Dim ClientWindow As IntPtr = MainForm.FindWindow(Nothing,
MainForm.WindowName)

' make sure we found an active client window
If Not ClientWindow.Equals(IntPtr.Zero) Then

' if there is text to send
If Me.MessageText.Text.Length > 0 Then
Dim message As String = Me.MessageText.Text
Dim data As CopyData

' set up the data...
data.lpData = Marshal.StringToHGlobalAuto(message)
data.cbData = message.Length * Marshal.SystemDefaultCharSize

' send the data
MainForm.SendMessage(ClientWindow, MainForm.WM_COPYDATA,
Me.Handle, data)

' free the pointer...
Marshal.FreeHGlobal(data.lpData)
End If
Else
MessageBox.Show("Could Not Find Active Client Window.")
End If
End Sub
End Class

HTH,
Tom Shelton
Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Frank Bechmann | last post by:
I started to write a SciTe director in python. I had a very basic communication running in Pythonwin but I disliked the strong mixture between Pythonwin's basic functionality and the Pythonwin...
3
by: Chris | last post by:
Hi. I'm trying to make a python program that can recieve WM_COPYDATA messages. Not ideal, but the application I'll be receiving them from will only send it that way. So I wrote a small program...
3
by: The Collector | last post by:
Hi, I've been looking for almost two full days now to get full control of WinAMP using python. Simple play/stop functions are no problem. It's the WM_COPYDATA that's used by IPC_PLAYFILE (=add a...
0
by: Gordon | last post by:
Hi I tried to implement a C++ dll and a Visual Basic .net application, which is able to receive WM_COPYDATA messages from the DLL. Here's my code DLL typedef struct _TRANSTA char teststr...
3
by: **** KiteOregon **** | last post by:
How do i receive a wm_copydata message from a third party application? I can't seem to get the data or the message at all in my vb.net application, what do i need to do. thanks -- Just...
1
by: Thomas Kehl | last post by:
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...
1
by: d-42 | last post by:
Hi, I'm pretty sure I've just got a Marshalling problem, but I'm completely stumped. If there is a better newsgroup to post this in, please point me towards it. First I'm trying to use...
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: dantz | last post by:
Hi everyone, I am trying to combine WM_COPYDATA and Serialization. I am converting an object into string using Serialization then pass that string as the LParam of my COPYDATASTRUCT. I can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.