繁体   English   中英

具有Office 2010 64位的C#COM DLL

[英]C# COM DLL with Office 2010 64 bit

我可能正在重新发布,但找不到解决方案。

我创建一个C#可视类。 这是下面的类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace COMTrial
{

    [Guid("2B71BC1B-16F5-4A0D-A015-CAE658A10B07")]
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface IMyExample
    {
        string GetData();
    }

    [ClassInterface(ClassInterfaceType.AutoDual), ComSourceInterfaces(typeof(IMyExample))]
    [Guid("2B71BC1B-16F5-4A0D-A015-CAE658A01B07")]
    [ComVisible(true)]
    public class Class1
    {

        public Class1()
        {
        }
        [ComVisible(true)]
        public string GetData()
        {
            return "Vikas";
        }
    }
}

然后,我检查了“注册Interop”选项,甚至使整个程序集可见并编译了项目和解决方案。

然后我去了excel并编写了以下代码:

Dim a as Object

set a = CreateObject("COMTrial.Class1")

它说,

ActiveX无法创建对象。

我想到的唯一原因是我在运行Office 2010 64位和Windows 7 64位。

然后我检查了注册互操作选项

那只会为32位进程注册您的程序集。 由于这是Office的64位版本,因此您将需要手动运行Regasm.exe。 从“以管理员身份运行”开始的Visual Studio命令提示符中执行此操作。 请确保使用Regasm.exe的64位版本,对于.NET 4,默认情况下位于C:\\ Windows \\ Microsoft.NET \\ Framework64 \\ v4.0.30319。 注意64。使用/ tlb和/ codebase选项来匹配IDE的行为。

另一个改进是显式使用[ProgId]属性,因此您不必猜测名称,并且如果项目名称不是“ COMTrial”,也不会出现问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM