Solved

CInternetSession::OpenURL

Posted on 1997-12-22
1
487 Views
Last Modified: 2013-11-19
The following is a function meant to load a webpage into the buffer.  It works fine except if url is not a valid url, or even if it just times out OpenURL does not return.  Instead an exception is thrown in kernel32.dll.  This isn't acceptable behavoir for my app.  However the function works perfectly if it find a valid url.  Does anybody have any ideas?  Any thoughts would be greatly appreciated. Thanx!

CInternetSession is("SPIDER");

int LoadURL(const char* url,char* buffer,int bufferSize)
{
 CStdioFile *urlHandle;
 char tmpBuffer[1000];
 int lenIntoBuf = 0;

 urlHandle = is.OpenURL(url);

 if (urlHandle == NULL)
  return 0;

 while (urlHandle->ReadString(tmpBuffer,1000) && 
  lenIntoBuf < bufferSize)
 {
 strncpy(buffer+lenIntoBuf,tmpBuffer,bufferSize-lenIntoBuf);
 lenIntoBuf += strlen(tmpBuffer);
 }
 return lenIntoBuf;
}
0
Comment
Question by:tlsoftware
[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
1 Comment
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1312908
OpenUrl is supposed to throw CInternetException. You should use try-catch.

try
{
    urlHandle = is.OpenURL(url);
}
catch (CInternetException *e)
{
    // exception handler
    // ...

    e->Delete();
}

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

763 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