到网上找了个通过Internet Explorer_Server 句柄得到IHTMLDocument2的代码,在vc6里面编译通过,而且可以用,但是搬到2005里面就不行,总是得不到头文件按照vc6的demo设置了,下面贴出了出问题的部分代码,小弟初学VC,还望高手指教....问题就出在下面代码中 if (SUCCEEDED(hr) ) 部分,这个判断在2005里面过不去....
// mfc_test_dragDlg.cpp : 实现文件
//#include "stdafx.h"
#include "mfc_test_drag.h"
#include "mfc_test_dragDlg.h"#include <atlbase.h>
#include <oleacc.h>
#include <winuser.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif/////////////////////////////////////////////////////////////////////////////
// CGetIhtmlDlg dialog
//You can store the interface pointer in a member variable
//for easier access
//Modified by Chu Fang
/*函数名:GetDocInterface
参数:hWnd,WebBrowser控件的窗口句柄
功能:通过WM_HTML_GETOBJECT取得控件的IHTMLDocument2接口
*/
IHTMLDocument2* GetDocInterface(HWND hWnd)
{
// 我们需要显示地装载OLEACC.DLL,这样我们才知道有没有安装MSAA
HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
IHTMLDocument2* pDoc2=NULL;
if ( hInst != NULL ){
if ( hWnd != NULL ){
CComPtr<IHTMLDocument> spDoc=NULL;
LRESULT lRes; UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") );
::SendMessageTimeout( hWnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes ); LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, LPCSTR("ObjectFromLresult") );
if ( pfObjectFromLresult != NULL ){
HRESULT hr;
hr=pfObjectFromLresult(lRes,IID_IHTMLDocument,0,(void**)&spDoc);
//★问题出在这个判断上,vs2005里面过不去,vc6可以
if (SUCCEEDED(hr) ){
CComPtr<IDispatch> spDisp;
CComQIPtr<IHTMLWindow2> spWin;
spDoc->get_Script( &spDisp );
spWin = spDisp;
spWin->get_document( &pDoc2 );
}
}
}
::FreeLibrary(hInst);
}
else{//如果没有安装MSAA
AfxMessageBox(_T("请您安装Microsoft Active Accessibility"));
}
return pDoc2;
}
// mfc_test_dragDlg.cpp : 实现文件
//#include "stdafx.h"
#include "mfc_test_drag.h"
#include "mfc_test_dragDlg.h"#include <atlbase.h>
#include <oleacc.h>
#include <winuser.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif/////////////////////////////////////////////////////////////////////////////
// CGetIhtmlDlg dialog
//You can store the interface pointer in a member variable
//for easier access
//Modified by Chu Fang
/*函数名:GetDocInterface
参数:hWnd,WebBrowser控件的窗口句柄
功能:通过WM_HTML_GETOBJECT取得控件的IHTMLDocument2接口
*/
IHTMLDocument2* GetDocInterface(HWND hWnd)
{
// 我们需要显示地装载OLEACC.DLL,这样我们才知道有没有安装MSAA
HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
IHTMLDocument2* pDoc2=NULL;
if ( hInst != NULL ){
if ( hWnd != NULL ){
CComPtr<IHTMLDocument> spDoc=NULL;
LRESULT lRes; UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") );
::SendMessageTimeout( hWnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes ); LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, LPCSTR("ObjectFromLresult") );
if ( pfObjectFromLresult != NULL ){
HRESULT hr;
hr=pfObjectFromLresult(lRes,IID_IHTMLDocument,0,(void**)&spDoc);
//★问题出在这个判断上,vs2005里面过不去,vc6可以
if (SUCCEEDED(hr) ){
CComPtr<IDispatch> spDisp;
CComQIPtr<IHTMLWindow2> spWin;
spDoc->get_Script( &spDisp );
spWin = spDisp;
spWin->get_document( &pDoc2 );
}
}
}
::FreeLibrary(hInst);
}
else{//如果没有安装MSAA
AfxMessageBox(_T("请您安装Microsoft Active Accessibility"));
}
return pDoc2;
}
解决方案 »
- MoveWindow函数
- 非常急!!!有使用HGE做游戏的师兄进
- 100分求助,请问怎么控制radio button?
- VBScript中的Set keysobj= CreateObject("wmrmobjs.WMRMKeys")用vc来写该怎么写?
- 主菜单操作的问题
- 一个DerectX方面的问题!!!!!!!!!
- 将字符串作为PostMessage参数传递的问题?
- C2146是什么错误?
- 小弟刚学VC++两天,做“hello world”窗口,好不容易编译过了,可是调试时却出了一堆东西,还请大侠帮忙。
- 有关行间距的问题。。。送分~~~~!!
- WEB页面连结本地access数据库的不同方案选择
- ATL下怎么用try catch(CException *e)编译通不过
===================
vs2005里面监视不到,说是未找到符号,但是vc6里面是0
调试环境中应该可以看到hr的值吧。或者用MessageBox显示出来,以Hex方式。
hr=pfObjectFromLresult(lRes,IID_IHTMLDocument,0,(void**)&spDoc);加一句
spDoc.Release();VC6.0 会自动释放, 后面的版本需要自己Release
在Cmfc_test_dragDlg::OnInitDialog()加上CoInitialize(NULL);//加上
在Cmfc_test_dragDl销毁时调用CoUninitialize();