[英]C# COM DLL with Office 2010 64 bit
I may be reposting but I cannot find solution of this. 我可能正在重新发布,但找不到解决方案。
I create a C# Comvisible Class. 我创建一个C#可视类。 This is the following class: 这是下面的类:
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";
}
}
}
Then I checked Register for Interop option and even made the complete assembly visible and compile the project and solution. 然后,我检查了“注册Interop”选项,甚至使整个程序集可见并编译了项目和解决方案。
Then I went to excel and wrote this code: 然后我去了excel并编写了以下代码:
Dim a as Object
set a = CreateObject("COMTrial.Class1")
It says, 它说,
ActiveX cannot create an object. ActiveX无法创建对象。
The only reason I think of is that I am running Office 2010 64 bit with Windows 7 64 bit. 我想到的唯一原因是我在运行Office 2010 64位和Windows 7 64位。
Then I checked Register for Interop option 然后我检查了注册互操作选项
That will only register your assembly for 32-bit processes. 那只会为32位进程注册您的程序集。 Since this is the 64-bit version of Office, you will need to run Regasm.exe by hand. 由于这是Office的64位版本,因此您将需要手动运行Regasm.exe。 Do so from the Visual Studio Command Prompt, started with "Run as administrator". 从“以管理员身份运行”开始的Visual Studio命令提示符中执行此操作。 Be sure to use the 64-bit version of Regasm.exe, for .NET 4 it is located by default in C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319. 请确保使用Regasm.exe的64位版本,对于.NET 4,默认情况下位于C:\\ Windows \\ Microsoft.NET \\ Framework64 \\ v4.0.30319。 Note the 64. Use the /tlb and /codebase options to match the IDE's behavior. 注意64。使用/ tlb和/ codebase选项来匹配IDE的行为。
Another improvement is to use the [ProgId] attribute explicitly so you don't have to guess at the name and won't have a problem if the project name is not "COMTrial". 另一个改进是显式使用[ProgId]属性,因此您不必猜测名称,并且如果项目名称不是“ COMTrial”,也不会出现问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.