Solved

Strange behavior of CoCreateInstance

Posted on 2004-09-03
8
591 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now