views:

198

answers:

3

I've been tasked with going through a database and checking all of the links, on a weekly schedule. I normally work in PHP, but doing this in PHP would be very slow (it actually would timeout the page after about 100 URLs), so I decided to make a quick C++ app.

Admitidly, I haven't used C++ since college, so I'm a bit rusty.

I found the ShellExecute function, and that it would open the page no problem. Here is what I have so far:

#include <shlobj.h>
#include <iostream>
using namespace std;
int main()
{
      if(   ShellExecute(NULL,"find","http://example.com/fdafdafda.php",NULL,NULL,SW_SHOWDEFAULT) )
      {
          cout << "Yes";

      } else {
             cout << "No";
      }
      cout << endl;
     system("PAUSE");
    return 0;
}

The problem is that it always returns true, whether it is opening a valid page or not. It appears to be checking if the associated app (a browser in this case) is able to open the document with no problems, then returns true. It isn't looking to see if the browser is getting a 404 or not, it simply sees it open and run and is fine.

Is there a better way to do this? Am I missing a step?

As an aside, I have attempted to use the cURLcpp stuff, but can't seem to figure it out. All of the examples point to header files that don't exist in the download. I have a feeling cURLcpp is the better way to do this.

Thanks for any help.

+3  A: 

I think you answered your own question. ShellExecute is really not appropriate for this task, and something like CURL would be better.

Nick Meyer
A: 

Documentation on the return value of ShellExecute :

If the function succeeds, it returns a value greater than 32. If the function fails, it returns an error value that indicates the cause of the failure. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. It is not a true HINSTANCE, however. It can be cast only to an int and compared to either 32 or the following error codes below.

See ShellExecute documentation.

And yes, CURL would be better.

Christopher
From a ShellExecute viewpoint, a 404 is not a failure. It started the browser, and that got a response. It's even the correct response for that URL.
MSalters
+3  A: 

or if you don't want to use an external library you can check directly with InternetOpen, InternetOpenURL etc.

Goz