How do I register a .NET COM DLL with Regsvr32?
我有一个使用COM DLL的VB6应用程序。 DLL是用C#编写的。 在C#项目属性中,选中了"注册COM互操作"选项。 VB6应用程序可以在我的开发机器上正常工作。 C#代码完全遵循此格式:CodeProject C#COM示例
部署到其他计算机时,Regsvr32.exe在尝试注册DLL时出现以下错误:
1 | The module"MyCOM.dll" was loaded but the entry-point DLLRegisterServer was not found. |
这是什么意思? 我读过的有关COM DLL的任何教程/文档都没有提及"入口点DLLRegisterServer"。
我们在其他计算机上使用RegAsm.exe时遇到了主要问题,因此我们确实需要一个可以在其中运行regsvr32.exe的解决方案,该解决方案将对我们部署到的任何计算机(例如XP,Vista,Windows 7,x86计算机,x64 机器等)
我需要在C#代码中添加什么才能使其可通过regsvr32.exe注册?
你不能 托管的[ComVisible]类库需要向Regasm.exe注册。
您可以从IDE的"项目+属性","构建"选项卡,"注册COM互操作"复选框中进行操作。 如果运行Regasm.exe,通常需要/ codebase命令行选项,这样就不必将程序集放在GAC中。 另一个选择是让Regasm.exe使用/ regfile选项生成一个.reg文件。 您只需在目标计算机上运行它即可更新注册表。
编辑:刚看到"主要问题"的评论。 请注意它们是什么,比/ codebase短。 您必须在64位计算机上选择正确的版本。 那里有两个。 而且,您需要提升权限的命令提示符,以便UAC不会停止前进。
您可以制作一个简单的Windows应用程序,并使用下面的代码注册COM DLL。 确保添加清单文件以管理员身份运行:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | ... 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(); } } } |