Visual Basic .NET/Interprocess Communication

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Generally, each program in Windows has its own virtual memory space. In other words, one program cannot change variables in another program. Marshalling is the process of passing data and memory addresses between applications. There are several ways different programs can communicate with each other.

Shared file(s)[edit | edit source]

This is a 'roll your own' solution. Both applications access files in a shared directory, reading and writing data from them to communicate. The simplest method is for the sending application to write a separate file for each message and the receiving application to delete those files once processed. The sending application should create the file with exclusive access so the receiving application cannot access a half-written file. There should also be a mechanism for re-synchronising if one or the other application is shut down during a conversation.

The main downside of this approach is that the receiving application must poll the shared directory at regular intervals (e.g. by using a Timer control). This generates harddisk/network traffic, and the polling interval limits the responsiveness of the conversation.

Windows messages[edit | edit source]

This method consists of overriding the WndProc method in a Form to receive, and the PostMessage Win32 API call to send a custom Windows message.

.NET Remoting[edit | edit source]

This method has the advantage of easily accommodating both communication between programs on the same computer, and programs on different computers in the same network (or even across the internet). It uses the System.Runtime.Remoting namespace, which you can add via Project References.

Older methods[edit | edit source]

These methods are not used much anymore, but may be encountered if you are trying to communicate with a legacy application.

DDE[edit | edit source]

Dynamic Data Exchange was the original method Windows used for programs to communicate with each other. It is still used by Windows for "Cut and Paste".

OLE[edit | edit source]

Object Linking and Embedding

COM[edit | edit source]

Common Object Model.

  • Reference counting
  • Late binding via IDispatch

OLE Automation[edit | edit source]

OLE Automation

ActiveX[edit | edit source]

ActiveX EXEs and DLLs

See Also[edit | edit source]

[1] [2] [3]