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

Pass data between 2 applications

Hi all,

I have 2 applications one in VB.net and the other in VC6. I need to
pass data between them. How can I do it? what's the best way to
implement such communication ?
Any comment will be appreciate.
Thank you.

Juky

Nov 17 '05 #1
3 4039
I use the RegisterWindowsMessage API. This lets you create a unique windows
message that will be common to both applications. The only catch is you need
to know the hWnd of the other application, I assume you know this or can find
it out somehow. It works like this.

long msg_connect = RegisterWindowsMessage("MyApplication.Connect");
long msg_transfer = RegisterWindowsMessage("MyApplication.Transfer");
long msg_close = RegisterWindowsMessage("MyApplication.Close");

Place something similar in the Visual Basic code. Then what I do is use
SendMessage to establish the connection.

long Accept = SendMessage(target_application_hwnd, msg_connect, 0, 0); // in
place of the zeroes you can pass pointers to structures of any relevant
information like a user name and password

The receiver will process the message by subclassing or overriding the
WndProc function. If it decides to accept the connection, it should return 1
or zero otherwise. The other application should then check this return value
which is why I assigned it to the variable Accept.

long Result = SendMessage(target_application_hwnd, msg_transfer, &data1,
&data2)

Where data1 and data2 are pointers to any information you want. To get a
pointer to memory that can be read by both applications use GlobalAlloc.

Finish by sending the msg_close instruction.
"juky" wrote:
Hi all,

I have 2 applications one in VB.net and the other in VC6. I need to
pass data between them. How can I do it? what's the best way to
implement such communication ?
Any comment will be appreciate.
Thank you.

Juky

Nov 17 '05 #2
juky wrote:
I have 2 applications one in VB.net and the other in VC6. I need to
pass data between them. How can I do it? what's the best way to
implement such communication ?


An easy way is using WM_COPYDATA. This lets you transfer an arbitrary
block of data between two applications; all marshalling and allocation
is taken care of for you.

--
Tim Robinson (MVP, Windows SDK)
http://mobius.sourceforge.net/
Nov 17 '05 #3
I have the following code in vb.net for sender and receiver. How should
Sender and Receiver look like in VC6 in order to communicate with the
code in .net ? I have problems to synchronize the 2 applications using
2 different languages.

Thanks,
Juky

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

Nov 17 '05 #4

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

Similar topics

1
by: Srini | last post by:
I am a beginner to using XML for communication between processes. I have heard about using XML for passing of information between 2 applications. We have 2 desktop applications developed in VB,...
12
by: Casey | last post by:
Yeah, I know this question was asked by someone elselike 2 weeks ago. But I need some additional help. I have a program I'm developing, and multiple different forms will be opened. For now though,...
2
by: seamoon | last post by:
ENG> How can I pass a value through CREATESTRUCT in MDI applications? How can I pass a parameter to CREATESTRUCT in VC++ MDI application. For example, Dialogue based examples can pass a value to...
1
by: Tom | last post by:
Hi, I am currently on a project where one site needs to send the user credentials to another site, through web services. Scenario: * "User 1" will authenticate to "Site A" using NTLM ("Site...
6
by: juky | last post by:
Hi all, I have 2 applications one in VB.net and the other in VC6. I need to pass data between them. How can I do it? what's the best way to implement such communication ? Any comment will be...
1
by: beachboy | last post by:
how can pass the login (security info) to secondary application? ASP.NET 1.1 user login to application 1(app1.myapp.com) with their username and password, then they have a link to application 2...
13
Frinavale
by: Frinavale | last post by:
One of the most fundamental topics in web design is understanding how to pass information collected on one web page to another web page. There are many different ways you could do this: Cookies,...
4
RedSon
by: RedSon | last post by:
I'm doing a bit of bluetooth programming and I am writing some middleware to make developing applications easier. The BT driver is implemented as a simple serial driver so its like OpenFile and...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.