Vit*_*ata 9 c# com intellisense vba visual-studio
有没有办法在VBA中自己构建的COM类中获取IntelliSense?
例如,在下面的示例中,每当我按下点(或ctrl + space for shortcut)时,我想显示"Number":

我想,如果以某种方式解决了这个问题,我还会得到一些关于对象公共函数的信息:
那么,有什么建议?
建议1:
简单的例子看起来像这样。
c#类库命名
IntellisenseDemo代码
using System;
using System.Runtime.InteropServices;
namespace IntellisenseDemo
{
[ComVisible(true)]
[Guid("41B3F5BC-A52B-4AED-90A0-F48BC8A391F1")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IIntellisenseDemo
{
int Number { get; set; }
string TestString(string name);
}
[ComVisible(true)]
[Guid("20EBC3AF-22C6-47CE-B70C-7EBBA12D0A29")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("IntellisenseDemo.Demo")]
public class Demo : IIntellisenseDemo
{
public int Number { get; set; }
public string TestString(string name)
{
throw new NotImplementedException();
}
}
}
Run Code Online (Sandbox Code Playgroud)
注意:[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]表示一个接口作为调度接口暴露给 COM,它只启用后期绑定。
[ClassInterface(ClassInterfaceType.None)]意味着 CLR 不公开此类型的类接口。COM 客户端可以使用IIntellisenseDemo接口中的方法调用此类的成员。
再高潮
C:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm C:\Temp\IntellisenseDemo.dll /tlb: C:\Temp\IntellisenseDemo.tlb
Run Code Online (Sandbox Code Playgroud)
VBA
| 归档时间: |
|
| 查看次数: |
854 次 |
| 最近记录: |