Solved

CInternetSession::OpenURL

Posted on 1997-12-22
1
481 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
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

20 Experts available now in Live!

Get 1:1 Help Now