If he only needs to check that one thing for some reason it's a lot of hassle to learn Winsock (and not really needed to run a server constantly on your own machine).
Here's a quick way of doing exactly what you're asking for - it's neater to do it with curl or something similar but this does the trick without external wrappers. Modify it to your source:
Code:
#include <shlobj.h>
//You have to include shlobj.h
void Check(string url)
{
typedef int * (*URLDownloadToFileA)(void*,const char*,char*,DWORD,void*);
HINSTANCE LibHnd = LoadLibrary("Urlmon.dll");
URLDownloadToFileA URLDownloadToFile = (URLDownloadToFileA) GetProcAddress(LibHnd,"URLDownloadToFileA");
URLDownloadToFile(0, url.c_str(), "check.txt", 0, 0);
}
Just make sure the url is defined somewhere and call the function from main or wherever you're doing it:
Code:
string link = "http://my.site.net/check.txt";
Check(link);
And checking the file you downloaded is just basic file I/O. If you don't know this, quick example:
Code:
//You need to include fstream and string for this
string mytext;
ifstream in;
in.open("check.txt");
if(!in){
cout << "Failed to open file for some reason...";
return 1;
}
getline(in, mytext);
in.close();
if(mytext.find ("program is offline") != string::npos)
{
//disable/exit, whatever you wanted to do)
}
//continue doing whatever the dll does
Alright you should really check that the file was actually downloaded and so on because otherwise it might still be in the cache and the program wouldn't notice if it failed to download but I'm writing most of this from the top of my head, google UrlDownloadToFileA and you can find how to do it.
It should also be added that this is not a safe way of checking anything, for example a malicious user could easily modify and lock "check.txt" to prevent you from downloading a new copy, your program would just read whatever the user put in it. Unless you simply disable it by checking return value of the download and exits if it failed.