Click here to Skip to main content
15,889,909 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhide a dialog on task bar. Pin
chandu0043-Jul-09 19:12
chandu0043-Jul-09 19:12 
AnswerRe: hide a dialog on task bar. Pin
enhzflep3-Jul-09 19:30
enhzflep3-Jul-09 19:30 
QuestionSend values from Exe to Browser Pin
tgm.arjun093-Jul-09 16:59
tgm.arjun093-Jul-09 16:59 
AnswerRe: Send values from Exe to Browser Pin
David Crow3-Jul-09 17:35
David Crow3-Jul-09 17:35 
AnswerRe: Send values from Exe to Browser Pin
Hamid_RT4-Jul-09 0:00
Hamid_RT4-Jul-09 0:00 
QuestionConstructor Exception Pin
hpjchobbes3-Jul-09 9:08
hpjchobbes3-Jul-09 9:08 
AnswerRe: Constructor Exception Pin
Stuart Dootson3-Jul-09 9:26
professionalStuart Dootson3-Jul-09 9:26 
QuestionIE automation [modified] Pin
eoloe3-Jul-09 8:08
eoloe3-Jul-09 8:08 
I'm trying to automate IE. That piece of code works fine on my VC++ desktop computer with vista and IE8. The problem is it's not working on my laptop (vista + IE7). There is no error message. According to the messageboxes, the code stops when trying to get the READYSTATE statement. I mean I got the first messagebox ("navigation ...") but not the second one ("readystate ..."). Plus the browser doesn't close as it is supposed to do.

I don't know if it's related but I compiled the project using the /MT command and I didn't install the Visual C++ 2008 Redistributable Package (x86) on the laptop. This is because I want to run this code as a single exe.

Can please someone help me to understand wht is going on ?

Here is my code :

#include "stdafx.h"
#include "Exdisp.h"
#include "mshtml.h"
#include "windows.h"
#include "winerror.h"



int _tmain(int argc, _TCHAR* argv[])
{
if (SUCCEEDED(OleInitialize(NULL)))
  {
    IWebBrowser2*    pBrowser2;
	IHTMLDocument2*  Doc;
	IDispatch* pHtmlDispatch;
	READYSTATE rState;
	DWebBrowserEvents2* pEvents;
	HRESULT hr;

   CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, 
                       IID_IWebBrowser2, (void**)&pBrowser2);
   if (pBrowser2)
     {
			
		VARIANT vEmpty;
		VariantInit(&vEmpty);

		BSTR bstrURL = SysAllocString(L"http://www.google.com");

		hr = pBrowser2->Navigate(bstrURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);
		if (SUCCEEDED(hr))
        {
			MessageBox(NULL, TEXT("Navigation successful"),TEXT("Status"),MB_OK);
			pBrowser2->put_Visible(VARIANT_TRUE);
			
		   
			
			do
			{
				hr = pBrowser2->get_ReadyState(&rState);
			}while(hr == S_OK && rState != READYSTATE_COMPLETE);
			
			MessageBox(NULL, TEXT("ReadyState Complete"),TEXT("Status"),MB_OK);
         }
      
       SysFreeString(bstrURL);


       hr = pBrowser2->get_Document(&pHtmlDispatch);
	    if (SUCCEEDED(hr) && (pHtmlDispatch != NULL)) 
         {
			MessageBox(NULL, TEXT("Dispatch obtained"),TEXT("Status"),MB_OK);
			hr = pHtmlDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&Doc);
			if (SUCCEEDED (hr) && (Doc != NULL))
			{
				MessageBox(NULL, TEXT("Document obtained"),TEXT("Status"),MB_OK);
				




				Doc->Release();
			}
			else
			{
				return hr;
			}
			pHtmlDispatch->Release();
        }
		else
		{
			return hr;
		}


		pBrowser2->Quit();
		pBrowser2->Release();
     }

   OleUninitialize();
  }

	return 0;
}


modified on Friday, July 3, 2009 2:40 PM

AnswerRe: IE automation Pin
Stuart Dootson3-Jul-09 8:47
professionalStuart Dootson3-Jul-09 8:47 
Questionsimple template question Pin
minkowski3-Jul-09 6:53
minkowski3-Jul-09 6:53 
QuestionRe: simple template question Pin
CPallini3-Jul-09 7:56
mveCPallini3-Jul-09 7:56 
AnswerRe: simple template question Pin
Stuart Dootson3-Jul-09 8:39
professionalStuart Dootson3-Jul-09 8:39 
QuestionSockets trouble in Visual Studio 2008 Pin
Manmohan293-Jul-09 5:07
Manmohan293-Jul-09 5:07 
AnswerRe: Sockets trouble in Visual Studio 2008 Pin
«_Superman_»3-Jul-09 5:10
professional«_Superman_»3-Jul-09 5:10 
AnswerRe: Sockets trouble in Visual Studio 2008 Pin
Stuart Dootson3-Jul-09 5:31
professionalStuart Dootson3-Jul-09 5:31 
GeneralRe: Sockets trouble in Visual Studio 2008 Pin
Manmohan293-Jul-09 9:10
Manmohan293-Jul-09 9:10 
GeneralRe: Sockets trouble in Visual Studio 2008 Pin
Stuart Dootson3-Jul-09 9:21
professionalStuart Dootson3-Jul-09 9:21 
GeneralRe: Sockets trouble in Visual Studio 2008 Pin
Manmohan293-Jul-09 9:39
Manmohan293-Jul-09 9:39 
GeneralRe: Sockets trouble in Visual Studio 2008 Pin
Stuart Dootson3-Jul-09 9:53
professionalStuart Dootson3-Jul-09 9:53 
GeneralRe: Sockets trouble in Visual Studio 2008 Pin
Manmohan293-Jul-09 10:21
Manmohan293-Jul-09 10:21 
GeneralRe: Sockets trouble in Visual Studio 2008 Pin
Stuart Dootson3-Jul-09 10:28
professionalStuart Dootson3-Jul-09 10:28 
GeneralRe: Sockets trouble in Visual Studio 2008 Pin
Stuart Dootson3-Jul-09 10:31
professionalStuart Dootson3-Jul-09 10:31 
GeneralRe: Sockets trouble in Visual Studio 2008 Pin
Manmohan293-Jul-09 10:48
Manmohan293-Jul-09 10:48 
GeneralRe: Sockets trouble in Visual Studio 2008 Pin
SquiZZlo31-Aug-09 14:48
SquiZZlo31-Aug-09 14:48 
AnswerRe: Sockets trouble in Visual Studio 2008 Pin
SquiZZlo1-Sep-09 5:11
SquiZZlo1-Sep-09 5:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.