【发布时间】:2013-03-22 20:37:09
【问题描述】:
我可能会重新发布,但我找不到解决方案。
我创建了一个 C# Comvisible 类。这是以下类:
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";
}
}
}
然后我检查了 Register for Interop 选项,甚至使完整的程序集可见并编译项目和解决方案。
然后我去excel写了这段代码:
Dim a as Object
set a = CreateObject("COMTrial.Class1")
它说,
ActiveX 无法创建对象。
我想到的唯一原因是我正在运行 Office 2010 64 位和 Windows 7 64 位。
【问题讨论】:
-
此链接可能提供一些信息:officepreview.microsoft.com/en-us/support/…
-
你是
writing C# code or VB.NET Code or a mixture..?吗?如果它是一个混合体......你在标题部分的using Microsoft.VisualBasic行在哪里......? -
并非如此。我相信我缺乏的是在 64 位环境中注册 DLL 的理解。连网上的文章都没有详细的解释。
-
@ Kraze,我使用的是纯 C#。并尝试从 Excel 调用函数
-
如果您还添加了 64 位。基本上 Office 64bit 只能加载 64bit dll