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

Printing to file in Linux WINE

I noticed that this post has been sitting as a draft since 2011. At this point I have no idea if it’s useful or what I was even doing, but I might as well make it public in case someone can find it helpful! So I’ve been trying to get one of those PDF print drivers working in WINE without success. I then came upon a process that might work. When printing you need to select the checkbox “Print to file” that creates a .prn file. Just Linux things... I was using a program that only has printing facilities, but I want to export around 100 pages of text and images. Once you have the .prn (postscript) file, you can do any number of things to it. In my case I want the postscript file to be converted to HTML. I am also considering PDF format because that has more conversion options to eventually get me to HTML or plain text. sudo apt-get install cups-pdf Or it looks like that package might have changed to this… sudo apt-get install printer-driver-cups-pdf Where PDFs would be generated in /home/...