INTERPROCESS COMMUNICATION IN VB

Method 1. Using the Clipboard - Simple but Risky.

Using the CLIPBOARD provides the easiest mode for two applications to interact with one another. One process -the SENDER- initiates the conversation by clearing the Clipboard ("Clipboard.Clear"). Then it pastes a textual message into the Clipboard ("Clipbaord.SetText myMessage"). The other application - the RECEIVER- reads the message from the Clipboard by issuing a call such as "theMessage = Clipboard.GetText". The problem with this technique is that other applications using the Clipboard could interfere with the dialog between SENDER-RECEIVER, and the message could be stolen, altered, or erased.


VB-SENDER

myMessage = "Hola Amigos 123"
Clipboard.Clear
clipboard.SetText myMessage / VB-RECEIVER

theMessage = Clipboard.GetText
' here we hope to get "Hola Amigos 123"
...


Private Sub cmdStart_Click()
On Error Resume Next
Dim TaskId As Double
TaskId = Shell(App.Path & "\RECEIVER.exe ", _
vbNormalFocus)
Clipboard.Clear
Clipboard.SetText TaskId
txtTaskID = TaskId
AppActivate TaskId, False
End Sub / Private Sub cmdCapture_Click()
Dim taskID As Double
taskID = Clipboard.GetText
txtTaskID = taskID
End Sub

Method 2. SendKey Command

Asynchronous communications using a master/slave mode. The SENDER activates the RECEIVER using a "Shell" command. The task ID can be used to activate the other application. The "SendKeys" command is used to transmit the message (char by char) to the destination.

This method is more reliable than Method-1, however it is asynchronous, and messages may not arrive right away. The destination needs to acknowledge the message somehow for the sender to know that the message has arrived.

X = shell("TheReceiver.exe ", 3)
AppActivate X
SendKeys "Hola 123" & "{TAB}", True
… / …
'This process collects the message
'a textbox , say Text1.Text

Method 3. Command Function

Asynchronous communications using a one-way Sender-to-Receiver mode. The SENDER activates the RECEIVER using a "Shell" command. Arguments are supplied at this point from the sender in the execution-line.

This method is reliable. The destination needs to parse and decode the argument list to obtain the different tokens arriving in the list. This technique could be used to make an MS-Access form call a VB-program, or a VB-program call another executable program.

‘SENDER
myArgs = “aa bb 123 etc”
X = shell("TheReceiver.exe " & myArgs)
… / ‘RECEIVER
private sub Form_Load()
'This process collects the message
myInputArgs = Command()