static internal void PostQuitMessage(int nExitCode)
 {
     try
     {
         UnSafeNativeMethods.PostQuitMessage(nExitCode);
     }
     catch (System.Exception ex)
     {
         OnWin32Error(ex);
     }
 }
 static internal System.IntPtr CreateWindowEx(int dwExStyle, string lpszClassName, string lpszWindowName, int style, int x, int y, int width, int height, System.IntPtr hWndParent, System.IntPtr hMenu, System.IntPtr hInst, [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.AsAny)] object pvParam)
 {
     System.IntPtr result = System.IntPtr.Zero;
     try
     {
         result = UnSafeNativeMethods.CreateWindowEx(dwExStyle, lpszClassName, lpszWindowName, style, x, y, width, height, hWndParent, hMenu, hInst, pvParam);
     }
     catch (System.Exception ex)
     {
         OnWin32Error(ex);
         result = System.IntPtr.Zero;
     }
     return(result);
 }
 static internal System.IntPtr GetForegroundWindow()
 {
     System.IntPtr result = System.IntPtr.Zero;
     try
     {
         result = UnSafeNativeMethods.GetForegroundWindow();
     }
     catch (System.Exception ex)
     {
         OnWin32Error(ex);
         result = System.IntPtr.Zero;
     }
     return(result);
 }
 static internal System.IntPtr DefWindowProc(System.IntPtr hWnd, int msg, System.IntPtr wParam, System.IntPtr lParam)
 {
     System.IntPtr result = System.IntPtr.Zero;
     try
     {
         result = UnSafeNativeMethods.DefWindowProc(hWnd, msg, wParam, lParam);
     }
     catch (System.Exception ex)
     {
         OnWin32Error(ex);
         result = System.IntPtr.Zero;
     }
     return(result);
 }
    static internal short RegisterClass(WNDCLASS wc)
    {
        short result = -1;

        try
        {
            result = UnSafeNativeMethods.RegisterClass(wc);
        }
        catch (System.Exception ex)
        {
            OnWin32Error(ex);
            result = -1;
        }
        return(result);
    }
    static internal int GetRawInputDeviceList(System.IntPtr pRawInputDeviceList, ref int uiNumDevices, int cbSize)
    {
        int result = -1;

        try
        {
            result = UnSafeNativeMethods.GetRawInputDeviceList(pRawInputDeviceList, ref uiNumDevices, cbSize);
        }
        catch (System.Exception ex)
        {
            OnWin32Error(ex);
            result = -1;
        }
        return(result);
    }
    static internal int GetRawInputData(System.IntPtr hRawInput, RawInputCommand uiCommand, System.IntPtr pData, ref int pcbSize, int cbSizeHeader)
    {
        int result = -1;

        try
        {
            result = UnSafeNativeMethods.GetRawInputData(hRawInput, uiCommand, pData, ref pcbSize, cbSizeHeader);
        }
        catch (System.Exception ex)
        {
            OnWin32Error(ex);
            result = -1;
        }
        return(result);
    }
    static internal bool TranslateMessage([System.Runtime.InteropServices.In(), System.Runtime.InteropServices.Out()]
                                          ref MSG msg)
    {
        bool result = false;

        try
        {
            result = UnSafeNativeMethods.TranslateMessage(ref msg);
        }
        catch (System.Exception ex)
        {
            OnWin32Error(ex);
            result = false;
        }
        return(result);
    }
    static internal int GetMessage([System.Runtime.InteropServices.In(), System.Runtime.InteropServices.Out()]
                                   ref MSG msg, System.IntPtr hWnd, int uMsgFilterMin, int uMsgFilterMax)
    {
        int result = -1;

        try
        {
            result = UnSafeNativeMethods.GetMessage(ref msg, hWnd, uMsgFilterMin, uMsgFilterMax);
        }
        catch (System.Exception ex)
        {
            OnWin32Error(ex);
            result = -1;
        }
        return(result);
    }
    static internal int DispatchMessage([System.Runtime.InteropServices.In()]
                                        ref MSG msg)
    {
        int result = -1;

        try
        {
            result = UnSafeNativeMethods.DispatchMessage(ref msg);
        }
        catch (System.Exception ex)
        {
            OnWin32Error(ex);
            result = -1;
        }
        return(result);
    }
    static internal int GetRawInputDeviceInfo(System.IntPtr hDevice, int uiCommand, [System.Runtime.InteropServices.In()]
                                              [System.Runtime.InteropServices.Out()]
                                              [System.Runtime.InteropServices.Optional()] System.IntPtr pData, [System.Runtime.InteropServices.In()]
                                              [System.Runtime.InteropServices.Out()]
                                              ref int pcbSize)
    {
        int result = -1;

        try
        {
            result = UnSafeNativeMethods.GetRawInputDeviceInfo(hDevice, uiCommand, pData, ref pcbSize);
        }
        catch (System.Exception ex)
        {
            OnWin32Error(ex);
            result = -1;
        }
        return(result);
    }
    static internal bool RegisterRawInputDevices([System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPArray, SizeParamIndex = 0)]
                                                 RAWINPUTDEVICE[] pRawInputDevices, int uiNumDevices, int cbSize)
    {
        bool result = false;

        try
        {
            result = UnSafeNativeMethods.RegisterRawInputDevices(pRawInputDevices, uiNumDevices, cbSize);
            if (!result)
            {
                OnWin32Error(new System.Exception("Native Method RegisterRawInputDevices returned False"));
            }
        }
        catch (System.Exception ex)
        {
            OnWin32Error(ex);
            result = false;
        }
        return(result);
    }
    static internal bool PostMessage(System.IntPtr hWnd, int Msg, int wParam, long lParam)
    {
        System.Diagnostics.Debug.WriteLine(hWnd.ToString("X16") + " : " + Msg.ToString("X16") + " : " + wParam.ToString("X16") + " : " + lParam.ToString("X16"));
        x = x + 1;
        if (x == 30)
        {
            System.Diagnostics.Debug.WriteLine("---------");
        }
        bool result = false;

        try
        {
            result = UnSafeNativeMethods.PostMessage(hWnd, (uint)Msg, wParam, lParam);
        }
        catch (System.Exception ex)
        {
            OnWin32Error(ex);
            result = false;
        }
        return(result);
    }