Click here to Skip to main content
15,885,683 members
Articles / Operating Systems / Windows

Use RegFree to Solve DLL Hell Even With COM Clients

Rate me:
Please Sign up or sign in to vote.
2.52/5 (8 votes)
25 Feb 20072 min read 39.4K   25   3
An article on using the RegFree capabilities of XP SP2 to solve DLL Hell.

Introduction

This article presents a method of using the RegFree feature even with COM client applications. RegFree is a new capability of Windows to use a local XML file rather than the Registry for the interface details.

Note: "Registry Free" COM is available only on Windows XP SP2, Windows Server 2003, or newer Windows OSs. If you are working with one of these, then you can take advantage of the following method from both your unmanaged applications (COM) as well as your managed ones.

Overview

Prior to .NET, COM components needed to be globally registered on the machine. It was assumed that any new version of a component would replace the previous version, but maintain compatibility with the older version's clients. The term DLL Hell arose to describe the situation in which that compatibility was not preserved. Here is an example of such a situation:

  1. Your application requires the latest version of a third-party OCX.
  2. An application on your customer's machine requires an older version of that third-party OCX.
  3. Neither application works with the OCX version required by the other application.

How to Create the XML Manifest

RegFree COM works by expressing all of the standard component registration information that is typically installed into the system Registry in a file that can be stored in the same folder as the application itself. Getting this file is the difficult part. Luckily, Visual Studio 2005 can do 99% of the work required regardless of whether your client is .NET or VB, or even if you are not the developer of the client.

The method is to create a dummy project (named "Dummy") in VS 2005, set a reference to the COM component(s) you wish to create the XML manifest for, and set its "Isolated" property to True.

When you build the project, the bin/debug or bin/release folder will then have a file titled "Dummy.exe.manifest".

  1. Rename the "Dummy" portion of this file to match your executable.
  2. Open the manifest, and search and replace "Dummy" with the name of your executable.
  3. Finally, place the file in the same location as your executable, along with the copy of the third party component(s) that you require.

Now, it doesn't matter what version of that third-party component is registered on the machine, your application will always use the one in its executable directory.

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


Written By
Web Developer
Canada Canada
Darrin Doherty is founder and CEO of Anjin Consulting Inc., providing custom solutions to the field service industry. Their latest online endeavor is Rep-Protect.com, helping companies protect their online reputations.

Comments and Discussions

 
Questionexported from a .NET assembly and cannot be added as a reference Pin
Patrick Wolf15-Apr-07 15:19
Patrick Wolf15-Apr-07 15:19 
A reference to ... could not be added
The ActiveX type library "..." was exported from a .NET assembly and cannot be added as a reference
Add a reference to the .NET assembly instead.
---------------------------------------------------------------
This happens when I try to add a COM visible .NET assembly in the way you described above.

So I tried to create a manifest by hand but its not working yet.

Basically I am trying very hard to use RegFree Com from Microsoft Access 2003 on XP
Pro .NET 2.0.
I made a class library project in VS 2005 C# (Service.cs & Assembly.cs).

When referencing in from a local installed Access it works fine.
When trying to run it from a different workstation where Test.API.COM.dll is
not registered it doesnt work.
When I put all files into the Office11 folder Access says on startup
"The application has failed to start because the application configuration
is incorrect.."

When I remove this line from the manifest Access starts again but it still
doesnt work to call Test.API.COM.dll
<typelib
tlbid="{2af5c211-13bf-43f9-b200-dce012140422}"
="" version="1.0.0.0" helpdir="" resourceid="0" flags="HASDISKIMAGE">

The event log also points to this line by the way:
Generate Activation Context failed for C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE.Manifest. Reference error message: The operation completed successfully.
Syntax error in manifest or policy file "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE.Manifest" on line 13.

Thank you very much for your help
Patrick Wolf

----------------------------------------------------------------------------------------------
Service.cs (in VS 2005 project)
----------------------------------------------------------------------------------------------
using System.Runtime.InteropServices;
using Microsoft.VisualBasic;

namespace Test.API.COM
{
// [ComVisible(true)]
[ComClass(Service.ClassId, Service.InterfaceId, Service.EventsId)]
public class Service
{
#region "COM GUIDs"
public const string ClassId = "D50636AF-44BF-4A4C-BF41-713070D9ECA2";
public const string InterfaceId = "FBA843CB-D290-4C95-8D04-C72B51A29F06";
public const string EventsId = "491518C7-D50F-4A36-A490-75A93C168E44";
#endregion

public Service():base() {}

public string GetMe(string test){return "return value: " + test;}
}
}

----------------------------------------------------------------------------------------------
AssemblyInfo.cs (in VS 2005 project)
----------------------------------------------------------------------------------------------
....
[assembly: ComVisible(true)]
[assembly: Guid("2af5c211-13bf-43f9-b200-dce012140422")]
....

----------------------------------------------------------------------------------------------
MsAccess VBA Code
----------------------------------------------------------------------------------------------
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim d As Test_API_COM.Service
Set d = New Test_API_COM.Service

MsgBox (d.GetMe("HIPAT"))

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox err.Description & err.LastDllError & err.Source & err.Number
Resume Exit_Command0_Click

End Sub

----------------------------------------------------------------------------------------------
MSACCESS.EXE.CONFIG
----------------------------------------------------------------------------------------------
<configuration>
<startup>
<supportedruntime version="v2.0.50727">



----------------------------------------------------------------------------------------------
MSACCESS.EXE.MANIFEST
----------------------------------------------------------------------------------------------

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestversion="1.0">
<assemblyidentity
version="10.0.4302.0" processorarchitecture="X86" name="MSACCESS.EXE"
type="win32"
="">

<file name="Cafe.Amanda.API.COM.dll"
="" xmlns="urn:schemas-microsoft-com:asm.v1">
<typelib
tlbid="{2af5c211-13bf-43f9-b200-dce012140422}"
="" version="1.0.0.0" helpdir="" resourceid="0" flags="HASDISKIMAGE">
<comclass
clsid="{D50636AF-44BF-4A4C-BF41-713070D9ECA2}"
="" threadingmodel="Apartment"
tlbid="{2af5c211-13bf-43f9-b200-dce012140422}" progid="Cafe_Amanda_API_COM.Service"
name="Cafe_Amanda_API_COM.Service">



----------------------------------------------------------------------------------------------
GeneralPrerequisits to make this work Pin
jerchap27-Feb-07 6:04
jerchap27-Feb-07 6:04 
GeneralRe: Prerequisits to make this work [modified] Pin
DarrinDoherty27-Feb-07 6:58
DarrinDoherty27-Feb-07 6:58 

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.