Groups | Blog | Home
all groups > dotnet interop > march 2007 >

dotnet interop : Problem with using created COM object with C#.NET 2005 under Excel2003 (Framework 2.0)


bobahop NO[at]SPAM gmail.com
3/23/2007 9:46:45 AM
In C# I would have to name the interface _IExtraStuff, I suspect the
same holds true for VB. Also, I explicitly set the COMVisible
attribute to true on the implemented interface methods. Also, if you
use the GUID generated in the project (as seen in Assembly
Information) that will screw things up. The interface and class need
separate GUIDs from the assembly. Just some suggestions. HTH. Bob
=?ISO-8859-2?B?UmFmYbMgR2llemdhs2E=?=
3/23/2007 4:42:42 PM
This is part of my assembly:

[assembly: ComVisible(true)]

[assembly: ClassInterfaceAttribute(ClassInterfaceType.None)]

// The following GUID is for the ID of the typelib if this project is
exposed to COM
[assembly: Guid("cd099def-f9fb-407f-b793-9db68f6b8a0b")]



This is my code:

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


namespace ExtraStuff
{
[Guid("4E3BBC1B-625F-47bf-BE80-DAB84F1934BE"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch),
ComVisible(true)]
public interface IExtraStuff
{
[DispId(1)]
double F2C(double val);
}

[Guid("F88DAD68-578A-4e23-BCFF-0FBBEC1C4B55"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(IExtraStuff)),
ComVisible(true)]
public class ExtraStuffClass : IExtraStuff
{
public ExtraStuffClass()
{
}

public double F2C(double val)
{
return ((5.0/9.0) * (val - 32.0));
}
}
}


and excel vb code:

Option Explicit

Public Function F2C(val As Double) As Double
Dim ccw As ExtraStuff.IExtraStuff
Set ccw = New ExtraStuffClass
F2C = ccw.F2C(val)
End Function



I put my dll to C:\Program Files\Microsoft Office\OFFICE11\ and I registered
that by:

regasm /tlb /codebase ExtraStuff.dll



And when I'm trying use it I get error:

'Run-time error '-2147024894 (80070002)'


In oleview.exe raport everything seems to be OK. Can anyone solve my problem
AddThis Social Bookmark Button