15

I have a VB6 application that uses a COM DLL. The DLL is written in C#. In the C# project properties I have checked the "Register for COM interop" option. The VB6 app works fine on my development machine. The C# code follows this format exactly: CodeProject C# COM Example

When deploying to other machines, Regsvr32.exe gives me the following error when I try to register the DLL:

The module "MyCOM.dll" was loaded but the entry-point DLLRegisterServer was not found.

What does this mean?
No tutorials/documentation I've read about COM DLLs say anything about "entry-point DLLRegisterServer".

We have had MAJOR problems using RegAsm.exe on different machines, so we really need a solution where we can run regsvr32.exe instead that will work for any machine that we deploy to (i.e. XP, Vista, Windows 7, x86 machines, x64 machines, etc.)

What do I need to add to my C# code to make it register-able with regsvr32.exe?

shA.t
  • 16,580
  • 5
  • 54
  • 111
Mike Webb
  • 8,855
  • 18
  • 78
  • 111

2 Answers2

23

You can't. Managed [ComVisible] class libraries need to be registered with Regasm.exe.

You can do it from the IDE with Project + Properties, Build tab, Register for COM interop checkbox. If you run Regasm.exe you usually want the /codebase command line option so you don't have to put the assembly in the GAC. Yet another option is to let Regasm.exe generate a .reg file with the /regfile option. You'd just run that on the target machine to get the registry updated.

Edit: just saw the "major problems" remark. Note sure what they are, short from /codebase. You do have to pick the right version on 64-bit machines. There are two. And you need an elevated command prompt so that UAC don't put a stop to it.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • @Hans - 2 questions: What are the 2 versions for 64-bit machines? Is there a way to create, deploy and use the COM DLL in VB6 without registering it? – Mike Webb Nov 16 '10 at 20:59
  • The 32-bit and the 64-bit version. Technically yes with a registry-free COM manifest in the client app. It needs ``. – Hans Passant Nov 16 '10 at 21:04
  • @Mike Webb: As you are doing COM interop with VB6 you need to 1. compile the C# project with an x86 target and 2. use regasm under c:\windows\syswow64. – Dirk Vollmar Nov 16 '10 at 21:32
  • No, regasm is in the framework directory. Framework64 for the 64-bit version but no need to worry about that for a vb6 client. – Hans Passant Nov 16 '10 at 21:39
  • @Hans - So I don't need to use the 64bit version of Regasm for a VB6 client? The COM DLL will only be targeting x86 as well. – Mike Webb Nov 16 '10 at 21:47
  • Right, there is no 64-bit vb6 version that could use it. You don't have to target x86 btw. The bitness is locked in by the version of Regasm. – Hans Passant Nov 16 '10 at 21:48
0

You can make a simple Windows application and use the code below to register COM DLL. Make sure to add the manifest file to run as Administrator:

...

namespace comregister
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string framework = Environment.GetEnvironmentVariable("SystemRoot") + @"\Microsoft.NET\Framework\v2.0.50727\";

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog1.FileName;
                button2.Enabled = true;
                button3.Enabled = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FileInfo fi = new FileInfo(textBox1.Text);
            string fn = fi.FullName.Substring(0, fi.FullName.Length - 4);
            string dll = "\"" + fi.FullName + "\"";
            string tlb = "\"" + fn + ".tlb\"";

            Process p = new Process();
            p.StartInfo.FileName = framework + "regasm.exe";
            p.StartInfo.Arguments = dll + " /tlb:" + tlb + " /codebase";
            p.Start();
            p.WaitForExit();
            label2.Text = "registered";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FileInfo fi = new FileInfo(textBox1.Text);
            string dll = "\"" + fi.FullName + "\"";

            Process p = new Process();
            p.StartInfo.FileName = framework + "regasm.exe";
            p.StartInfo.Arguments = dll + " /unregister";
            p.Start();
            p.WaitForExit();
            label2.Text = "unregistered";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
Jamal
  • 763
  • 7
  • 22
  • 32
user3806621
  • 278
  • 1
  • 6
  • 1
    What if a user has a different version of .NET Framework? In my case I seem to have multiple versions and many does not have RegAsm at all. Only v2.0.50727 and v4.0.30319 does. – Shameel Mohamed Jun 28 '17 at 14:48
  • @ShameelMohamed https://stackoverflow.com/questions/48393660/how-to-find-regasm-location-on-a-machine might help – StayOnTarget Jan 15 '20 at 12:26