This example can be found in Development\examples\csharp\sharedmemory\sharedmemory.cs
.
This example shows how to activate the shared memory communication pipeline that enables communication of the PST Client application through the PST SDK. Note that for the shared memory pipeline to function, the application has to run with elevated access (administrator rights). After enabling shared memory, the PST Client application can be used to download calibration information and manage tracking targets.
When compiling and running this example, please make sure that the required dependencies can be found by the executable (e.g. by copying the Development\Redist
directory into the build directory).
using System;
using System.Runtime.InteropServices;
using System.Threading;
namespace PSTech.SharedMemory
{
public class SharedMemory
{
[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(ConsoleEventHandler handler, bool add);
private delegate bool ConsoleEventHandler(CtrlType sig);
static ConsoleEventHandler ConsoleCtrlEventHandler;
public enum CtrlType
{
CtrlCEvent = 0,
CtrlBreakEvent = 1,
CtrlCloseEvent = 2,
CtrlLogOffEvent = 5,
CtrlShutdownEvent = 6,
}
private static bool ConsoleHandler(CtrlType sig)
{
Exithandler((int)sig);
return true;
}
static void Exithandler(int sig)
{
Tracker.DisableSharedMemory();
Tracker.Shutdown();
Environment.Exit(0);
}
static int Main(string[] args)
{
ConsoleCtrlEventHandler += new ConsoleEventHandler(ConsoleHandler);
SetConsoleCtrlHandler(ConsoleCtrlEventHandler, true);
try
{
Tracker tracker = new Tracker();
tracker.StartTracker();
Tracker.EnableSharedMemory();
Console.Write("Shared memory server initialized. Start the PST Client application to create a connection.\n");
Thread.Sleep(60000);
Tracker.DisableSharedMemory();
}
{
Console.Write(e + "\n");
}
finally
{
Tracker.Shutdown();
}
return 0;
}
}
}