Click here to Skip to main content
15,881,559 members
Articles / Programming Languages / C++

HexEdit - Window Binary File Editor

Rate me:
Please Sign up or sign in to vote.
4.96/5 (137 votes)
17 Oct 2012MIT45 min read 491.2K   22.3K   321  
Open-source hex editor with powerful binary templates
// UpdateChecker.cpp - implements UpdateChecker class for checking for new versions
//
// Copyright (c) 2011 by Andrew W. Phillips.
//
// This file is distributed under the MIT license, which basically says
// you can do what you want with it but I take no responsibility for bugs.
// See http://www.opensource.org/licenses/mit-license.php for full details.
//

#include "stdafx.h"
#include <Wininet.h>
#include "UpdateChecker.h"

// Returns true if the version is able to be checked - ie, the 
// Internet is active and the URL is available.
bool UpdateChecker::Online()
{
	return ::InternetCheckConnection(strUrl, FLAG_ICC_FORCE_CONNECTION, 0) != 0;
}

// Checks the current version (curr) against the latest version number stored
// in a file on the Internet.  All numbers are simple integers greater than 100.
// For example, version 4.10 is stored as the 3 digits "410".
// Returns false if a newer version is not available or there is an error, else true.
bool UpdateChecker::UpdateAvailable(int curr)
{
	bool retval = false;

	HINTERNET hint, hurl;
	hint = ::InternetOpen(_T("Update"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	if (hint == (HINTERNET)0)
		return false;

	hurl = InternetOpenUrl(hint, strUrl, NULL, -1,
	                       INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE |
	                           INTERNET_FLAG_PRAGMA_NOCACHE | WININET_API_FLAG_ASYNC,
	                       NULL);

	char buf[8];            // stores bytes read from current version file on the Internet
	DWORD nread = 0;        // number of bytes read into buf
	if (hurl != (HINTERNET)0 &&	::InternetReadFile(hurl, buf, sizeof(buf)-1, &nread))
	{
		// File (or at least start of file) read OK
		buf[nread] = '\0';    // ensure string is null terminated
		int ver = atoi(buf);  // get version (eg "350" means version 3.50

		if (ver > curr)
			retval = true;

		::InternetCloseHandle(hurl);
	}
	::InternetCloseHandle(hint);

	return retval;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Australia Australia
Andrew has a BSc (1983) from Sydney University in Computer Science and Mathematics. Andrew began programming professionally in C in 1984 and has since used many languages but mainly C, C++, and C#.

Andrew has a particular interest in STL, .Net, and Agile Development. He has written articles on STL for technical journals such as the C/C++ User's Journal.

In 1997 Andrew began using MFC and released the source code for a Windows binary file editor called HexEdit, which was downloaded more than 1 million times. From 2001 there was a shareware version of HexEdit (later called HexEdit Pro). HexEdit has been updated to uses the new MFC (based on BCG) and is once more open source.

Comments and Discussions