Avoid DLL Hell with Registration-free COM

Avoid DLL Hell with Registration-free COM

eusable, dynamically linked components are generally a good idea, because they allow you to leverage code and save memory rather than reinvent the wheel. But with thousands of developers leveraging thousands of native DLLs?and no OS-enforced systematic control of versioning or installation, developers often overwrite their own and others’ DLLs during installation, a process colloquially known as “stomping.”

One might hope that those days are behind us, given .NET framework’s Global Assembly Cache (GAC), assembly manifests, and managed code components, but the fact is if you still develop with VB6 Controls, the C++ Active Template Library (ATL), or ActiveX, your interop applications might still be contributing to someone’s DLL hell. DLL hell, is a common description of what happens when an application loads and executes code from a DLL whose name is the same as a referenced DLL, but whose behavior differs from the developer’s expectations. Most often, this happens when an installer copies and registers an older version of a DLL, replacing a newer version of that component or overwriting a different one with the same name, or?less commonly?by introducing a backward-breaking change in a newer DLL.

In either case, applications that were working fine suddenly break, either because the older DLL doesn’t support the functionality of the newer DLL that the applications expected to load, or because the newer DLL breaks functionality that was working fine in a previous version.

But if your clients run Windows XP SP2, Windows Server 2003 or newer Windows OSs, Microsoft’s introduction of Registration Free COM (Ref-free COM) can reduce or eliminate DLL conflicts. This article provides an overview of using Reg-free COM with managed .NET code, and offers a development scenario that illustrates deploying a COM component with XCOPY.

Reg-free COM In Action
Here’s a quick peek at Reg-free COM in action.

To build the solution for the reg-free COM test, unzip the downloadable code associated with this article to a local drive. First, open the WaveOutComControl solution and build the solution. Next, open the FlashCards solution in the /FlashCards_CSharp directory and rebuild that solution. You will see one warning, which you can safely ignore. From the debug directory of the FlashCards solution, copy FlashCards.exe twice, once to the /Reg directory and again to the /RegFree directory.

Visual Studio registers the included WaveOut.ocx control automatically when you build the solution. To clear the registry entries and set your machine up for the Reg-Free demonstration (mimicking a client machine where the control would not be registered), go to a Visual Studio .NET command prompt and type the following command to unregister the control: regsvr32 /u WaveOut.ocx.

After performing these steps, in the
directories you’ll have two copies of the sample application, “FlashCards.” FlashCards is a C# .NET 2.0 Windows Forms application that presents Spanish words and their English counterparts. It reads the words from an XML file called lesson1.xml via an XPATH query and randomly presents the words to end users. If present, FlashCards uses the WaveOut.ocx ActiveX control to play the associated word .wav file, giving FlashCards users the opportunity to hear the word with native pronunciation. WaveOut.ocx is a native COM control written using C++ and MFC. The sample application demonstrates how to use this control without creating or modifying any registry entries?in other words, registration-free. Without altering any existing registry entries or overwriting any existing DLLs, you’ll see how Reg-free COM lets supporting versions of Windows load and use multiple copies of identically-named DLLs.

The /Reg directory is set up as a standard “old-COM-style” application executable, FlashCards.exe, which depends on WaveOut.ocx being registered as a COM object in the registry. In contrast, /RegFree contains the same sample application, but built the Reg-free COM way. A quick comparison of the two directories reveals that /RegFree contains a file named FlashCards.exe.Manifest which I’ll discuss later.

Navigate to the /Reg directory on the command line and attempt to run our sample application: Flashcards.exe. Because of the COM dependency, you’ll get the error shown in Figure 1.

Figure 1. COM Lookup Exception: This is the standard error message that results when an application calls an unregistered COM component.

Remember, at this point, (after unregistering the .ocx control earlier), you’ve run no installer that registered the component, nor have you manually registered the control with REGSVR32. Consequently, the Native Assembly Loader complains that the control referenced in the FlashCard program is not registered.

Now, step into the /RegFree subdirectory and run FlashCards.exe. This time, the application runs without the COM error. When the application opens, use the toolbar to open the lesson1.xml file. For any word, you should be able to press the “Play Word” button to cause the ActiveX control to play the associated .wav file.

Author’s Note: The ActiveX control used in the /Regfree directory is exactly the same as the one used in the /Reg directory, but we’ve invoked it the Reg-free way!

Building for Reg-free COM
With Visual Studio.NET 2005, building registration free applications is simple. Before you open the FlashCards solution, however, you will have to register the WaveOut.ocx control. Somewhat ironically, although you can launch a deployed application without registering COM controls, you do have to register COM components on development machines where you’re building applications that use Reg-free COM?for now, Reg-free COM is strictly runtime.

Back at the command line, navigate to the sample code folder and type the following command:

   regsvr32 WaveOut.ocx

That command registers the component, so you can now load the FlashCards application from the /Reg directory into Visual Studio.

From the Reg/FlashCards folder, open the FlashCards solution file. In Solution Explorer, open the References folder. When I added the ActiveX control WaveOut.ocx to the application form (via Toolbox->Right Click->Choose Items->COM), VS added two references to the project: WaveOutLib and AxWaveOutLib. These two files are automatically generated by Visual Studio through a call to aximp.exe to provide a wrapper for the ActiveX control. Set the isolated flag to “True” to allow for Reg-free deployment (see Figure 2). You can select either DLL, as Visual Studio will update the other one to match automatically.

Figure 2. Set COM Component Isolation: Here’s the property setting to isolate an interop COM component for a Reg-free build.

Now, when you build (either release or debug) the FlashCards application, VS will also create an XML manifest file named FlashCards.exe.Manifest that contains the ClassID and type library information for the control?the same information that was previously stored in the registry.

Here’s a portion of the manifest:


With the manifest created, simply copying the release folder (using XCOPY) to any client will let that client use the control without any entries in the Registry. Copying the files is the only step required for interop deployment, but be sure to review the checklist in the next section before using Reg-free COM.

Reg-free COM Checklist

  1. The end-user’s operating system must be Windows 2003 Server or Windows XP with Service Pack 2. Reg-free COM will not work on earlier OSs or earlier XP service packs.
  2. Verify that the COM component is registered on the development box that does the build. The component must be properly registered for Visual Studio to generate the manifest information required to use Reg-free COM.
  3. Do not use Reg-free COM unless you wish the component to be isolated. In other words, if you want to share the component with other applications, you must make sure it’s properly registered on the target machines.
  4. Test on a clean machine (one where the components are not registered). That’s because you won’t get a warning if Reg-free COM deployments are actually accessing the registered version of a COM control. A clean machine is the best way to verify that an application using Reg-free COM is functioning as expected.
  5. Think through dependencies. For Reg-free COM, use only components that can function in isolation. For example, graphics components make good candidates for isolation, but system files do not.
  6. Keep it legal. Third-party COM components (including Office) are not typically redistributable royalty-free.


Share the Post:
Remote Learning

Revolutionizing Remote Learning for Success

School districts are preparing to reveal a substantial technological upgrade designed to significantly improve remote learning experiences for both educators and students amid the ongoing

Revolutionary SABERS Transforming

SABERS Batteries Transforming Industries

Scientists John Connell and Yi Lin from NASA’s Solid-state Architecture Batteries for Enhanced Rechargeability and Safety (SABERS) project are working on experimental solid-state battery packs

Build a Website

How Much Does It Cost to Build a Website?

Are you wondering how much it costs to build a website? The approximated cost is based on several factors, including which add-ons and platforms you

Iran Drone Expansion

Iran’s Jet-Propelled Drone Reshapes Power Balance

Iran has recently unveiled a jet-propelled variant of its Shahed series drone, marking a significant advancement in the nation’s drone technology. The new drone is poised to reshape the regional

Solar Geoengineering

Did the Overshoot Commission Shoot Down Geoengineering?

The Overshoot Commission has recently released a comprehensive report that discusses the controversial topic of Solar Geoengineering, also known as Solar Radiation Modification (SRM). The Commission’s primary objective is to

Remote Learning

Revolutionizing Remote Learning for Success

School districts are preparing to reveal a substantial technological upgrade designed to significantly improve remote learning experiences for both educators and students amid the ongoing pandemic. This major investment, which

Revolutionary SABERS Transforming

SABERS Batteries Transforming Industries

Scientists John Connell and Yi Lin from NASA’s Solid-state Architecture Batteries for Enhanced Rechargeability and Safety (SABERS) project are working on experimental solid-state battery packs that could dramatically change the

Build a Website

How Much Does It Cost to Build a Website?

Are you wondering how much it costs to build a website? The approximated cost is based on several factors, including which add-ons and platforms you choose. For example, a self-hosted

Battery Investments

Battery Startups Attract Billion-Dollar Investments

In recent times, battery startups have experienced a significant boost in investments, with three businesses obtaining over $1 billion in funding within the last month. French company Verkor amassed $2.1

Copilot Revolution

Microsoft Copilot: A Suit of AI Features

Microsoft’s latest offering, Microsoft Copilot, aims to revolutionize the way we interact with technology. By integrating various AI capabilities, this all-in-one tool provides users with an improved experience that not

AI Girlfriend Craze

AI Girlfriend Craze Threatens Relationships

The surge in virtual AI girlfriends’ popularity is playing a role in the escalating issue of loneliness among young males, and this could have serious repercussions for America’s future. A

AIOps Innovations

Senser is Changing AIOps

Senser, an AIOps platform based in Tel Aviv, has introduced its groundbreaking AI-powered observability solution to support developers and operations teams in promptly pinpointing the root causes of service disruptions

Bebop Charging Stations

Check Out The New Bebob Battery Charging Stations

Bebob has introduced new 4- and 8-channel battery charging stations primarily aimed at rental companies, providing a convenient solution for clients with a large quantity of batteries. These wall-mountable and

Malyasian Networks

Malaysia’s Dual 5G Network Growth

On Wednesday, Malaysia’s Prime Minister Anwar Ibrahim announced the country’s plan to implement a dual 5G network strategy. This move is designed to achieve a more equitable incorporation of both

Advanced Drones Race

Pentagon’s Bold Race for Advanced Drones

The Pentagon has recently unveiled its ambitious strategy to acquire thousands of sophisticated drones within the next two years. This decision comes in response to Russia’s rapid utilization of airborne

Important Updates

You Need to See the New Microsoft Updates

Microsoft has recently announced a series of new features and updates across their applications, including Outlook, Microsoft Teams, and SharePoint. These new developments are centered around improving user experience, streamlining

Price Wars

Inside Hyundai and Kia’s Price Wars

South Korean automakers Hyundai and Kia are cutting the prices on a number of their electric vehicles (EVs) in response to growing price competition within the South Korean market. Many

Solar Frenzy Surprises

Solar Subsidy in Germany Causes Frenzy

In a shocking turn of events, the German national KfW bank was forced to discontinue its home solar power subsidy program for charging electric vehicles (EVs) after just one day,

Electric Spare

Electric Cars Ditch Spare Tires for Efficiency

Ira Newlander from West Los Angeles is thinking about trading in his old Ford Explorer for a contemporary hybrid or electric vehicle. However, he has observed that the majority of

Solar Geoengineering Impacts

Unraveling Solar Geoengineering’s Hidden Impacts

As we continue to face the repercussions of climate change, scientists and experts seek innovative ways to mitigate its impacts. Solar geoengineering (SG), a technique involving the distribution of aerosols

Razer Discount

Unbelievable Razer Blade 17 Discount

On September 24, 2023, it was reported that Razer, a popular brand in the premium gaming laptop industry, is offering an exceptional deal on their Razer Blade 17 model. Typically

Innovation Ignition

New Fintech Innovation Ignites Change

The fintech sector continues to attract substantial interest, as demonstrated by a dedicated fintech stage at a recent event featuring panel discussions and informal conversations with industry professionals. The gathering,

Import Easing

Easing Import Rules for Big Tech

India has chosen to ease its proposed restrictions on imports of laptops, tablets, and other IT hardware, allowing manufacturers like Apple Inc., HP Inc., and Dell Technologies Inc. more time

Semiconductor Stock Plummet

Dramatic Downturn in Semiconductor Stocks Looms

Recent events show that the S&P Semiconductors Select Industry Index seems to be experiencing a downturn, which could result in a decline in semiconductor stocks. Known as a key indicator

Anthropic Investment

Amazon’s Bold Anthropic Investment

On Monday, Amazon announced its plan to invest up to $4 billion in the AI firm Anthropic, acquiring a minority stake in the process. This decision demonstrates Amazon’s commitment to

AI Experts Get Hired

Tech Industry Rehiring Wave: AI Experts Wanted

A few months ago, Big Tech companies were downsizing their workforce, but currently, many are considering rehiring some of these employees, especially in popular fields such as artificial intelligence. The

Lagos Migration

Middle-Class Migration: Undermining Democracy?

As the middle class in Lagos, Nigeria, increasingly migrates to private communities, a PhD scholar from a leading technology institute has been investigating the impact of this development on democratic