我正在尝试在 VBA 中访问 COM 公开的方法。
Problem:我看到所有默认方法(例如GetHashCode
, GetType
and ToString
) 在 VBA 中但是not那些是 COM 接口的一部分并且专门编写为 COM 可见的(例如getStringValue()
below).
设置详情:
- 视觉工作室2008
- Windows 7 x64
- 办公室2007
- .NET 3.5
接口“IGetMyString.cs”
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace SimpleCOMAssembly
{
[ComVisible(true), GuidAttribute("4153A1AC-ECE9-4f66-B56C-1DDEB6514D5D")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
interface IGetMyString
{
[DispId(1)]
string getStringValue();
}
}
实施“GetMyString.cs”
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace SimpleCOMAssembly
{
[ComVisible(true), GuidAttribute("0A3D4D65-CF50-4020-BF13-77001F8AAABE")]
[ProgId("SimpleCOMAssembly.GetMyString")]
[ClassInterface(ClassInterfaceType.None)]
public class GetMyString : IGetMyString
{
public GetMyString() { }
[ComVisible(true), Description("Get my string")]
public string getStringValue()
{
return "hello";
}
}
}
在构建属性中,我检查了“使程序集 COM 可见”(见下面的快照)
还要求 Visual Studio 2005 制作“注册 COM 互操作”(见下面的快照)
最后,作为构建后事件,我运行 regasm.exe 来注册 .DLL 以及 .TLB 到注册表,如下所示:
%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\regasm /codebase "$(TargetPath)" /tlb:"$(TargetDir)$(TargetName).lib"
In Excel Object Explorer view, I enabled COM server (SimpleCOMAssembly written above), and now in the Object Explorer it does not list down the COM interface method (see below)
![enter image description here](https://i.stack.imgur.com/CRLob.png)
有人可以帮助我知道我缺少什么导致 COM 接口方法未在 VBA 中显示吗?
EDIT
Attaching ITypeLib View of the generated TLB
![enter image description here](https://i.stack.imgur.com/utKj5.png)