IHTMLDocument2 get_body error
Hi all, I have this code:
Code:
void OnGetDocInterface(HWND hWnd)
{
CoInitialize( NULL );
// Explicitly load MSAA so we know if it's installed
HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
if ( hInst != NULL )
{
if ( hWnd != NULL )
{
HWND hWndChild=NULL;
// Get 1st document window
hWndChild = FindIEWindow()
if ( hWndChild )
//hWndChild contains a valid "Internet Explorer_Server" handle
{
CComPtr<IHTMLDocument2> spDoc;
LRESULT lRes;
UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") );
::SendMessageTimeout( hWndChild, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes );
LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, (char *)("ObjectFromLresult") );
if ( pfObjectFromLresult != NULL )
{
HRESULT hr;
hr = (*pfObjectFromLresult)( lRes, IID_IHTMLDocument, 0, (void**)&spDoc );
if ( SUCCEEDED(hr) )
{
// Change background color to red
spDoc->put_bgColor( CComVariant(L"red") );//this is were the program crashes*
}
}
} // else document not ready
} // else Internet Explorer is not running
::FreeLibrary( hInst );
} // else Active Accessibility is not installed
CoUninitialize();
}
-----------------
When execution gets to:
spDoc->put_bgColor( CComVariant(L"red") );
I get error:
"Unhandled exception at 0xabababab in TestApp.exe: 0xC0000005: Access violation reading location 0xabababab."
and my program crashes.
----------------------
The handle is corect and there is no error until that point.
The code is from http://support.microsoft.com/kb/249232 so it is probably corect.
I use VC++ 2008 Express Edition, I have included:
#include <Windows.h>
#include <Mshtml.h>
#include <OleAcc.h>
#include <atlbase.h>
----------------
Thx in advance :).