Skip to main content

Getting .NET COM Interop DLLs Working

I recently finished working on a macro program where the software’s interface is COM.  Everything worked great until I wanted to transfer the macro over to a test client computer.  The program I was writing the macro for requires some registry entries, so I assumed that was all I needed to do.  After about 2 hours of having issues I figured out how to get the macro working on computers other than the one I developed the macro on.

What happens automatically when developing COM innerop projects in Visual Studio is that the IDE automatically registers the DLL file behind the scenes, so when the program that is going to use the macro starts up, it can find the DLL file (assuming the “register for COM Interop” is checked in project properties).

When transferring over the macro DLL(s), the client computer does not have the correct registry entries, so when the program attempts to load the macro, it will fail because it can’t find the macro DLL(s).

Things I learned:

  • regsrv does not work on .NET DLLS, you must use regasm.exe (included in the .NET framework).
  • just running regasm.exe with the dll name is not enough (there are two methods to getting the DLL visible to COM)

The method I used:
This method is good if you only want one program to see your DLLs, this does not register it with the GAC.
In your project properties inside Visual Studio 2005:

  • Select the “Signing” tab, check the “Sign the assembly” checkbox.
  • From the drop-down box, select <new>, fill out the fields in the pop-up (eg. key name and password).
  • Creating a key for your DLL means that it will disallow people to create a DLL with the same name as yours and so the .NET framework can properly manage dependencies.  If you don’t do this step you will get a warning when you try to run the regasm step below.
  • Figure out where the regasm file is so we can use it.  This step isn’t necessary if you use a console window inside Visual Studio. (for .net 2.0 it is in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe), regasm can’t be called with “regasm …” inside a normal console window, unless you added your own dos “shortcut” to the exe.
  • Copy all of your output files to where you want them to be.  So for my macro, I had a directory inside the application’s add-on folder.
  • Create a  text/BAT file  in the same directory
  • include this command in the BAT file:  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm macroname.dll /codebase /regfile:install.reg
  • run the bat file in a console window, it will generate a reg file that you can use to install the necessary registry entries to make the DLL visible to your selected DLL file.  Remember that the BAT file needs to be executed in the directory that you intend to run the macro from.  When the REG file is created, it adds various direct paths to the directory, so we need the regasm utility to use the correct path.

Now you can merge the REG file from anywhere in the user’s computer.  It will register the DLL file so that your specified program will find it.  When we write the regasm command line, take note of a few things.  The codebase switch is the directory where the DLLs are located.  the regfile switch is the filename you want the registry install file.  You can run regasm without the regfile switch, but it will install the registry keys directly into the registry.  This is fine, but for me having a reg file is more convenient.

Popular posts from this blog

ChatGPT is a new, and faster, way to do programming!

Currently ChatGPT is in a free “initial research preview” . One of its well known use cases at this point is generating software code. I’ve also just used it to write most of this article… Well, actually a future article about cleaning up SRT subtitle files of their metadata faster than I have been by hand with Notepad++ and its replace functionality. Update: I recorded a screencast of writing the SRT subtitle cleaner application loading and processing portion. I relied heavily on ChatGPT for code. It was a fun process! https://youtu.be/TkEW39OloUA ChatGPT, developed by OpenAI, is a powerful language model that can assist developers in a variety of tasks, including natural language processing and text generation. One such task that ChatGPT can help with is creating an SRT cleaner program. SRT, or SubRip Subtitle, files are commonly used to add subtitles to video files. However, these files can become cluttered with unnecessary information, such as timing lines or blank spaces. To clean...

Theme error in 2010s Android App after AppCompat Migration

I plan on releasing a lot of my old work as GPL open source, but most of it has aged to the point that it no longer functions, or if it does work it’s running in compatibility mode. Basically it’s no longer best practices. Not a good way to start off any new public GPL projects, in my opinion. The current project I’m working on is an Android app that calculates star trails meant to help photographers get or avoid that in their night time photos. For now I’m going to skip some of the import process because I didn’t document it exactly. It’s been mostly trial and error as I poke around Android Studio post import. The Android Studio import process… Removing Admob Google Play code before the project would run at all. After removing dependencies, it kind of worked, but when running it in the emulator it shows a pop-up message saying that the app was developed for an old version of Android. Going through the process of updating code to match current best practices… I had the IDE convert the ...

Blogger Notable theme pop-up header issue fix (thanks to Gemini Pro)

I've made a few half hearted attempts over the years to to fix Blogger's Notable theme's rendering of the pop-up header that shows up when you scroll down the page a decent amount and then pull back to reveal that secondary header. On Chrome mobile I noticed a gray box that forms next to the magnifying glass icon. I never looked in detail on  Chrome desktop, but it had an issue as well which I'll detail below.  If you are looking for a solution and don't want all of the extra talk about how I was able to find it, here it is:  .centered-top-container .sticky .main_header_elements { overflow : hidden !important ; } I decided to try using Gemini Pro 2.5 to see if it was capable of finding the issue and giving me a fix. Turns out that it was able, but it took a bit of collaboration back and forth to find the actual problem.  Here is a modified article I asked it to give me based on our debugging chat (it was very colorful in the article which I scaled back a lot, ...