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
?
bobahop@gmail.com - 23 Mar 2007 17:46 GMT
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
Rafał Giezgała - 23 Mar 2007 19:15 GMT
Each class and interface have different GUID and COMVisible == true.
Changing interface on _IExtraStuff didn't help.
bobahop@gmail.com - 23 Mar 2007 20:20 GMT
You have some things I don't have. For instance, I don't explicitly
set
[assembly: ClassInterfaceAttribute(ClassInterfaceType.None)]
or
ComSourceInterfaces(typeof(_IExtraStuff))
I do, however, set the ProgID
[ProgId("MyNamespaceName.MyClassName")]
HTH. Bob.
Rafał Giezgała - 26 Mar 2007 10:47 GMT
Yes I saw this part on one of example somewhere on the net. You can skip
this part. It doesn't change anything...unfortunately.