gpt4 book ai didi

Windows 7 64Bit 上的 .NET COM Interop 让我头疼

转载 作者:行者123 更新时间:2023-12-04 15:37:44 27 4
gpt4 key购买 nike

.NET COM 互操作到目前为止一直运行良好。自从我升级到 Windows 7 后,我的 .NET COM 对象就无法再工作了。

我的 COM 对象很简单:


namespace Crap
{
[ComVisible(true)]
[Guid("2134685b-6e22-49ef-a046-74e187ed0d21")]
[ClassInterface(ClassInterfaceType.None)]
public class MyClass : IMyClass
{

public MyClass()
{}

public void Test()
{
MessageBox.Show("Finally got in here.");
}

}
}



namespace Crap
{
[Guid("1234685b-6e22-49ef-a046-74e187ed0d21")]
public interface IMyClass
{

}
}

assembly is marked ComVisible as well.

I register the assembly using

regasm /codebase /tlb "path"

注册成功(管理员模式)。
我尝试了 regasm 32 和 64 位。两次我都收到错误

“ActiveX 组件无法创建对象 Crap.MyClass”使用此 vbscript:

dim objReg
Set objReg = CreateObject("Crap.MyClass")
MsgBox typename(objReg)

fuslogvw 也没有给我任何提示。
该 COM 对象在我的 Vista 32 位机器上完美运行。

我不明白为什么我无法通过谷歌搜索解决该问题的方法..我真的是唯一遇到过这个问题的人吗?

查看 OleView 我看到我的对象已成功注册。我也可以创建其他 COM 对象..它只不适用于我自己的对象。

谢谢,
凯文

最佳答案

我不是 C# 人,但这里有一个我从 VB.net 转换而来的示例。请注意,我必须确保在项目级别有一个命名空间,然后在 VB 项目中有这个类。我知道这在 C# 项目中有所不同。

[ComClass(MyClass.ClassId, MyClass.InterfaceId, MyClass.EventsId)] 
public class MyClass {

// These GUIDs provide the COM identity for this class
// and its COM interfaces. If you change them, existing
// clients will no longer be able to access the class.
public const string ClassId = "f58411e1-1689-4bf3-a0e1-b49f479e28ba";
public const string InterfaceId = "f4a575c6-62d2-44eb-af0f-f5b2bb65ad51";
public const string EventsId = "ad56e4f9-3512-4233-aae4-7d1c2457c08f";

// A creatable COM class must have a Public Sub New()
// with no parameters, otherwise, the class will not be
// registered in the COM registry and cannot be created
// via CreateObject.
public SalePayStatus() : base()
{
}
}

如果我担心 COM,我总是首先检查注册表以确保已创建适当的条目。我发现版本控制和 MSI 安装会导致问题,特别是卸载(不清理注册表)或重新安装和 MSI 与覆盖现有 COM 条目的 .net COM 对象会导致各种麻烦。

我通常发现您必须小心 x64 与 x32 构建 .net DLL。例如,您可能必须明确引用 VBS 引擎的 C:\Windows\SysWow64\或 C:\Windows\System32\版本。

最后,如果您在带有 x32 COM .net 组件的 x64 服务器上的 ASP 网站中使用 VBS,那么您需要确保 IIS 7 应用程序池高级选项是 32 位应用程序正确设置为 True/False。

关于Windows 7 64Bit 上的 .NET COM Interop 让我头疼,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2749638/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com