开发者

Exposing .NET enums to COM clients{VBScript}

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 = C开发者_如何学JAVAurrencyConvertorBL.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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜