Horizontal Menu Bar

Follow C# Tutorials

Wednesday, 31 October 2012

C# Tutorials : How to make a COM DLL

Yesterday I was working on a C#.net solution. The solution is quite big and has so many projects added in it. Some of these projects require a COM DLL as a reference. I was working on a machine, where the solution was getting built successfully, then for some reason I moved all code to some other machine. However this time when I rebuilt the Solution on new machine, I got so many errors only related to COM DLL.

The error was like –

“A reference to ‘[DLL_NAME]’ could not be loaded. Please make sure that the file is accessible, and that it is a valid assembly or COM component.”
Initially I struggled to understand the error and then on how to make a COM object DLL. Because it was quite a long time back almost 4 years ago I created a COM dll so I forgot the steps to make a com object. J

And then it just clicked in my mind to write up a step by step article on how to create a COM object DLL for my some those friends who are still struggling to create a COM dll. J

Here are the steps. Let’s start then J
  • The first step is to open a command prompt. You will need to type “cmd” in run box and hit enter button. 
make a com object
How to make a com dll - open Command Prompt
  • “TlbImp.exe” is an executable file which you need to create a com object from existing valid type library dll.
    • If you are working on VS-2010 then follow the steps –
      • If a machine is 32 bit where you are making your COM dll then go to following location in opened command prompt –
                     %ProgramFiles%\Microsoft SDKs\Windows\v7.0A\bin
      • If a machine is 64 bit then go to following location in command prompt –
                      %ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\bin
    • VS-2005 users follow the steps –
      • 32 bit users, go to following location -
                          %ProgramFiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin 
      • 64 bit users, go to following location –
                           %ProgramFiles(x86)%\Microsoft Visual Studio 8\SDK\v2.0\Bin 
  •  Now type following command in command prompt and hit enter as shown -
                          TlbImp.exe fully_qualified_path_of_your_dll
how to make a com dll
  
  • If a dll is valid type library then the above command will create a successful COM dll object in location from where you are executing “tlbimp.exe” with the same dll name.
  • Copy this newly created valid COM object to your project reference location and build the solution. The error will not appear again… J

Follow C# Tutorials