Solved

Strange behavior of CoCreateInstance

Posted on 2004-09-03
8
595 Views
Last Modified: 2013-11-20
Hi,

In my code, I use following code to invoke IE to hit a remote web application. Of course, I'd like to have the IE window invisible.

CoInitialize(NULL);
CoCreateInstance(CLSID_InternetExplorer,NULL,CLSCTX_SERVER,IID_IWebBrowserApp,(LPVOID*)&pWBApp);
pWBApp->put_Visible(VARIANT_FALSE);
pWBApp->Navigate(bsURL,&vFlags,&vTargetFrameName,&vPostData,&vHeaders);
Sleep(2000);
pWBApp->Release();

However, by doing this, the web application will not be able to read/set cookies

I did a small test, I changed
pWBApp->put_Visible(VARIANT_FALSE);
to
pWBApp->put_Visible(VARIANT_TRUE);
By doing this, an IE window will be opened and the web application will be able read/set cookies.

So, is there any way that I can hide the IE window and read/set cookie in the web application?

Thanks.
0
Comment
Question by:ubiwebdev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 5

Expert Comment

by:Nass89
ID: 11979498
Hi,
I tested your codes under Win98 and PWS. The cookies read/write is OK with
 pWBApp->put_Visible(VARIANT_FALSE);
I added  a message box and it displayes the cookies.

Sending  some codes mabe usefull.

Good Luck!
0
 

Author Comment

by:ubiwebdev
ID: 12006237
Thanks Nass89.

I am using XP with SP1.

Well, how do you add a message box? In your web application or in the C++ application? My problem is that my web application can't read cookie.
0
 
LVL 5

Expert Comment

by:Nass89
ID: 12032683
Hi,
I added the messagebox in web application, to display the cookies that read and checked the cookies file in cooki directory.

Good Luck!
0
 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

 
LVL 5

Expert Comment

by:Nass89
ID: 12032806
Hi,
I will try it under XP.

Good Luck!
0
 
LVL 5

Expert Comment

by:Nass89
ID: 12033588
Hi,
I tested it undr XP. It is OK.
I used following codes:

      IWebBrowser2* pWBApp = NULL;

      CString strURL = CString("http://MyServer/Xyz/cookicheck.asp");
      BSTR bstrURL = strURL.AllocSysString();
      VARIANT var;
      var.vt = VT_I4;
      var.lVal = 0;

      CoInitialize(NULL);
      CoCreateInstance      (CLSID_InternetExplorer,NULL,CLSCTX_SERVER,IID_IWebBrowserApp,(LPVOID*)      &pWBApp);
      //pWBApp->put_Visible(VARIANT_TRUE);
      pWBApp->put_Visible(VARIANT_FALSE);
      //pWBApp->Navigate      (bstrURL,&vFlags,&vTargetFrameName,&vPostData,&vHeaders);
      pWBApp->Navigate(bstrURL,&var,&var,&var,&var);
      Sleep(2000);
      pWBApp->Release();

Good Luck!
0
 

Author Comment

by:ubiwebdev
ID: 12064871
Hi,

I tried with your code. It looks like it is working. However, if my web application doesn't have messege box (I assume that you are using alert), it can't read the cookie.

What I do is that I have my web application (ASP.NET) running in debug mode. And if I use VARIANT_TRUE, at my breakpoint, I can see the cookie value. If I user VARIANT_FALSE, at my breakpoint, I can not see the cookie value.

Thanks.
0
 
LVL 5

Accepted Solution

by:
Nass89 earned 500 total points
ID: 12094910
Hi,
Here is my test results:

I used it without alert (Visible mode) . It writes direct to the page. It works fine.
I read the cooki and wrote it  into a file (Hidden mode). It works fine.

Good luck!
0
 

Author Comment

by:ubiwebdev
ID: 12101510
Ok, I think maybe it is just my PC. I will close this thready.

Thanks.
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question