从VBScript调用.NET COM对象 [英] calling .NET COM object from VBScript
问题描述
我使用VS 2008和Windows 7.
获得一个作为COM对象公开的.NET C#类。
I use VS 2008 and Windows 7.
Got a .NET C# class which is exposed as COM object.
[Guid("E5014B85-FCB2-4F0D-95EC-F741395A7923")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface DSystem
{
[DispId(1610809354)]
void setProperties(IDictionary propertymap);
}
COM对象从VBScript
COM object is called from a VBScript
dim dSystem
set dSystem = CreateObject("MYCOMOBJECT")
Dim objDictionary
Set objDictionary = CreateObject("System.Collections.Hashtable")
objDictionary.Add "PROP1", "abc"
objDictionary.Add "PROP2", "zyx"
dSystem.setProperties(objDictionary)
一切正常...但是,
a返回类型从 void
至 bool
Everything works fine ... but,
a return type change from void
to bool
[DispId(1610809354)]
bool setProperties(IDictionary propertymap);
和
success = dSystem.setProperties(objDictionary)
导致错误
Microsoft VBScript运行时错误'800a0005'
无效的过程调用或参数
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument
.tlb文件似乎确定
The .tlb file seems to be ok
[id(0x6003000a)]
HRESULT setProperties(
[in] IDictionary* propertymap,
[out, retval] VARIANT_BOOL* pRetVal);
我做错了什么?
$ b $
What am i doing wrong?
Can anybody give me a hint?
推荐答案
不知道这一点,但我似乎模糊地记得,因为VBScript只使用变体,您需要将您的方法参数声明为对象。
Not sure about this, but I seem to vaguely remember that because VBScript uses only Variants, you need to declare your method parameters as object.
尝试
[DispId(1610809354)]
bool setProperties(object propertymap);
并转换到方法体内的IDictionary。
and cast to an IDictionary inside the method body.
这篇关于从VBScript调用.NET COM对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!