Results 1 to 3 of 3

Thread: 10 easy steps to COM & DCOM Clean Living

Threaded View

  1. #1

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Lightbulb 10 easy steps to COM & DCOM Clean Living

    A few years back I was project testing a large and complex VB6 project which employed hundreds of ActiveX DLLs and OCXs.

    I learned there is a right way and a wrong way to do things when developing COM objects.

    Every COM object has a certain number of Publicly exposed member functions which take a fixed number of arguments. If you make changes to the existing interface, it will in effect, change that object's signature (interface). This is called breaking compatibility.

    Note: adding new public members to the interface will not break compatibility.

    When this happens, you have 2 entries in your registry. The old object (with the old signature) and the new object. Repeat this procedure and you will wind up with hunderds of dangling entries in your registry which can lead to problems and bloat up your registry (bad).

    So when we are working with a COM object we are smart and set up our IDE to be Binary Compatible, so that as long as our interface does not change, we will keep using the same registry entry. So what happens when we must break Compatibility?

    Follow these steps to keep your registry clean as a whistle. Ideally, there should be one and only one entry for any given COM object.

    1) Create a new project and develop an ActiveX OCX or DLL.
    2) Compile the binary.
    3) The IDE does this for you, but we can do it anyway. Register the Binary (regsvr32 Path\FileName)
    4) Go to Project...Settings...Component and choose Binary Compatibility - using the previously compiled binary as a reference.
    5) Recompile the binary.
    6) Oops! After further testing you see you have to change an existing Public Function, or add an argument to an existing function.
    7) You are ready to Break Compatibility.
    8) You must now UnRegister the old binary. (regsvr32 -u Path\FileName)
    9) Delete the old binary from disk (one could back it up somewhere safe)
    10) Resume at step (2) above with the COM object's new signature.

    So what happens when we are working with an ActiveX EXE? No problem! We simply replace step (8) with a command-line execution (Path\exeName /unregserver)

    Steps (3) and (8) can be made much easier if you set things up a little smarter. We can automate the Registry/UnRegistry of an object type using Windows Explorer.

    1) 2x click the OCX file on disk, bringing up Window's "File Association" applet
    2) Instead of choosing a program, we have to Browse for it
    3) Browse to C:\Windows\System32 and choose the file REGSVR32.EXE
    4) Now we can 2x click any OCX file and Register it. How do we get it to UnRegister? Continue on...
    5) Open up your favorite registry editor (I use regedit) go to Start...Run and enter REGEDIT
    6) Go to the root hive and go to Edit...Find
    7) Type in regsvr32
    8) It should take you to HKEY_CLASSES_ROOT\Applications\regsvr32.exe
    9) Open up the [+] symbol. The tree expands out to Shell...Open...Command
    10) Copy the Default String under the command key item to the clipboard
    11) Create a new Key under the shell key and call it UnRegister
    12) Under the new Unregister key, create another key called command
    13) Paste the clipboard contents into the default string, and make it look like this:
    "C:\WINDOWS\system32\regsvr32.exe" "-u" "%1"

    The above should also be applied to DLLs.

    Well, your done! Now you can use Windows explorer to Register and Unregister DLLs & OCXs with a couple mouse clicks! Try it: Right click on any DLL or OCX and you can painlessly Register and UnRegister them from the context menu.

    You will notice I put my binaries in C:\Program Files\Common Files. This is a great place to put your binary ActiveX components. Even better - you could make your own folder matching youR Project Name, and put your binaries in there.

    Well, follow the above guidelines and you will be practicing COM & DCOM Clean Living!
    Attached Images Attached Images  
    Last edited by Dave Sell; Dec 1st, 2004 at 12:35 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width