Click here to Skip to main content
Click here to Skip to main content
Go to top

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.

    Properties

    • 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.

    Methods

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

    Events

    • 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
    


    License

    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

    Share

    About the Author

    Alessandro Vergani
    Software Developer (Senior)
    Italy Italy
    No Biography provided
    Follow on   Twitter

    Comments and Discussions

     
    Generalmspatchc.dll is buggy PinmemberAnonymous14-Mar-02 3:37 
    GeneralHelp: You can find the creation dll in the Platform SDK PinsussBen Burnett12-Jun-00 0:13 
    GeneralRe: Help: You can find the creation dll in the Platform SDK PinsussAlessandro Vergani12-Jun-00 6:48 

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

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

    | Advertise | Privacy | Mobile
    Web04 | 2.8.140921.1 | Last Updated 8 Jun 2000
    Article Copyright 2000 by Alessandro Vergani
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Service
    Layout: fixed | fluid