I'm building a COM object in C# (.Net 4.0) to be used in an classic asp site. Now I'd like to know what's the proper way to marshal VB-Script arrays (single and multidimensional) back and forth between the component and the asp site? A code sample would be highly appreciated.
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- How to get the maximum of more than 2 numbers in V
- 'System.Threading.ThreadAbortException' in
- Faster loop: foreach vs some (performance of jsper
VBScript only likes to handle SAFEARRAY's that contain VARIANTS. And it likes to have these passed arround in VARIANTS on the COM methods or properties. So you need to construct a VARIANT property that contains a SAFEARRAY of VARIANT type. The following C# code does this. First using just a plain array of objects and then also showing we can cast an array of any other managed type into an array of objects such that the marshalling code will convert this into a SAFEARRAY of VARIANTs for us.
This can be tested using the following vbscript:
You can see the type reported here as Variant() - ie: an array of variants.
Not so much an answer but some additional information:
This is how to consume patthoyts' answer in Classic ASP using VBScript:
I cannot access the individual array elements (eg. o.Names(2)) which indicates that it isn't an array but acting more like a collection.
JScript version: