calling .NET COM object from VBScript

别等时光非礼了梦想. 提交于 2020-01-02 03:27:27

问题


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 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)

Everything works fine ... but, a return type change from void to bool

    [DispId(1610809354)]
    bool setProperties(IDictionary propertymap);

and

 success = dSystem.setProperties(objDictionary)

causes an error

Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument


The .tlb file seems to be ok

[id(0x6003000a)]
HRESULT setProperties(
[in] IDictionary* propertymap, 
[out, retval] VARIANT_BOOL* pRetVal);


What am i doing wrong?
Can anybody give me a hint?


回答1:


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.

Try

[DispId(1610809354)]      
bool setProperties(object propertymap);

and cast to an IDictionary inside the method body.



来源:https://stackoverflow.com/questions/4885038/calling-net-com-object-from-vbscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!