using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
internal static class Program
internal enum RpcAuthnLevel
internal enum RpcImpLevel
NoCustomMarshal = 0x2000,
private static Mutex mutex = new Mutex(true, "{8814ea4c-2574-4342-b8aa-d1a2cb5adb89}");
internal static extern int CoInitializeSecurity(IntPtr pVoid, int cAuthSvc, IntPtr asAuthSvc, IntPtr pReserved1, RpcAuthnLevel level, RpcImpLevel impers, IntPtr pAuthList, EoAuthnCap dwCapabilities, IntPtr pReserved3);
private static void Main()
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, RpcAuthnLevel.Default, RpcImpLevel.Identify, IntPtr.Zero, EoAuthnCap.None, IntPtr.Zero);
if (mutex.WaitOne(TimeSpan.Zero, true))
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string fileVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
LogWrap.Log("Initializing driver4vr application ver: " + fileVersion);
Type type = Type.GetType("Driver4Lib.Trevor, Driver4Lib", true);
LogWrap.Log("Initializing driver4vr: step 1");
object obj = Activator.CreateInstance(type);
LogWrap.Log("Initializing driver4vr: step 2");
string formName = DriverVersionInfo.formName;
MethodInfo method = type.GetMethod(formName);
LogWrap.Log("Initializing driver4vr: step 3");
Form mainForm = (Form)method.Invoke(obj, new object[0]);
LogWrap.Log("Initializing driver4vr: step 4");
Application.Run(mainForm);
LogWrap.Log("Shutdown of driver4vr application has been completed.");
LogWrap.Log("Fatal error. Program will be closed: " + ex.Message);
MessageBox.Show("Fatal error. Program will be closed!" + Environment.NewLine + ex.Message);
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
Exception ex = e.ExceptionObject as Exception;
string text = (ex == null) ? e.ExceptionObject.ToString() : ex.Message;
LogWrap.Log("Unhandled error. Program will be closed: " + text);
MessageBox.Show("Unhandled error. Program will be closed!" + Environment.NewLine + text);