简体   繁体   English

具有Office 2010 64位的C#COM DLL

[英]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.

相关问题 我已经使用Visual Studio Express C#为2010 Office(64位)编写了Excel代码,如何在2010 Office(32位)上运行它? - I have written excel code for 2010 Office (64 bit) with visual studio express c#, how to run it on 2010 office (32 bit)? 如何注册也在Windows 64bit中使用的DLL C#COM Interop BouncyCastle.dll? - How to register a DLL C# COM Interop BouncyCastle.dll also used in Windows 64bit? 64位COM dll和C#/。Net应用程序之间的免注册互操作 - Registration-free Interop between a 64-bit COM dll and a C#/.Net application c#中64位应用程序中的32位dll - 32bit dll in 64bit application in c# 64 位 C# 与 32 位 VB6 COM ZA8CFDE6331BD59EB2AC96F8911C4B6 - 64 bit C# with a 32 bit VB6 COM object 无法创建C#COM DLL。 是代码吗? 项目属性? 安装程序属性? 32-64位? 什么? - Can't create C# COM DLL. Is it the code? Project properties? Installer properties? 32-64 bit? What? 在Visual Studio 2010中生成64位C# - Building 64-bit C# in Visual Studio 2010 生成英特尔兼容的x64位dll(C#) - generate Intel compatible x64 bit dll (C#) C# 在 64 位系统上调用 user32.dll - C# PInvoking user32.dll on a 64 bit system 在64位中从delphi dll返回字符串到C#调用者 - Returning a string from delphi dll to C# caller in 64 bit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM