CInternetSession.OpenURL() recursive call fails....

Hi,

ENV: Windows XP, VS Studio 2003 with MFC

[SUMMARY]
My recursive call to CInternetSession.OpenURL() fails, as Close() is
probably not resetting the handle to NULL.

[IN DETAIL]
My recursive call to CInternetSession.OpenURL() fails with system
error saying about invalid handle. I am calling Close() on the session
object after my first invocation of OpenURL(). However, as the Close()
returns nothing, I have no way to know if it could close the session
with success. I guess its closing the session, but the handle to
session is not reset to null, which probably breaks my recursive call.
Here is what I suspect may be happening:

myInternetSession.OpenURL(...); // is success

myInternetSession.Close();         // no way to know if it closed
session

myInternetSession.OpenURL(....);
/* above call throws CInternetException, as probably session was
closed. I have no way to know if session is closed with success, as
there is no IsOpen() kind of call. Also, my guess is its closed with
success, but handle is not reset, hence this second calls fails. */

Can somebody throw some light?

Thanks for your time.

- Kedar Agarkar

0
7/30/2007 10:33:03 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
587 Views

Similar Articles

[PageSpeed] 18

"Kedar Agarkar" wrote:

> Hi,
> 
> ENV: Windows XP, VS Studio 2003 with MFC
> 
> [SUMMARY]
> My recursive call to CInternetSession.OpenURL() fails, as Close() is
> probably not resetting the handle to NULL.
> 
> [IN DETAIL]
> My recursive call to CInternetSession.OpenURL() fails with system
> error saying about invalid handle. I am calling Close() on the session
> object after my first invocation of OpenURL(). However, as the Close()
> returns nothing, I have no way to know if it could close the session
> with success. I guess its closing the session, but the handle to
> session is not reset to null, which probably breaks my recursive call.
> Here is what I suspect may be happening:
> 
> myInternetSession.OpenURL(...); // is success
> 
> myInternetSession.Close();         // no way to know if it closed
> session
> 
> myInternetSession.OpenURL(....);
> /* above call throws CInternetException, as probably session was
> closed. I have no way to know if session is closed with success, as
> there is no IsOpen() kind of call. Also, my guess is its closed with
> success, but handle is not reset, hence this second calls fails. */
 
This not a recursion but a sequence of calls to the same method...

If you look at the source code of CInternetSession::Close, you will see that 
it sets the handle to NULL. Anyway, to test it, you could use operator 
HINTERNET to get the handler;
HINTERNET hSession = myInternetSession;
ASSERT(hSession == NULL);

But the problem here is simple; you are closing the session and then calling 
OpenURL which in turn makes OpenURL throw an exception as m_hSession is NULL. 
So either do not close the session, or if closed, create another session 
object. (Usually sessions are created inside the application object and are 
closed after the job being done on them).



-- 
=====
Arman

An internal error has occured while showing an internal error!
-- eclipse

0
armancho_x1 (249)
7/30/2007 11:18:04 AM
See below...
On Mon, 30 Jul 2007 10:33:03 -0000, Kedar Agarkar <kedar.agarkar@gmail.com> wrote:

>Hi,
>
>ENV: Windows XP, VS Studio 2003 with MFC
>
>[SUMMARY]
>My recursive call to CInternetSession.OpenURL() fails, as Close() is
>probably not resetting the handle to NULL.
>
>[IN DETAIL]
>My recursive call to CInternetSession.OpenURL() fails with system
>error saying about invalid handle. I am calling Close() on the session
>object after my first invocation of OpenURL(). However, as the Close()
>returns nothing, I have no way to know if it could close the session
>with success. I guess its closing the session, but the handle to
>session is not reset to null, which probably breaks my recursive call.
>Here is what I suspect may be happening:
>
>myInternetSession.OpenURL(...); // is success
>
>myInternetSession.Close();         // no way to know if it closed
>session
>
>myInternetSession.OpenURL(....);
****
This is not a *recursive* call.  This is an *iterative* call.  No sign of recursion exists
here.
****
>/* above call throws CInternetException, 
****
What are the values in CInternetException, in particular, the m_dwError value?  This would
be a massively important value to display.  Without knowing what it is, it is impossible
to begin to guess what has happened.


There are questions about whether or not a CInternetSession can be reused; the
documentation appears to leave this unstated, so in fact there may be residual state that
is causing problems.

When in doubt, just set a breakpoint and do some single-stepping until you understand the
code.
				joe

****
>as probably session was
>closed. I have no way to know if session is closed with success, as
>there is no IsOpen() kind of call. Also, my guess is its closed with
>success, but handle is not reset, hence this second calls fails. */
>
>Can somebody throw some light?
>
>Thanks for your time.
>
>- Kedar Agarkar
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15973)
7/30/2007 2:01:06 PM
Hi Joseph, Arman,

Got a clue. Session was being created inside constructor of
CInternetSession unlike my assumption of it being created inside first
invocation of OpenURL(). Now that elimination of Close() till very
last point solves my problem.

Thanks both for your replies.

Regards.

- Kedar Agarkar

On Jul 30, 7:01 pm, Joseph M. Newcomer <newco...@flounder.com> wrote:
> See below...
>
>
>
>
>
> On Mon, 30 Jul 2007 10:33:03 -0000,KedarAgarkar<kedar.agar...@gmail.com> wrote:
> >Hi,
>
> >ENV: Windows XP, VS Studio 2003 with MFC
>
> >[SUMMARY]
> >My recursive call to CInternetSession.OpenURL() fails, as Close() is
> >probably not resetting the handle to NULL.
>
> >[IN DETAIL]
> >My recursive call to CInternetSession.OpenURL() fails with system
> >error saying about invalid handle. I am calling Close() on the session
> >object after my first invocation of OpenURL(). However, as the Close()
> >returns nothing, I have no way to know if it could close the session
> >with success. I guess its closing the session, but the handle to
> >session is not reset to null, which probably breaks my recursive call.
> >Here is what I suspect may be happening:
>
> >myInternetSession.OpenURL(...); // is success
>
> >myInternetSession.Close();         // no way to know if it closed
> >session
>
> >myInternetSession.OpenURL(....);
>
> ****
> This is not a *recursive* call.  This is an *iterative* call.  No sign of recursion exists
> here.
> ****>/* above call throws CInternetException,
>
> ****
> What are the values in CInternetException, in particular, the m_dwError value?  This would
> be a massively important value to display.  Without knowing what it is, it is impossible
> to begin to guess what has happened.
>
> There are questions about whether or not a CInternetSession can be reused; the
> documentation appears to leave this unstated, so in fact there may be residual state that
> is causing problems.
>
> When in doubt, just set a breakpoint and do some single-stepping until you understand the
> code.
>                                 joe
>
> ****>as probably session was
> >closed. I have no way to know if session is closed with success, as
> >there is no IsOpen() kind of call. Also, my guess is its closed with
> >success, but handle is not reset, hence this second calls fails. */
>
> >Can somebody throw some light?
>
> >Thanks for your time.
>
> >-KedarAgarkar
>
> Joseph M. Newcomer [MVP]
> email: newco...@flounder.com
> Web:http://www.flounder.com
> MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text -
>
> - Show quoted text -


0
7/31/2007 7:31:21 AM
Reply:

Similar Artilces:

Help with CInternetSession
Hey everyone, hoping someone can give me a hand here as this seems a little backwards to me. Basically I am writing an application that uploads a file to my webserver (a static IP) using CInternetSessions and CFtpConnection. Now I've included the code I'm using below to illustrate what seems wrong to me (and probably is :( ). Basically I don't know/understand when I'm supposed to delete my sessions and connections (seems like I never call ::Close() probably not a good thing). If anyone can see what I'm doing wrong (remember I'm calling this chunk of code about every ...

SP3 for Windows XP Failed
In reviewing my Windows Update History, I find that Windows XP Service Pack 3 Failed on 08 21 2008, but several Service Pack 3 Updates have downloaded since that date. Two Questions: 1) Why did the SP3 Update Fail, and 2) Why are the updates downloading and installing even though the Service Package Failed? This does not make sense. I just tried again to install it and it stopped downloading. Why? tkb656 wrote: > In reviewing my Windows Update History, I find that Windows XP > Service Pack 3 Failed on 08 21 2008, but several Service Pack 3 > Updates have downloaded sinc...

Search failing
Hi When I search in Outlook it does not find all emails from past is there anyway I can makes sure it does such as by recreating indexes etc or whatever Outlook uses for searching? Thanks Regards Which version of Outlook do you use? What mail account type do you use? -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, HowTo, Downloads, Add-Ins and more http://www.msoutlook.info/ Real World Questions, Real World Answers ----- "John" <John@nospam.infovis.co.uk> wrote in message news:uVYkU244HHA.58...

CInternetSession #2
Hello! For two days now, Iam strugling with some dificulties using CInternetSession.OpenURL() function. Iam writing simple code for separate thread function such as: while(true) { CInternetSession csiSession; CStdioFile* MyFile = csiSession.OpenURL(_T("http://www.someurl.com")); // working on retrieved data MyFile->Close(); delete MyFile; } Iam using VC2k5 and while building solution Ive received warning: First-chance exception at 0x7c90eb74 in Project1.exe: 0xC0000008: An invalid handle was specified. Warning is poiting to "OpenURL", but I don&#...

EnumThreadWindows callback never called
Hi All, I am using following code for Enumeration of process window to get HWND from Process INformation Struct? // CALL BACK FUCNTION IN .CPP BOOL CALLBACK FindWndProc(HWND hwnd, LPARAM lParam) { int i; i = 1000; //AfxMessageBox((LPTSTR)hwnd); return TRUE ; } // Process Creation Code STARTUPINFO si; PROCESS_INFORMATION pi; HWND hwnd = NULL ; ZeroMemory( &si, sizeof(si)); si.cb = sizeof(si); si.lpTitle = "My Windwso"; ZeroMemory( &pi, sizeof(pi)); if (!CreateProcess(NULL,"c:\\Windows\\explorer.exe",NULL,NULL,FALSE,0,NULL,NULL ,&si,&pi)) { ...

Odd VBSCRIPT error with function call
Hello, Here’s an oddball occurrence. In a VBScript-driven ASP page, I have a function like this: Function GetFlagsApplicableToUser2(lngUserID) ‘DO MORE STUFF End Function Later in the same ASP file, I call it like this: thisUsersFlags = GetFlagsApplicableToUser2(someLongValue) And, I get this error on the output: Microsoft VBScript runtime error '800a01c2' Wrong number of arguments or invalid property assignment /_admin/users/editUserFlags.asp, line 103 If I change this to a SUB.. END SUB, I get this: Microsoft VBScript runtime error '800...

Cystal Reports : update viewstate failed
This is a multi-part message in MIME format. ------=_NextPart_000_0008_01C604FC.ABBFA0D0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable Hi All, I have problem with crystal reports. When I try to generate some report = it does not work and always shows an error (see below). CrystalReportViewer updateViewState failed The Page Server you are trying to connect to is not accessible. Please = contact your system administrator. Restarting crystal and IIS services does not help. I have tried to = disable and add new crystal page server , b...

Updates faile to install
MS Automatic Update has downloaded a whole buch of updates, but I cannot get any of them to install, either singly or at shutdown. It looks like one of them might just cure my persistent junk mail problem, if only I could get XP Pro to take it on board. Anyone any ideas? Post in an XP forum or Windows Updates forum. This is not an Outlook problem. "martin_cartwright" wrote: > MS Automatic Update has downloaded a whole buch of updates, but I > cannot get any of them to install, either singly or at shutdown. It > looks like one of them might just cure my persistent junk...

XP macro fails in 2000
I've created several macros in a workbook using Excel XP. They are run by clicking on drawing objects to which I've assigned the macros. When my colleague uses the spreasheet on his Office 2000 equipped PC, the macro buttons don't work. Any solutions please? TIA ...

CRM 1.2 add user fails for OU users. Domain root users OK.
Hello. I am having trouble adding users to CRM 1.2. If I try to add a CRM user from an OU in the domain with deployment manager or the web GUI it fails. If I add a user to CRM from the root of the domain the user is added fine to CRM. In our test environment I was able to add users to CRM that are in OU's in a test domain without any trouble. Any ideas? Thanks!! Mike What kind of error messages do you get? It sounds like a AD security issue. Is the user you are logged in as a Domain Admin? Matt Parks MVP - Microsoft CRM ---------------------------------------- ------------...

CInternetSession Behavior
I have been witnessing some strange behavior in the CInternetSession::SetOption and CInternetSession::QueryOption methods. My goal is to get through my company's proxy server programmatically. I have a static member for my CInternetSession and a static method for initializing the the CInternetSession. I first start out with trying to get a direct connection to the internet and test it by going to a specific location (ie. google.com); if that throws an error, then I change the CInternetSession via SetOption to work via proxy (very simplistic explanation). The strange behavior that I men...

Updates fail to download/install
Had to reinstall Vista a week ago. Now Windows Update doesn't seem to work properly. When running Windows Update I get a window saying "X updates are downloaded" but the speed is 0. After a while I get an error message in the Update History saying the updates failed. I haven't been able to see any error codes. There are plenty of updates that fail, but interestingly about 30% seems to go well. Any ideas? What problems were you having that you though reinstalling Vista might resolve? Did you do a Repair Install or did you format the HDD & do a clean ins...

CButton DrawItem never be called
Hi, I want to modify some CButtons in the OnCreate() method of the class (CMainFrame : public CFrameWnd) int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { m_btn1.SetButtonImg(IDC_BUTTON1, IDC_BUTTON1); m_btn1.SetButtonText("Test"); m_btn1.SetFont("Arial",16); m_btn1.SubclassDlgItem(IDOK, this); return 0; } But these information are not taken place, because the DrawItem method (class CButton) will never be called. Which steps do I have to do - getting called the DrawItem function (Cbutton-class)? m_btn1 is created within a di...

Failed to duplicatehandle
when I use MFC to create a Win32 application which call CreateProcess to call service procedurces which are created from MinGW. I want use pipe to draw the information generated in service produrces, there is a strange thing happened. When the MFC Application runs called by VC++'s GO command, all the service procedures work correctly. But when I double chick the MFC Application to run, these service procedures occur error, and summit the MFC Application a error message "Duplicatehandle error xxxx.exe can not duplicate handle". How strange it is! I why to know why this happe...

implementation of call back in Driver
i want to implement timer in driver and call particular function in application can u plz tell me , thanks suhas ...

Office Install Fails
Given: Fresh install Windows XP Pro with SP3 Office 2007 Pro Symptom: Office 2007 Pro Install Error Message: "Setup cannot find Proofing.en-us\Proof.es\Proof.cab" When I go to the specific directory and click on it and retry I get the error message "Invalid location". If I retry from a parent directory (IE: \Proofing.en-us) I get the same "Invalid location" message. I can see the appropriate files on the CD. Trying something else I attempted to copy the parent directory (Proofing.en-us) and all contents to the C: drive. ...

CInternetSession
I'm creating a simple "Software Update" feature that uses the CInternetSession & CHttpFile classes to download an xml file that contains a list of available software updates. I have very little Internet programming experience. Here's the basis of the code that I'm using: CInternetSession internetSession; CHttpFile* pFileRemote = NULL; CProgressDlg dlg; dlg.SetStatus(_T("Connecting to blah")); try { pFileRemote = reinterpret_cast<CHttpFile*>(internetSession.OpenURL(_T("updates.xml"), 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_RELOAD...

addnew functionality fails
This problem is about recordset functionality. Actually, When using RFX_Int, value 32484 is being treated as null and can't be entered. So converting RFX_Int into RFX_Long and type casting the variable to long can solve this problem. Look at the link: http://support.microsoft.com/kb/170257/en-us But again, value 1246576928 is being treated as null in case of RFX_Long. And when tried to type cast the variable to double, it shows the fractional truncation error and numeric out of range error. So wouid anyone please let me know: 1)How to resolve the issue? 2) How value can be entered in data...

Why do they call assemblies for module
Hi! Why do they call an assembly for module Here I have an example of that. So when I call GetModules and write out this I write out the exe file or dll file where this piece of code is located in. Assembly ass = Assembly.GetExecutingAssembly(); foreach (Module mod in ass.GetModules()) { Console.WriteLine("Module Name: {0} ", mod.Name); } //Tony On 13-05-2010 13:06, Tony Johansson wrote: > Why do they call an assembly for module > Here I have an example of that. So when I call GetModules and write out this > I wri...

Problem having VC++ reading from Internet Using session.OpenURL
I have a program that use to work but now doesn't. It's a simple c++ program which reads a website if you supply an URL. When it worked I was using a DSL interconnection, however now that I'm trying to use a dial up connection I no longer is working. It's a simple program which uses the following to open the connection to the URL: pFile1 = session.OpenURL(url, 0, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_KEEP_CONNECTION| INTERNET_FLAG_RELOAD |INTERNET_FLAG_DONT_CACHE); Now everytime I check pFile1 it is a zero. What am I doing wrong, or is there something which got...

Calling Excel shortcuts from VBA
Hi, I am trying to automate the following two excel shortcuts using VBA. I know I can use commandbar and commandcontrol to call excel menus but I can not find the submenus these shortcuts belong to. 1. Ctrl + [ -- cursor goes to the precedent cell 2. F5 + Enter -- cursor goes to the original cell Also, is it possible to call an excel shortcut from VBA? I know that one can call a worksheet function from VBA (For example, Application.WorksheetFunction.Fact(5) ). But is there way to call a shortcut, say Ctrl + C from VBA? Thanks, MG. Submitted via EggHeadCafe - So...

New custom report failing to display
Hi all, I am starting to create new custom reports for the first time. As a test, I have changed the Account Overview report slightly in MS VS 2003. I uploaded the new report to CRM as per the many posts on here. When I run the SUB report from CRM, it runs fine. When I run the main report, I get this error message "Error: Subreport could not be shown." Following the posts here, I set the right data source connection in MS VS 2003. When I run the SUB report from there, again it runs fine. When I run the main report, I get this other error message "The url javascript:void(windo...

Access the call stack
In a debug build, is there a way for me to get a list of functions on the call stack? I.e., I have a function that is getting passed incorrect data and I want to display the call stack so I can find out who called this function. Oh yeah, this is happening on a beta tester's computer, so I can't just set a breakpoint. Note it is NOT crashing so I don't really need the post mortem Watson-type setup... I am hoping there is a call that gets the call stack info... Thanks, Steve > In a debug build, is there a way for me to get a list of functions on > the call stack? I.e., I h...

SMTP server failing #2
My copy of Outlook 2K3 has developed a weird problem, only with one of my POP3 accounts (I use 5 regularly) and only on sends. I consistently get the error: Task 'Comcast - Sending' reported error (0x800CCC61) : "Your outoing (SMTP) e-mail server has reported an internal error. If you continue to receive this message, contact your server adminstrator or Internet service provider (ISP). The server responded: 556 null byte in data' As I said, I can send mail using any of my other accounts. Comcast claims it's not their problem, and it wouldn't make any differe...

C++ calling vb6 dll which calls another vb6 dll
I am having problems with a C++ project I am working on. I am trying to call a vb6 dll which in turn calls another vb6 dll. Now I can call some methods in the first vb6 dll fine, but when i call the method which then calls the other vb6 dll, c++ just hangs. No errors are raised, nothing, it just sits there doing nothing. The c++ project is itself a DLL. I have created a simple vb6 exe program to call the exact same vb6 dll and it works fine. Also i have created a c++ win32 exe to call the vb6 dll and that also works fine. Can anybody help? Kind Regards, Matt > I am having problems w...