将Enum数组从COM(VBA)传递到.NET(C#) [英] Passing array of Enum from COM (VBA) to .NET(C#)

查看:109
本文介绍了将Enum数组从COM(VBA)传递到.NET(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正试图将枚举数组从VBA传递到我的.NET库.但是,抛出了指定的数组不是预期类型"的异常.如何实现它?
在我的.NET库中,我声明了该参数要通过引用传递,这就是将其从COM传递到.NET的预期方式.对于Enums而言,它仍然无法正常工作.请告诉我我应该怎么做才能克服这个问题.这是我的示例调用.

在.NET中,我已经声明了一个Enum,然后尝试在函数中使用它.

[ComVisible(true)]
   公共枚举DataType
    {
      整数,
       Double,
      字符串,
       DateTime
    }

[ComVisible(true)]
   公共类UserInterfaceControls
    {
      公共无效测试(ref DataType [] colTypes)
       {
           MessageBox.Show(colTypes.ToString());
        }
    }

从VBA,我试图像

Dim arrType(1)as DataType
arrType(0)= DataType_String
arrType( 1)= DataType_Integer

obj ='UserInterfaceControls的实例

obj.Test arrType.

该调用引发了异常,即指定数组是

请给我一些解决此问题的方法.

谢谢,
Sushant M.

Hi,

I'm trying to pass enum array from VBA to my .NET library. However, it is throwing exception that "Specified array is not of expected type". How do I achieve it?
In my .NET library, I have declared the parameter to pass by reference, which is how it is expected to pass array from COM to .NET. Still for Enums, it is not working. Kindly tell me what should I do to overcome this. Here is my sample calls.

IN .NET, I have declared an Enum and then trying to use it in function.

[ComVisible(true)]
    public enum DataType
    {
        Integer,
        Double,
        String,
        DateTime
    }

[ComVisible(true)]
    public class UserInterfaceControls
    {
        public void Test(ref DataType[] colTypes)
        {
            MessageBox.Show(colTypes.ToString());
        }
    }

From VBA, I'm trying to call like

Dim arrType(1) As DataType
arrType(0) = DataType_String
arrType(1) = DataType_Integer

obj = 'instance of UserInterfaceControls

obj.Test arrType.

This call is throwing exception that "Specified array was not of the expected types".

Kindly give me some resolution for this problem.

Thanks,
Sushant M.

推荐答案



我正在尝试将枚举数组从VBA传递到我的.NET库.但是,抛出了指定的数组不是预期类型"的异常.如何实现它?
在我的.NET库中,我声明了该参数要通过引用传递,这就是将其从COM传递到.NET的预期方式.对于Enums而言,它仍然无法正常工作.请告诉我我应该怎么做才能克服这个问题.这是我的示例调用.

在.NET中,我已经声明了一个Enum,然后尝试在函数中使用它.

[ComVisible(true)]
   公共枚举DataType
    {
      整数,
       Double,
      字符串,
       DateTime
    }

[ComVisible(true)]
   公共类UserInterfaceControls
    {
      公共无效测试(ref DataType [] colTypes)
       {
           MessageBox.Show(colTypes.ToString());
        }
    }

从VBA,我试图像

Dim arrType(1)as DataType
arrType(0)= DataType_String
arrType( 1)= DataType_Integer

obj ='UserInterfaceControls的实例

obj.Test arrType.

该调用引发了异常,即指定数组是

请给我一些解决此问题的方法.

谢谢,
Sushant M.
Hi,

I'm trying to pass enum array from VBA to my .NET library. However, it is throwing exception that "Specified array is not of expected type". How do I achieve it?
In my .NET library, I have declared the parameter to pass by reference, which is how it is expected to pass array from COM to .NET. Still for Enums, it is not working. Kindly tell me what should I do to overcome this. Here is my sample calls.

IN .NET, I have declared an Enum and then trying to use it in function.

[ComVisible(true)]
    public enum DataType
    {
        Integer,
        Double,
        String,
        DateTime
    }

[ComVisible(true)]
    public class UserInterfaceControls
    {
        public void Test(ref DataType[] colTypes)
        {
            MessageBox.Show(colTypes.ToString());
        }
    }

From VBA, I'm trying to call like

Dim arrType(1) As DataType
arrType(0) = DataType_String
arrType(1) = DataType_Integer

obj = 'instance of UserInterfaceControls

obj.Test arrType.

This call is throwing exception that "Specified array was not of the expected types".

Kindly give me some resolution for this problem.

Thanks,
Sushant M.


这篇关于将Enum数组从COM(VBA)传递到.NET(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆