Windows挂钩无法在Windows8.1 IE11 x64机器上运行

时间:2014-12-08 13:15:31

标签: c++ windows internet-explorer bho

我正在使用 ATL C ++ IE 创建浏览器帮助对象。 但我的 Windows挂钩无法使用 Windows8.1 IE11 x64计算机

事情正在发挥作用 x86机器 win7,Win8,win8.1和 x64机器 WIN7

我试图调试我的代码并发现 - 当从代理进程调用SendMessage时,从代理进程(IEInjector.exe)设置的Hook不会调用主进程(IEBHO.dll)上的Windows过程。 此外,经纪人流程中没有抛出任何异常。

代码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;

}

代码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 */
        }
    }
  ---
  ---
  ---
}
-----
-----

请建议我的代码中有关Windows8.1 IE11 x64机器的错误。

0 个答案:

没有答案