描述:
MSHTML::IHTMLDocument4Ptr pDoc4;
MSHTML::IHTMLDocument2Ptr pDoc2;
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER,IID_IHTMLDocument, (void**)&pDoc4);
// HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER,IID_IHTMLDocument2, (void**)&pDoc2);
// MSHTML::IHTMLDocument2Ptr spHtmlDocument(pDocument);
if(SUCCEEDED(hr))
{
_bstr_t strurl=_bstr_t(m_url);
// _bstr_t strOptions =_bstr_t(_T(""));
HRESULT hr1=pDoc4->createDocumentFromUrl(strurl,"");
if(SUCCEEDED(hr))
{
pDoc2=pDoc4;
MSHTML::IHTMLElementCollection *pCollection;
pDoc2->get_all(&pCollection);
long len;
pCollection->get_length(&len);
for(int i = 0; i < len; i++)
{
LPDISPATCH lpItem = pCollection->item(CComVariant(i), CComVariant(i));
//Parse Button, Input, Check, Radio
MSHTML::IHTMLInputElementPtr lpElement;
HRESULT hr = lpItem->QueryInterface(&lpElement);
if(SUCCEEDED(hr))
{
_bstr_t name = lpElement->Getname();
_bstr_t type = lpElement->Gettype();
_bstr_t value = lpElement->Getvalue();
CString strName = (LPTSTR)name;
CString strType = (LPTSTR)type;
CString strValue = (LPTSTR)value;
CString str = _T("\r\n") + strName + _T(" $$$ ") + strType + _T(" $$$ ") + strValue;
//// m_pEditView->SendMessage(EM_SETSEL, -1, -1);
// m_pEditView->SendMessage(EM_REPLACESEL, 0, (LPARAM)(LPCTSTR)str);
m_list.AddString(str);
::SysFreeString(name);
::SysFreeString(type);
::SysFreeString(value);
}
}
运行时出现下面错误The value of ESP was not properly saved across a function call. This is
usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention高手帮忙呀!!!!!!!!!!!!!!!!!!!!!!
解决方案1:
应该是这样的,你的pDocument估计是 get_Document(&pDispatch)里得到的,那么就可以
pDocument->QueryInterface(IID_IHTMLDocument4,(void**)&pDoc4)
当然根据com 的特性,也可以:
pDispatch->QueryInterface(IID_IHTMLDocument4,(void**)&pDoc4)
这样就可以获得.
用IID_IHTMLDocument的ID得到IHTMLDocument4接口啊?
应该是IID_IHTMLDocument4吧?
看到一位大侠的VB代码,这样写的
pDoc4.createDocumentFromUrl("http://www.google.com","null");
另外,你的pDoc2不用CoCreateInstance啊
直接从pDoc4中QueryInterface得到
CString strName = (LPTSTR)name;
CString strType = (LPTSTR)type;
CString strValue = (LPTSTR)value;
错了,用OLE2T转
哪一行出的错?