You need to configure a bi-directional IPC interface. There are a range of different ways to implement this. What follows is one example using .NET Remoting.
First take a look at the EasyHook remote file monitor tutorial as a starting point for creating your interface to send messages from the DLL back to APP, i.e. APP <- interface <- DLL.
To allow messages from APP -> interface -> DLL, a new channel needs to be configured within the DLL IEntryPoint constructor: e.g.
#region Allow client event handlers (bi-directional IPC)
// Attempt to create a IpcServerChannel so that any event handlers on the client will function correctly
System.Collections.IDictionary properties = new System.Collections.Hashtable();
properties["name"] = channelName;
properties["portName"] = channelName + Guid.NewGuid().ToString("N"); // random portName so no conflict with existing channels of channelName
System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider binaryProv = new System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider();
binaryProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
System.Runtime.Remoting.Channels.Ipc.IpcServerChannel _clientServerChannel = new System.Runtime.Remoting.Channels.Ipc.IpcServerChannel(properties, binaryProv);
System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(_clientServerChannel, false);
#endregion
To implement the IPC from APP -> interface -> DLL take a look at the Disconnect
method and Disconnected
event within the "Client-side events" of the Direct3DHook project, CaptureInterface.Disconnect
, CaptureInterface.Disconnected
and ClientCaptureInterfaceEventProxy.Disconnected
, all in CaptureInterface.cs. In addition to the interface class, this approach also uses a client event proxy class that inherits from MarshalByRefObject
and allows an event handler to be called elsewhere in your DLL in response to the APP calling a method. You will need to take a good look at the code linked, there are some additional points of interest that need to be considered (such as event handler lifetime), the interface implements a wrapper around each event to trigger it in a "Safe" manner.
Finally the handler for the Disconnected
event is attached within the DLL's IEntryPoint
Run method:
_interface.Disconnected += _clientEventProxy.DisconnectedProxyHandler;
_clientEventProxy.Disconnected += () =>
{
// This code in the DLL will run when APP calls CaptureInterface.Disconnect
};