CreateObject("Scripting.Dictionary") の代わりに CreateObject("DotNETbridge.ScriptingDictionary") でCOMオブジェクトを作ると、 大体 Scripting.Dictionary のようにアクセスできる。
using System;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices;
namespace DotNETbridge
{
/// <summary>
/// Scripting.Dictonary の振りをする .NET COM コンポーネント
/// </summary>
[GuidAttribute("2B115907-4561-4d0f-BF54-6A69F7AB2D35")]
public interface IDictionary
{
int Count { get; }
object this[object index] { get; set; } // インデックサ (VBScript では Itemプロパティ によるアクセス)
// Key プロパティは実装方法がわからない
void Add(object key, object item);
bool Exists(object key);
object[] Items();
object[] Keys();
void Remove(object key);
void RemoveAll();
// テスト用メソッド
string getClassName(object o);
object getValueOfDictionary(object o, object key);
}
[ClassInterfaceAttribute(ClassInterfaceType.None)]
public class ScriptingDictionary : IDictionary
{
private Scripting.Dictionary dict = null;
public ScriptingDictionary()
{
dict = new Scripting.Dictionary();
}
#region IDictionary メンバ
public int Count
{
get { return dict.Count; }
}
public object this[object index]
{
get { return dict.get_Item(ref index); }
set { dict.set_Item(ref index, ref value); }
}
public void Add(object key, object item)
{
dict.Add(ref key, ref item);
}
public bool Exists(object key)
{
return dict.Exists(ref key);
}
public object[] Items()
{
return (object[]) dict.Items(); // dict.Items() 自体の返り値は object 型(配列でない)
}
public object[] Keys()
{
return (object[]) dict.Keys(); // dict.Keys() 自体の返り値は object 型(配列でない)
}
public void Remove(object key)
{
dict.Remove(ref key);
}
public void RemoveAll()
{
dict.RemoveAll();
}
public string getClassName(object o)
{
return o.GetType().Name;
}
public object getValueOfDictionary(object o, object key)
{
if (o.GetType().Name == "DictionaryClass")
{
// HashTable に代入してから取り出すテスト
Scripting.Dictionary d = (Scripting.Dictionary)o;
object[] arrKeys = (object[]) d.Keys();
object[] arrValues = (object[]) d.Items();
Hashtable h = new Hashtable(d.Count);
for(int i = 0; i < d.Count; i++)
{
h[arrKeys[i]] = arrValues[i];
}
return h[key];
}
return null;
}
#endregion
}
}
DLLファイルをマシンにインストールする際、GACに登録しなくても
regasm 絶対パス.dll /codebose コマンドで利用できるようになった。
いずれにせよアセンブリに署名しておく必要がある。
また、 も、この.NETアセンブリDLLと同じディレクトリに置いておけば利用できた。
引数を取りながら左辺値となる Key プロパティを実装する方法は分からなかった。
641P-II
回線代7000円upの他に、接続するために 同時通話数*800円+電話番号数*100円 かかる模様。 同時通話数8chぐらい設定しないともったいない感じ。