Game Development Reference
What Microsoft.NET Should Provide
There are a couple mechanisms that Microsoft.NET should provide that are only
accessible through unmanaged Interop.
A common IPC mechanism that exists on the majority of modern operating sys-
tems is referred to as a pipe. Windows has named pipes, which are one-way or
duplex for communication between a pipe server and one-to-many pipe clients.
All instances of a named pipe share the same name, though each instance has a
reserved and separate set of buffers and handles. Any process can function as both
a server and a client, which allows for peer-to-peer communication. Named pipes
can also provide communication between processes on the same machine or
between processes across a network.
Named pipes can be accessed by any process, making them ideal candidates for
simple communication between related or unrelated processes. Named pipes are
also much more efficient than Remoting when using chatty calls, as named pipes
avoid binary serialization. Named pipes are not natively supported by Microsoft.NET,
so developers must resort to legacy Interop in order to use them.
A simple communication method that Win32 applications can use to send data
between processes is the WM_COPYDATA message in the Windows API. WM_COPYDATA
runs at a low level, so it is capable of sending data between process address spaces.
This message is very useful for sending data between applications, but it requires
cooperation between the sending and receiving applications. Both applications
must know the format of the data being sent, and must respond to it appropriate-
ly. The sender must ensure that it does not modify any data referenced by point-
ers sent to receiving applications, and any pointers used must be accessible from
any application. This means that you cannot send a pointer that references mem-
ory in the local address space of the sender application.
Building a Wrapper Around WM_COPYDATA
WM_COPYDATA is not natively supported by Microsoft.NET, so it is only accessible
through Platform Invocation Services. The remainder of this chapter will focus on
sending and receiving data between managed and unmanaged applications.