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;
}