将 .NET 枚举公开给 COM 客户端{VBScript}

发布于 2024-08-28 18:18:54 字数 1029 浏览 1 评论 0原文

我正在尝试创建 PoC 以从 COM 客户端公开/调用各种 .NET 对象。 .NET 库包含一些类和枚举。

我能够成功访问 VBScript 中的类,但无法访问枚举。 我知道枚举是值类型,因此“CreateObject”在这种情况下不起作用。

但我能够在 VBA 代码中访问相同的枚举。

问题:

  • 如何访问 VBScript 中的枚举?

  • 为什么两个 COM 客户端的行为不同?如果 VBA 对象浏览器可以看到枚举,为什么 VBScript 不允许我创建一个枚举?

.NET

  [ComVisible(true)]
[GuidAttribute("ebc25cf6-9120-4283-b972-0e5520d0000E")]        
public enum Currency
{        
    GBP = CurrencyConvertorBL.CurrencyConvertorRef.Currency.GBP,        
    USD = CurrencyConvertorBL.CurrencyConvertorRef.Currency.USD,        
    INR = CurrencyConvertorBL.CurrencyConvertorRef.Currency.INR,
    AUD = CurrencyConvertorBL.CurrencyConvertorRef.Currency.AUD
}

VBA

    Private Function ConvertCurrency(fromCurrency As Currency, 
toCurrency As Currency) As Double

VBScript ???

Set currencyConvertorCCY = CreateObject("CurrencyConvertorBL.Currency")

提前致谢。

Am trying create of PoC for exposing/invoking various .NET objects from COM clients.
The .NET library contains some classes and Enums.

Am able to successfully access the classes in VBScript but not able to access the Enums.
I know that Enums are value types and hence 'CreateObject' wont work in this case.

But am able to access the same Enum in VBA code.

Questions:

  • How can I access the enums in VBScript?

  • Why does the behaviour differ in the two COM clients? If VBA object browser can see the enum, why cant VBScript allow me to create one?

.NET

  [ComVisible(true)]
[GuidAttribute("ebc25cf6-9120-4283-b972-0e5520d0000E")]        
public enum Currency
{        
    GBP = CurrencyConvertorBL.CurrencyConvertorRef.Currency.GBP,        
    USD = CurrencyConvertorBL.CurrencyConvertorRef.Currency.USD,        
    INR = CurrencyConvertorBL.CurrencyConvertorRef.Currency.INR,
    AUD = CurrencyConvertorBL.CurrencyConvertorRef.Currency.AUD
}

VBA

    Private Function ConvertCurrency(fromCurrency As Currency, 
toCurrency As Currency) As Double

VBScript ???

Set currencyConvertorCCY = CreateObject("CurrencyConvertorBL.Currency")

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅的被狗咬 2024-09-04 18:18:54

Currency 是 VBA 中的一种内置数据类型,是一种数字类型。您必须在枚举前加上类型库名称作为前缀,以免编译器产生歧义,即 fromCurrency As MyProject.Currency

对于 VBScript,请尝试这篇文章:如何从脚本中访问类型库?

Currency is a built-in datatype in VBA, a numeric one. You have to prefix your enum with your typelib name not to be ambiguous for the compiler i.e. fromCurrency As MyProject.Currency.

For VBScript try this article: How Can I Access a Type Library From Within a Script?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文