Vikas
Vikas

Reputation: 805

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. 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.

Then I went to excel and wrote this code:

Dim a as Object

set a = CreateObject("COMTrial.Class1")

It says,

ActiveX cannot create an object.

The only reason I think of is that I am running Office 2010 64 bit with Windows 7 64 bit.

Upvotes: 0

Views: 1207

Answers (1)

Hans Passant
Hans Passant

Reputation: 942000

Then I checked Register for Interop option

That will only register your assembly for 32-bit processes. Since this is the 64-bit version of Office, you will need to run Regasm.exe by hand. Do so from the Visual Studio Command Prompt, started with "Run as administrator". 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. Note the 64. Use the /tlb and /codebase options to match the IDE's behavior.

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".

Upvotes: 1

Related Questions