This project is read-only.


VS2010, Windows 7 PRO - Error


Everything looks ok in design mode, but whenever I've tried to run project I get this exception :
File: GlobalHook.cs, Line: 446
Win32Exception was unhandled
Invalid window handle.

file attachments

Closed May 16, 2013 at 1:22 PM by adriancs
Please visit the new development site.


isotoxin wrote Aug 2, 2010 at 9:20 AM

OK, I get rid of that crap. But now I've got rendering problems. See attached screenshot.

bpell wrote Nov 22, 2010 at 8:01 PM

I don't know if this helps or not, but I commented out that line that throws the exception and the Ribbon appears to work fine, or at least I haven't run into any scenarios yet that are problematic.

wrote Mar 6, 2011 at 9:46 AM

saamorim wrote Dec 27, 2011 at 10:45 PM

Hi. Actually there is a solution for this posted on the codeproject page ( Credits foes to han6man.

On the GlobalHook.cs file

using System.Diagnostics;

replace InstallHook with

/// <summary>
    /// Installs the actual unsafe hook
    /// </summary>
    private void InstallHook()
        /// Error check
        if (Handle != 0) throw new Exception("Hook is already installed");

        #region htype
        int htype = 0;

        switch (HookType)
            case HookTypes.Mouse:
                htype = WinApi.WH_MOUSE_LL;
            case HookTypes.Keyboard:
                htype = WinApi.WH_KEYBOARD_LL;
                throw new Exception("HookType is not supported");

        /// Delegate to recieve message
        _HookProc = new HookProcCallBack(HookProc);

        /// Hook
        _hHook = WinApi.SetWindowsHookEx(htype, _HookProc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
        _hHook = WinApi.SetWindowsHookEx(htype, _HookProc, GetCurrentModule().BaseAddress, 0);

        /// Error check
        if (Handle == 0) throw new Win32Exception(Marshal.GetLastWin32Error());
add the method:

public static ProcessModule GetCurrentModule()
        // need instance handle to module to create a system-wide hook
        Module[] list = System.Reflection.Assembly.GetExecutingAssembly().GetModules();
        System.Diagnostics.Debug.Assert(list != null && list.Length > 0);

        var currentProcess = Process.GetCurrentProcess();
        var modules = currentProcess.Modules;
        ProcessModule mod = null;
        foreach (ProcessModule m in modules)
            //for .net 2 we will find module here
            if (m.ModuleName == list[0].Name)
                mod = m;
        //for .net 4 take current module
        if (mod == null)
            mod = Process.GetCurrentProcess().MainModule;

        return mod;

adriancs wrote Apr 29, 2012 at 2:21 AM

dont inherit RibbonForm

adriancs wrote Apr 29, 2012 at 2:21 AM

Dont inherit RibbonForm

wrote Feb 22, 2013 at 12:18 AM

adriancs wrote May 16, 2013 at 1:19 PM

Hi, new version of Ribbon had released. Please visit the new development site of this project for latest fixes, info and downloads.
New site:

wrote May 16, 2013 at 1:22 PM