Solved

Strange behavior of CoCreateInstance

Posted on 2004-09-03
8
585 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
 
LVL 5

Expert Comment

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

Good Luck!
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

16 Experts available now in Live!

Get 1:1 Help Now