|
-
July 26th, 2009, 06:45 PM
#1
MFC: Sign in and get web page source
Hi everybody
I need to submit a form in the web page.
I need to:
1. Sign in.
2. Fill in all required fields and submit the form.
I'm using IWebBrowser interface, and I know how to submit form using IHTMLDOcument2 interface. But I don't want the IWebBrowser display the web page itself(I should use as low bandwidth as possible). How I can eliminate the downloading of images and also get the IHTMLDocument as fast as possible?
I could use CInternetSession::OpenURL(_T("http://something.com"));
But then I cannot get the IHTMLDcocument2 interface, therefore cannot submit the form.
Thank you.
-
July 27th, 2009, 04:12 PM
#2
Re: MFC: Sign in and get web page source
I think I found solution:
Thanks to this article: http://www.codeguru.com/cpp/i-n/iepr...cle.php/c4385/
I made this function based on that article:
Code:
BOOL CWebBrowsingDlg::GetHtmlDoc(LPCTSTR source, IHTMLDocument2* &result){
IHTMLDocument2* pDoc=NULL;
HRESULT hr=NULL;
if(!SUCCEEDED(CoInitialize(NULL))) return FALSE;
hr=CoCreateInstance(CLSID_HTMLDocument,NULL,CLSCTX_INPROC_SERVER,IID_IHTMLDocument2,(LPVOID*)&pDoc);
if (SUCCEEDED(hr)&&pDoc){
IPersistStreamInit* pPersist=NULL;
hr=pDoc->QueryInterface(IID_IPersistStreamInit,(LPVOID*)&pPersist);
if (SUCCEEDED(hr)&&pPersist){
IMarkupServices* pMS=NULL;
pPersist->InitNew();
pPersist->Release();
hr=pDoc->QueryInterface(IID_IMarkupServices,(LPVOID*)&pMS);
if (SUCCEEDED(hr)&&pMS){
IMarkupContainer* pMC=NULL;
IMarkupPointer* pMkStart=NULL;
IMarkupPointer* pMkFinish=NULL;
pMS->CreateMarkupPointer(&pMkStart);
pMS->CreateMarkupPointer(&pMkFinish);
hr=pMS->ParseString((BSTR)source,0,&pMC,pMkStart,pMkFinish);
if (SUCCEEDED(hr)&&pMC){
IHTMLDocument2* pDoc2=NULL;
hr=pMC->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&pDoc2);
if (SUCCEEDED(hr)&&pDoc2){
result=pDoc2; //...
pDoc2->Release();
}else{
pMC->Release();
pMS->Release();
pDoc->Release();
return FALSE;
}
pMC->Release();
}else{
pMS->Release();
pDoc->Release();
return FALSE;
}
pMS->Release();
}else{
pDoc->Release();return FALSE;
}
}else{
pDoc->Release();return FALSE;
}
pDoc->Release();
}else{return FALSE;}
CoUninitialize();
return TRUE;
}
The Function is returnting TRUE, but I cannot access the pDoc(IHTMLDocument2 interface):
Code:
...
IHTMLDocument2* pDoc=NULL;
if (GetHtmlDoc(src,pDoc)&&pDoc){
BSTR s;
HRESULT hr=pDoc->get_title(&s); //I'm getting on this line.
if (SUCCEEDED(hr)){
AfxMessageBox(CString(s));
}
}
I'm getting this error:
Unhandled exception at 0x004f847e in WebBrowsing.exe: 0xC0000005: Access violation reading location 0xfeeeff32.
I think I defined my function wrong.
Please help me out.
Thank you.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|