Web-based program version check

Source: Internet
Author: User

 

Many programs can Update versions over the Internet. Windows Update is a typical example. To implement this feature, you must first check the application version. How can I check the version of my program on the Internet?

However, if you only want to check the version of the program, you can save the new version information in text form on the Web site. You need to obtain the file information through FTP. File downloading can be implemented through the ready-made Windows Internet API, that is, WinInet, which everyone is familiar with. If you haven't used it, it doesn't matter, this article describes in detail how to use it to write FTP programs. WinInet is easy to use. It has a fixed routine: Step 1 creates a connection, step 2 creates an FTP session, step 3 opens the file, and step 4 reads the file data. The code is like the following:

HINTERNET h = InternetOpen (...);
  
HINTERNET hftp = InternetConnect (..., INTERNET_SERVICE_FTP ,..);
  
HINTERNET hftpfile = FtpOpenFile (...);
  
InternetReadFile (...);
  

Let's dive into the details and enjoy the highlights. To facilitate code reuse, I wrote the class CWebVersion, which encapsulates all the details and implements a simple function: obtaining the program version information through the Web to check the version. This class is also very convenient to use:

If (CWebVersion: Online ()){
  
CWebVersion ver ("pub.chinafsdu.net ");
  
If (ver. ReadVersion ("version.txt"), "pub", "pub "){
  
DWORD maj = ver. dwVersionMS;
  
DWORD min = ver. dwVersionLS;
  
}
  
}
  

Below isCWebVersion declaration:

//////////////////////////////////////// ////////////////////////
  
// WebVersion. h
  
//
  
# Pragma once
  
 
  
Class CWebVersion {
  
Protected:
  
Enum {BUFSIZE = 64 };
  
LPCTSTR m_lpServer;// Server name
  
DWORDM_dwError;// Most recent error code
  
TCHARM_errInfo [2, 256];// Extended error info
  
TCHARM_version [BUFSIZ];// Version number as text
  
VoidSaveErrorInfo ();// Helper to save error info
  
 
  
Public:
  
DWORD dwVersionMS;// Version number: most-sig 32 bits
  
DWORD dwVersionLS;// Version number: least-sig 32 bits
  
 
  
CWebVersion (LPCTSTR server): m_lpServer (server ){}
  
~ CWebVersion (){}
  
 
  
StaticBOOL Online ();
  
BOOLReadVersion (maid, maid

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.