Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling .NET COM object from VBScript

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?

like image 959
ak75 Avatar asked Feb 03 '11 10:02

ak75


1 Answers

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.

like image 158
Joe Avatar answered Oct 29 '22 17:10

Joe