1

I am creating a Browser Helper Object for IE using the ATL and C++. But my Windows hook is not working on Windows8.1 IE11 x64 machine.

Things are working for x86 machine win7, Win8, win8.1 and x64 machine win7

I tried to debug my code and found that- The Hook set from the broker process(IEInjector.exe), does not call the Windows procedure on the main process(IEBHO.dll), when SendMessage is called from the broker process. Also, There is no exception thrown inside broker process.

code IEInjector.cpp

#include <Windows.h>
#include <stdlib.h>

    typedef LRESULT (CALLBACK *PHOOKCALLWNDPROCRET)( int nCode, WPARAM wParam, LPARAM lParam   );
    PHOOKCALLWNDPROCRET g_pHookCallWndProcRet;
    UINT g_uiRegisteredMsg;

    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, char * pszCommandLine, int )
    {


    HWND hWndIEFrame = (HWND)atoi( pszCommandLine );

    wchar_t szFullPath[ MAX_PATH ];
    DWORD dwCopied = GetModuleFileName( NULL, szFullPath, sizeof( szFullPath ) / sizeof( wchar_t ) );
    if ( dwCopied == 0 ) {
        wchar_t szError[ 16 ];
        _ltow_s( GetLastError(), szError, 10 );
        MessageBox( NULL, szError, L"Injector GetModuleFileName Error", NULL );
    } else {
        wchar_t * pLastAntiSlash = wcsrchr( szFullPath, L'\\' );
        if ( pLastAntiSlash ) *( pLastAntiSlash + 1 ) = 0;
        wcscat_s( szFullPath, L"IEBHO.dll" );
        g_hDll = LoadLibrary( szFullPath );
        if ( g_hDll == 0 ) {
            wchar_t szError[ 16 ];
            _ltow_s( GetLastError(), szError, 10 );
            MessageBox( NULL, szError, L"Injector LoadLibrary Error", NULL );
        } else {
            g_pHookCallWndProcRet = (PHOOKCALLWNDPROCRET)GetProcAddress( g_hDll, "HookCallWndProcRet" );
            if ( g_pHookCallWndProcRet == 0 ) {
                wchar_t szError[ 16 ];
                _ltow_s( GetLastError(), szError, 10 );
                MessageBox( NULL, szError, L"Injector GetProcAddress Error", NULL );
            } else {
                g_uiRegisteredMsg = RegisterWindowMessage( L"BHO_MSG" );
                if ( g_uiRegisteredMsg == 0 ) {
                    MessageBox( NULL, L"RegisterWindowMessage Failed", L"Injector", NULL );
                } else {
                    DWORD dwTID = GetWindowThreadProcessId( hWndIEFrame, NULL );
                    HHOOK hHook = SetWindowsHookEx( WH_CALLWNDPROCRET, g_pHookCallWndProcRet, g_hDll, dwTID );
                    if ( hHook == 0 ) {
                        MessageBox( NULL, L"SetWindowsHookEx Failed", L"Injector", NULL );
                    } else {
                        SendMessage( hWndIEFrame, g_uiRegisteredMsg, 0, reinterpret_cast<LPARAM>( hWndIEFrame ) );
                        UnhookWindowsHookEx( hHook );
                    }
                }
            }
        }
    }

    if ( g_hDll ) FreeLibrary( g_hDll );
    return 0;

}

code IEBHO.cpp

----
----
LRESULT CALLBACK CIEBHO::HookCallWndProcRet( int nCode, WPARAM wParam, LPARAM lParam ) {

if ( nCode == HC_ACTION ) {
    PCWPRETSTRUCT pcwprets = reinterpret_cast<PCWPRETSTRUCT>( lParam );
    if ( pcwprets && ( pcwprets->message == WM_COMMAND ) ) {
        if ( LOWORD( pcwprets->wParam ) == 4242 ) {
            /* do something */
        }
    }
  ---
  ---
  ---
}
-----
-----

Please suggest what could be wrong in my code with respect to Windows8.1 IE11 x64 machine.

  • Smells like tuna rotting in the Sun. No need to use hooking here. Once the BHO is started you can use a wide variety of IPC methods to communicate between it and your process. You could even create an out of process COM object that is managed by your app and created by the bHO to invoke functionality inside the server. – Captain Obvlious Dec 08 '14 at 13:20
  • I've had issues previously with IE Enhanced Protected Mode preventing my BHO from performing certain actions. As a test it could be worth disabling that but I wouldn't suggest that as a fix. However, as @CaptainObvlious suggests, you shouldn't need to use hooking here. – Ralara Dec 08 '14 at 13:25
  • i have use the [link](http://stackoverflow.com/questions/21364178/add-browser-action-button-in-internet-explorer-bho?lq=1) reference for the BHO implementation. – Prakash Raj Dec 08 '14 at 13:40
  • I am new to COM and BHO please provide some details about **IPC methods** and **out of process COM object**. @ [Captain Obvlious](https://stackoverflow.com/users/845568/captain-obvlious) – Prakash Raj Dec 08 '14 at 13:44
  • I know that code :-) You "SendMessage" the g_uiRegisteredMsg message (Is that a WM_NULL, "0" message?) Your Hook procedure tests for WM_COMMAND... Please clarify. – manuell Dec 27 '14 at 15:58

0 Answers0