Solved

Strange behavior of CoCreateInstance

Posted on 2004-09-03
8
594 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to monitor remote shell execution on linux 9 113
method notes when mouse over in eclipse 5 95
only14 challenge 19 89
matchUp  challenge 9 134
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 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