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.