Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Strange behavior of CoCreateInstance

Posted on 2004-09-03
8
Medium Priority
?
598 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

688 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