Click here to Skip to main content
15,113,131 members
Articles / Desktop Programming / WTL
Posted 5 Mar 2002


26 bookmarked

Patch: WTL application for creating patches and patching files

Rate me:
Please Sign up or sign in to vote.
3.75/5 (4 votes)
5 Mar 20023 min read
WTL application for creating patches and patching files

Sample Image - Patch.png


I read a posting here by Alessandro Vergani, UnPatcher: a COM object for patching files. He created a COM object that used a little known capability (providing you have the needed MS DLL's) that can create and apply delta patches to files. (Please refer to Alessandro's article on availability of the required patch creation and application DLLs).

I decided to create a WTL app that would use his component, but later decided to abandon usage of the component in favor of a direct class wrapper, so as to avoid the need to distribute and register a separate DLL, and make my utility easily distributable as a single .exe. As such, this WTL app is a measly 108K, and has minimal runtime requirements.

The application can create, test and apply patch files, which, if you don't know, are files that represent the deltas between two files so that an original file can be changed to a newer version by "patching", or applying a file that is (hopefully!) much smaller than the new version. Seeing as the two DLLs, mspatcha.dll (apply) and mspatchc.dll (create) are provided by MS, it is obvious that they use patching techniques in Windows installer.

Program overview

The app is a WTL dialog app created with the WTL wizard. Obviously you will need to install the WTL SDK to build the app, but I was nice enough to include a release exe in the zip anyway.

There is a reusable class CPatch in patcher.cpp/h that performs all the needed DLL loading/unloading and patch functions. It is pretty self explanatory. Kudos to Alessandro again, as I pasted the code from his COM component, and converted it from there.

There is an exception class, CPatchError() that is thrown in the event of any patch failures. It does the job of decoding the errors and optionally displaying a MessageBox. Obviously you will need to wrap calls to the class in try..catch.

Most of the rest of the APP is WTL boilerplate, with the obvious exception of maindlg.h, which contains all the UI code. CMainDlg is derived from CPatch. The actual patch operations are run in a separate thread so as to allow a Cancel button to interrupt the process. You will note that I used the default extension of .ptx for patch files, this was arbitrary. I don't know if ptx is a currently common extension type. FYI, the blue triangle icon is the Greek symbol for delta, meaning change.

I included a couple files, jabberwocky.txt and jabberwocky.ptx so that the apply patch functionality can be tried. After running the patch, the full text of jabberwocky will be patched in, instead of just the first verse!

The UI state is persisted to the registry, so that the UI settings on application close are reloaded on app restart. A little gold plating there :-)

My next objective is to make a patcher than can operate on the contents of two directories, similar to other commercial patch apps such as RTP. Another thing I may do is, add command line handing to this app, and/or make a console app patcher.

As Alessandro states in his posting, the mspatchc.dll (create patch) is probably not on your PC currently, but can be freely downloaded as part of the Windows installer SDK. mspatcha.dll (apply patch) should be on your PC if you have IE 5 installed.

Hope you find this interesting and useful, as I do all the great postings at this phenomenally cool site!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
Brit living in USA
C++ Windows/Unix developer

Comments and Discussions

GeneralNot working... Pin
Member 130971717-Oct-04 16:37
MemberMember 130971717-Oct-04 16:37 
GeneralRe: Not working... Pin
SGarratt20-Oct-04 4:52
MemberSGarratt20-Oct-04 4:52 
GeneralRe: Not working... Pin
SGarratt20-Oct-04 4:53
MemberSGarratt20-Oct-04 4:53 
GeneralRe: Not working... Pin
AlexEvans22-Jan-06 20:27
MemberAlexEvans22-Jan-06 20:27 
GeneralRe: Not working... Pin
NOELPG3010-Jul-06 17:32
MemberNOELPG3010-Jul-06 17:32 
GeneralRe: Not working... Pin
dcsoft18-Dec-08 7:53
Memberdcsoft18-Dec-08 7:53 
GeneralNeat Pin
McGarrah27-Mar-02 17:06
MemberMcGarrah27-Mar-02 17:06 
GeneralRe: Neat Pin
SGarratt28-Mar-02 5:17
MemberSGarratt28-Mar-02 5:17 
GeneralRe: Neat Pin
McGarrah28-Mar-02 8:04
MemberMcGarrah28-Mar-02 8:04 
GeneralRe: Neat Pin
NOELPG3010-Jul-06 18:06
MemberNOELPG3010-Jul-06 18:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.