When I get an error message inside the above code I am waiting for 5 seconds and I then try to return to the above code with, return 0, etc. Nothing seems to work.
It looks like you are trying to call main(). Standard C++ does not allow that. Instead you should use a loop, in order to go back to the start when required.
int main(int argc , char *argv[])
{
while (true) // repeat forever
{
HINTERNET connect1 = InternetOpen("MyBrowser",INTERNET_OPEN_TYPE_PRECONFIG,NULL, NULL, 0);
if (!connect1)
{
printf("Connection Failed or Syntax error");
Sleep(10000);
InternetCloseHandle(connect1);
continue; // go back to start and try again
}
HINTERNET OpenAddress1 = InternetOpenUrl(connect1,"http://127.0.0.1", NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE|INTERNET_FLAG_KEEP_CONNECTION, 0);
if ( !OpenAddress1 )
{
DWORD ErrorNum = GetLastError();
printf("Failed to open URL \nError No: ");
Sleep(10000);
InternetCloseHandle(connect1);
InternetCloseHandle(OpenAddress1);
continue; // go back to start and try again
}
break; // exit from the loop
}
}