如何在C#中VBA.Collection()对象 [英] How to create VBA.Collection() object in c#

查看:332
本文介绍了如何在C#中VBA.Collection()对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个从C#code
互操作VBA.Collection对象 我必须提及Interop.VBA在我的项目

I need create Interop VBA.Collection object from C# code
I have reference to Interop.VBA in my project

当我打电话说:

var col = new VBA.Collection()

在运行时我有一个错误,指出DLL未注册...
我发现: http://support.microsoft.com/kb/323737/en-us

In runtime I've got an error saying that dll is not registered...
I found that: http://support.microsoft.com/kb/323737/en-us

这可能工作,但我没有VB6编译器对我的盒子。
我不知道你知道其他的解决办法(或也许有人可以编译此ActiveX对我?)

It might work but I don't have VB6 compiler on my box.
I wonder you know other workaround (or maybe someone can compile this ActiveX to me?)

推荐答案

我没有尝试这样做,但它可能工作。

I haven't tried this, but it might work.

创建一个导入库VB6的VBA6.dll。创建自己的实现其_Collection接口。使用替代VBA.Collection类的此实现。

Create an import library for VB6's VBA6.dll. Create your own implementation of its _Collection interface. Use this implementation in place of the VBA.Collection class.

class MyCollection : VBA._Collection
{
    private Dictionary<object, object> _items = new Dictionary<object, object>();

    public void Add(ref object Item, [System.Runtime.InteropServices.OptionalAttribute]ref object Key, [System.Runtime.InteropServices.OptionalAttribute]ref object Before, [System.Runtime.InteropServices.OptionalAttribute]ref object After)
    {
        // Ignoring the Before and After params for simplicity
        _items.Add(Key, Item);
    }

    public int Count()
    {
        return _items.Count;
    }

    public System.Collections.IEnumerator GetEnumerator()
    {
        return _items.Values.GetEnumerator();
    }

    public dynamic Item(ref object Index)
    {
        return _items[Index];
    }

    public void Remove(ref object Index)
    {
        _items.Remove(Index);
    }
}

这篇关于如何在C#中VBA.Collection()对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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