PointerDeviceDriver.WindowsHook.CanSetWindowsHook C# (CSharp) Method

CanSetWindowsHook() static private method

Returns true if the hook can be set, false if it can't be set.
static private CanSetWindowsHook ( HookType type, string &errorMessage ) : bool
type HookType
errorMessage string
return bool
        internal static bool CanSetWindowsHook( HookType type, out string errorMessage )
        {
            errorMessage = null;
            try
            {
                using( Process curProcess = Process.GetCurrentProcess() )
                {
                    using( ProcessModule curModule = curProcess.MainModule )
                    {
                        IntPtr hookHandle = Win32Wrapper.SetWindowsHookEx(
                            type,
                            delegate( int code, IntPtr wParam, IntPtr lParam ) { return 0; },
                            Win32Wrapper.GetModuleHandle( curModule.ModuleName ), 0 );

                        if( hookHandle != null )
                        {
                            Win32Wrapper.UnhookWindowsHookEx( hookHandle.ToInt32() );
                            return true;
                        }
                        errorMessage = "SetWindowsHookEx returned null.";
                    }
                }
            }
            catch( Exception ex )
            {
                errorMessage = ex.Message;
            }
            return false;
        }