I would like to do something like this:

readfilethingy("www.mywebsite.com/update.txt"); //fail

with update.txt being this:

3.4


//OR just the http location

with the result being:

*user clicks on update button*
"NEW UPDATE IS AVAILABLE! :D"
*Clicks download*
*Download on .exe starts*

So, is it possible? I have searched and searched on google with no results...

Dani AI

Generated

Short answer: yes — a remote text file can be fetched and parsed from C++. There are three practical routes depending on the project type: managed C++/CLI (use the .NET networking APIs), native Win32 (WinHTTP/WinINet or URLDownloadToFile), or a cross‑platform library like libcurl. already pointed toward the managed route; a compact C++/CLI example below shows a minimal, practical way to download the file, convert it to a C++ string, and extract the version and URL (it also handles the case where the file contains an HTML anchor).

#include <msclr/marshal_cppstd.h>
using namespace System;

void CheckUpdate()
{
    System::Net::WebClient^ wc = gcnew System::Net::WebClient();
    String^ text = wc->DownloadString("http://www.mywebsite.com/update.txt");
    std::string s = msclr::interop::marshal_as<std::string>(text);

    std::istringstream iss(s);
    std::string ver, line;
    if (std::getline(iss, ver)) {
        // version is in 'ver'
    }
    while (std::getline(iss, line)) {
        if (line.empty()) continue;
        size_t p = line.find("http");
        if (p != std::string::npos) {
            std::string url = line.substr(p);
            // url is usable (strip trailing tags/characters if needed)
            break;
        }
    }
}

Keep in mind: build the module with /clr and ensure required .NET assemblies are referenced; run network calls off the UI thread; prefer plain text (Content-Type: text/plain) for the update file so HTML parsing is unnecessary. For native apps, libcurl provides a simple, robust alternative (curl_easy_perform + a write callback) and avoids mixing managed/native code. Also handle HTTPS, redirects, timeouts, and error codes; validate the version string (semantic compare) and prefer HTTPS and signed downloads for security.

Recommended Answers

All 3 Replies

See this post from over in C# land: http://www.daniweb.com/forums/post1129114.html#post1129114 . You'll have to translate the syntax of it to C++/CLI (M$ mungware per Salem :) ) but it'll be the same .NET functions from the System.Net namespace (HttpWebRequest/
HttpWebResponse). It was a similar problem to what you are working on.

Hmm...

I was unable to translate it to C++. Got any ideas? I used:

using namespace System::Net;

It came up as part of the default included references for me... (it's marked as a part of system.dll).

Right click on your project in the Solution Explorer, go to References, from there Add New Reference, on the .NET tab scroll down to System.Net. See if that gets it for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.