我有一个使用COM DLL的VB6应用程序。 DLL是用C#编写的。在C#项目属性中,已选中“注册COM互操作”选项。 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时遇到了主要问题,因此我们确实需要一个可以在其中运行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。确保添加清单文件以管理员身份运行:
...
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();
}
}
}