Interprocess communication

Interprocess communication

Interprocess communication between Visual Basic 6 and .NET(C#)

This is an example project to showcase interprocess communication between VB6 and .NET apps using the Windows API to send messages.

Check the repository for the full source code

https://github.com/nikosportolos/COM-Interoperability-in-.NET/tree/main/part-iii/src

Table of Contents


Getting started

Introduction

Interprocess communication (IPC) is a set of programming interfaces that allow a programmer to coordinate activities among different program processes that can run concurrently in an operating system. This allows a program to handle many user requests at the same time. Since even a single user request may result in multiple processes running in the operating system on the user’s behalf, the processes need to communicate with each other. The IPC interfaces make this possible. Each IPC method has its own advantages and limitations so it is not unusual for a single program to use all of the IPC methods. IPC methods include pipes and named pipes;message queueing;semaphores; shared memory; and sockets.

Originally posted on WhatIs.com

Windows Messages

The system passes input to a window procedure in the form of a message. Messages are generated by both the system and applications. The system generates a message at each input event—for example, when the user types, moves the mouse, or clicks a control such as a scroll bar. The system also generates messages in response to changes in the system brought about by an application, such as when an application changes the pool of system font resources or resizes one of its windows. An application can generate messages to direct its own windows to perform tasks or to communicate with windows in other applications.

The system sends a message to a window procedure with a set of four parameters:

  • a window handle,
  • a message identifier,
  • and two values called message parameters.

The window handle identifies the window for which the message is intended. The system uses it to determine which window procedure should receive the message.

A message identifier is a named constant that identifies the purpose of a message. When a window procedure receives a message, it uses a message identifier to determine how to process the message. For example, the message identifier WM_PAINT tells the window procedure that the window’s client area has changed and must be repainted.

Message parameters specify data or the location of data used by a window procedure when processing a message. The meaning and value of the message parameters depend on the message. A message parameter can contain an integer, packed bit flags, a pointer to a structure containing additional data, and so on. When a message does not use message parameters, they are typically set to NULL. A window procedure must check the message identifier to determine how to interpret the message parameters.

PostMessage function

Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.

To post a message in the message queue associated with a thread, use the PostThreadMessage function.

Source code

.NET Source code

Check the entire source code of the C# class library here: https://github.com/nikosportolos/COM-Interoperability-in-.NET/tree/main/part-iii/src/dotNET

VB6 Source code

Check the entire source code of the VB6 winform app here: https://github.com/nikosportolos/COM-Interoperability-in-.NET/tree/main/part-iii/src/VB6

References


You may also be interested in