Click here to Skip to main content
12,999,837 members (49,847 online)
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 7 Jun 2000

UnPatcher: a COM object for patching files

, 7 Jun 2000
Rate this:
Please Sign up or sign in to vote.
An article on patching files.
  • Download demo project - 30 Kb
  • Download source files - 20 Kb
  • Introduction

    Recently I faced myself with a problem that I think is very common among developers: patching a software release.

    There are many tools for doing this, even freeware, but I wanted something similar to the LiveUpdate of a well-known software.

    Since all patching software I found is not free-source, I started writing my patch algorithm without good results: the patch file it generated is almost the same size of the original file.

    I started asking around for help, but none can get me out of trouble. Then an help arrived: Blake Miller told me to look in the Platform SDK. I looked and I found a very-not documented set of APIs for creating and applying patches.

    The problems and the solutions

    The only documentation to the APIs is in a file called PatchApi.h. This set of function isn't very complex so I understand without problems what each function does (apart from the flags, if someone know something more, please tell me).

    The problem is that there is an import library only for the patch creation routines (CreatePatch and CreatePatchEx) and not for patch applying functions. So I tried creating one without success.

    The only solution I found was to dynamically load the DLLs implementig the API. This is not so bad: you can ship the patch program without the patch creation DLL.

    You may have noted that I wrote DLLs (plural). This is true: there are two DLLs implementig this API: mspatchc.dll (creation) and mspatcha.dll (apply). I've not included these DLLs in the zips (I don't know if I can redistribute them). You can find the creation dll in the Platform SDK and the apply dll comes with MSIE 5.01 (maybe with other MS products, I looked on MSDN and found only IE carrying this).

    The last step

    I finally got it working so I wrote a simple COM dll implementing the logic of patching. The object is very simple: it has 3 properties, 4 methods and 1 event.


    • SourceFile: The old file name or the file to patch.
    • DestinationFile: The new file name or the patched file to generate.
    • PatchFile: Is the patch file name to be created or applyed.


    • CreatePatch: Creates the patch file.
    • TestPatch: Tests the patch file
    • ApplyPatch: Applies the patch file
    • GetFileSignature: Returns a unique (?) file signature


    • OnProgress: Called during processing.

    Final notes

    It compiles under UNICODE, but it's not well tested.

    The included demo is written in Visual Basic. To get it to work, you first need to register the UnPatcher DLL by doing:

    regsvr32 UnPatcher.dll


    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

    Alessandro Vergani
    Software Developer (Senior)
    Italy Italy
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    Generalmspatchc.dll is buggy Pin
    Anonymous14-Mar-02 3:37
    memberAnonymous14-Mar-02 3:37 
    GeneralHelp: You can find the creation dll in the Platform SDK Pin
    Ben Burnett12-Jun-00 0:13
    sussBen Burnett12-Jun-00 0:13 
    GeneralRe: Help: You can find the creation dll in the Platform SDK Pin
    Alessandro Vergani12-Jun-00 6:48
    sussAlessandro Vergani12-Jun-00 6:48 

    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.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web02 | 2.8.170624.1 | Last Updated 8 Jun 2000
    Article Copyright 2000 by Alessandro Vergani
    Everything else Copyright © CodeProject, 1999-2017
    Layout: fixed | fluid