我有一个使用COM DLL的VB6应用程序。 DLL是用C#编写的。在C#项目属性中,我选中了“Register for COM interop”选项。 VB6应用程序在我的开发机器上运行良好。 C#代码完全遵循以下格式:CodeProject C# COM Example
部署到其他计算机时,Regsvr32.exe在尝试注册DLL时出现以下错误:
The module "MyCOM.dll" was loaded but the entry-point DLLRegisterServer was not found.
这是什么意思?没有教程/文档我读过关于COM DLL的任何关于“入口点DLLRegisterServer”的内容。
我们在不同的机器上使用RegAsm.exe时遇到了MAJOR问题,所以我们真的需要一个解决方案,我们可以运行regsvr32.exe,它将适用于我们部署的任何机器(即XP,Vista,Windows 7,x86)机器,x64机器等。)
我需要将哪些内容添加到我的C#代码中才能使用regsvr32.exe注册?
答案 0 :(得分:19)
你做不到。需要使用Regasm.exe注册托管的[ComVisible]类库。
您可以使用Project + Properties,Build选项卡,Register for COM interop复选框从IDE执行此操作。如果运行Regasm.exe,通常需要/ codebase命令行选项,因此您不必将程序集放在GAC中。另一个选择是让Regasm.exe使用/ regfile选项生成.reg文件。您只需在目标计算机上运行它即可更新注册表。
编辑:刚看到“重大问题”的评论。请注意它们是什么,来自/ codebase。您必须在64位计算机上选择正确的版本。那里有两个。并且您需要一个提升的命令提示符,以便UAC不会停止它。
答案 1 :(得分:0)
您可以创建一个简单的Windows应用程序并使用下面的代码注册COM DLL。确保添加清单文件以管理员身份运行:
...
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();
}
}
}