I think, the automatical updating of your applications on user's PC is good idea. Also, sometimes you do not want to add some big files in your installation projects. For example you need to install the MDAC (Microsoft Data Access Components) before using a MS Access databases in your applications. But the MDAC installation program is very big (about 7.5 Mb) and is no necessity to install it on the Windows XP. You can use IOUpdate.dll for it.
The IOUpdate.dll uses Microsoft's Component Object Model (COM) technology to provide access to updating services such as:
The IOUpdate.dll COM object have ICoUpdate interface.
The ICoUpdate interface uses the FTP folders and files for updating.
You can use two wrapper class for updating of your application.
Four methods is available:
ICoUpdate methods | Description |
Update | Updating to newest version or back to previous version. |
DownloadAndInstall | Downloading and installing an application or file(s) |
Close | Closes all opened handlers. |
get_Error | Returns an error string if an error occured. |
HRESULT Update(
BSTR bstrURL,
BSTR bstrCaption,
BOOL boPromptNewestVersion,
WORD wVersion1,
WORD wVersion2,
WORD wVersion3,
WORD wVersion4,
BSTR bstrTempFolder,
BSTR bstrDefaultInstallDirectory
);
Updating to newest version or back to previous version.
Returns one of these values:
S_OK The operation was successful S_FALSE The operation was failed. To get extended error information, call get_Error method.
bstrURL
FTP address. For example ftp://comber-adsl.demon.co.uk/Updates/
bstrCaption
Used for creating of messages and dialogs captions. For example, if bstrCaption = "Update Test" and you want to update the 1,0,0,1 version of the application, you can see a dialog with "Update Test 1,0,0,1 update" caption.
boPromptNewestVersion
TRUE - informs user about he use newest version. No necessary to update. User can return to old version in this case yet.FALSE - Nothing does if newest version is used. This mode is useful to updating in separate thread during starting of the application. See using of the CInternetUpdateEm class for details.
wVersion1, wVersion2, wVersion3, wVersion4
Application's version is used for comparison with version folder name.The version folder name have structure - <wVersion1>,<wVersion2>,<wVersion3>,<wVersion4>.
wVersion1 higher of the wVersion2
wVersion2 higher of the wVersion4
ATTENTION!!! wVersion4 higher of the wVersion3
For example your current application's version is: 1,0,0,1
The version, located in the "1,0,0,2" folder of the "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/" site is higher of the current version.
You can see a file version in the Version tab of the file Properties. You can get file version by GetFileVersionInfo(...) function. See my GetFileVersion(...) function for example.
Temporary folder for downloading all files from FTP folder before updating or installing. For example if you want update UpdateTest.exe application from "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/" site and bstrTempFolder = "C:\My Documents\MyProjects\UpdateTest\Debug\Update", then all files from this site will be downloaded to "C:\My Documents\MyProjects\UpdateTest\Debug\Update" folder.
Path to the folder on your hard drive, where an application will be updated or installed. This parameter is used only if key Directory=Default for current installed file section in the FileList.INI file, located in a FTP folder. For example you want to update the UpdateTest.exe applacation located in the "C:\MY DOCUMENTS\MYPROJECTS\UpdateTest\Debug\" directory from "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/" site.For it:
- Include Directory=Default key in the [UpdateTest.exe] section of the "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/FileList.INI" file.
- bstrDefaultInstallDirectory = "C:\MY DOCUMENTS\MYPROJECTS\UpdateTest\Debug\"
HRESULT DownloadAndInstall(
BSTR bstrURL,
BSTR bstrFolder,
BSTR bstrCaption,
BSTR bstrTempFolder,
BSTR bstrDefaultInstallDirectory);
Downloading and installing an application or file(s)
Returns one of these values:
S_OK The operation was successful S_FALSE The operation was failed. To get extended error information, call get_Error method.
bstrURL
FTP address
bstrFolder
Name of the folder with installation files in the current FTP site. For example if you want to install Microsoft Data Access Components 2.5 from "ftp://comber-adsl.demon.co.uk/Updates/Em/MDAC/MDAC_TYP.EXE" and lpszURL="ftp://comber-adsl.demon.co.uk/Updates/" (see CInternetUpdate constructor), then lpszFolder="Em/MDAC"
bstrCaption
Used for creating of messages and dialogs captions. For example, if bstrCaption = "Update Test" and you want to update the 1,0,0,1 version of the application, you can see a dialog with "Update Test 1,0,0,1 update" caption.
bstrTempFolder
Temporary folder for downloading all files from FTP folder before updating or installing. See Update bstrTempFolder for details.
bstrDefaultInstallDirectory
Path to the folder on your hard drive, where an application will be updated or installed. This parameter is used only if key Directory=Default for current installed file section in the FileList.INI file, located in a FTP folder. See Update bstrDefaultInstallDirectory for details.
HRESULT Close( void);
Closes all opened handlers. Use it if you do not use an updating methods long time.
Returns one of these values:
S_OK The operation was successful
HRESULT get_Error(
BSTR FAR *pVal
);
Returns an error string if an error occured.
Returns one of these values:
S_OK The operation was successful
pVal
Address of a callee-allocated buffer that receives the error message
Folders
Root folderVersion folderFTP folder for all available application versions and files. For example "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/"
Any version update files are located in the FTP version folder. The name of the version folders have the following structure:
<version1>,<version2>,<version3>,<version4>
For example if you have new 1,0,0,2 version of your application for updating, then upload all new files to the FTP folder named '1,0,0,2'. (See ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/)
Files
CABARC.EXEVersion folder filesUses for unzip of *.cab files. For example "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/UpdateTest.cab". Located in the Root folder.
Details.txt - contents of the Details column of the versions list of the Application update dialog.
enumeration of the files for updating. See initialization files in the MSDN for details. A section in the FileList.INI must have the following form:
[file_name]
key=string
where:
file_name - file for updating.
key
INFFile
Name of the Information (INF) file. See MSDN Setup API for details. If INFFile key is not defined, then new file replaces of the old file. NOTE! The error can occur if old file is shared and INFFile key is not defined.
Directory- rules for creation of the destination folder of installation. Possible values:
Module - Installing to current directory. For example if IOUpdate.dll located in the "C:\MY DOCUMENTS\MYPROJECTS\UpdateTest\Debug\" folder, then new file will be installed in the same folder.
Default - Installing to Default Install Directory. See bstrDefaultInstallDirectory for details.
[path] - path to installation folder. For example "C:\Program Files\Update Test". You can define a boot drive in the path - %boot drive%[path]. For example if you want to install file to "Program Files\Update Test" folder of the boot drive, then Directory=%boot drive%\Program Files\Update Test
DllRegisterServer - Register of the dll (call the DllRegisterServer function). Possible values:
Yes - register
No - (default) no register.
You can use two wrapper class for updating of your application. See my source code of example of using. Please include WTL in the Include files Directories before building of my code example.
Class CInternetUpdate. For updating or installing of an application or file.
Class CInternetUpdateEm. For updating or installing of an application or file in separate thread
For updating or installing of an application or file.
Five class members is available:
CInternetUpdate members | Description |
CInternetUpdate | The constructor. |
~CInternetUpdate | The destructor. |
Download | Updating to newest version or back to previous version. |
DownloadAndInstall | Downloading and installing an application or file(s) |
SetURL | Set URL. |
CInternetUpdate::CInternetUpdate
CInternetUpdate(
LPCTSTR lpszMessageBoxCaption,
LPCTSTR lpszURL,
LPCTSTR lpszDefaultInstallDirectory,
LPCTSTR lpszTempFolder,
BOOL boPromptNewestVersion = FALSE
);
The constructor.
Parameters
lpszMessageBoxCaption
Used for creating of messages and dialogs captions. For example, if lpszMessageBoxCaption = "Update Test" and you want to update the 1,0,0,1 version of the application, you can see a dialog with "Update Test 1,0,0,1 update" caption.
lpszURL
FTP site address.
lpszDefaultInstallDirectory
Path to the folder on your hard drive, where an application will be updated or installed. This parameter is used only if key Directory=Default for current installed file section in the FileList.INI file, located in a FTP folder. For example you want to update the UpdateTest.exe applacation located in the "C:\MY DOCUMENTS\MYPROJECTS\UpdateTest\Debug\" directory from "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/" site.
For it:
- Include Directory=Default key in the [UpdateTest.exe] section of the "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/FileList.INI" file.
- lpszDefaultInstallDirectory = "C:\MY DOCUMENTS\MYPROJECTS\UpdateTest\Debug\"
lpszTempFolder
Temporary folder for downloading all files from FTP folder before updating or installing. For example if you want update UpdateTest.exe application from "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/1,0,0,2/" site and lpszTempFolder = "C:\My Documents\MyProjects\UpdateTest\Debug\Update", then all files from this site will be downloaded to "C:\My Documents\MyProjects\UpdateTest\Debug\Update" folder.
boPromptNewestVersion
TRUE - informs user about he use newest version. No necessary to update. User can return to old version in this case yet.
FALSE - Nothing does if newest version is used. This mode is useful to updating in separate thread during starting of the application. See using of the CInternetUpdateEm class for details.
virtual void Download(WORD wVersion1, WORD wVersion2, WORD wVersion3, WORD wVersion4);
Updating to newest version or back to previous version.
Parameters
wVersion1, wVersion2, wVersion3, wVersion4
Application's version is used for comparison with version folder name. The version folder name have structure - <wVersion1>,<wVersion2>,<wVersion3>,<wVersion4>
wVersion1 higher of the wVersion2
wVersion2 higher of the wVersion4
ATTENTION!!! wVersion4 higher of the wVersion3
For example your current application version is: 1,0,0,1
The version, located in the "1,0,0,2" folder of the "ftp://comber-adsl.demon.co.uk/Updates/UpdateTest/" site is higher of the current version.You can see a file version in the Version tab of the file Properties.
You can get file version by GetFileVersionInfo(...) function. See my GetFileVersion(...) function for example.
CInternetUpdate::DownloadAndInstall
void DownloadAndInstall(LPCTSTR lpszFolder);
Downloading and installing an application or file(s).
Parameters
lpszFolder
Name of the folder with installation files in the current FTP site. For example if you want to install Microsoft Data Access Components 2.5 from "ftp://comber-adsl.demon.co.uk/Updates/Em/MDAC/MDAC_TYP.EXE" and lpszURL = "ftp://comber-adsl.demon.co.uk/Updates/" (see CInternetUpdate constructor), then lpszFolder = "Em/MDAC"
void SetURL(LPCTSTR lpszURL);
Set FTP's URL.
Parameters
lpszURL
FTP site address.
For updating or installing of an application or file in separate thread.
Four class members is available:
CInternetUpdateEm members | Description |
CInternetUpdateEm | The constructor. |
~CInternetUpdateEm | The destructor. |
GetLastVersion | Updating to newest version or back to previous version. |
DownloadAndInstall | Downloading and installing an application or file(s) |
CInternetUpdateEm::CInternetUpdateEm
CInternetUpdateEm(
LPCTSTR lpszMessageBoxCaption,
LPCTSTR lpszURL,
LPCTSTR lpszDefaultInstallDirectory,
LPCTSTR lpszTempFolder
);
The constructor.
Parameters
See CInternetUpdate::CInternetUpdate for details.
CInternetUpdateEm::GetLastVersion
void GetLastVersion(BOOL boPromptNewestVersion)
Updating to newest version or back to previous version.
Parameters
boPromptNewestVersion
TRUE - informs user about he use newest version. No necessary to update. User can return to old version in this case yet.
FALSE - Nothing does if newest version is used. This mode is useful to updating in separate thread during starting of the application. See using of the CInternetUpdateEm class for details.
CInternetUpdateEm::DownloadAndInstall
void DownloadAndInstall(LPCTSTR lpszFolder);
Downloading and installing an application or file(s)
Parameters
See CInternetUpdate::DownloadAndInstall for details