Passing strongly typed arguments in .NET COM interop

前端 未结 2 1746
半阙折子戏
半阙折子戏 2021-01-05 14:03

I have two .NET classes exposed via COM interop - let\'s say Foo and Bar, and I need to pass an argument of type Foo to a method defined in Bar. Something like this:

2条回答
  •  星月不相逢
    2021-01-05 14:46

    After struggling with this same issue for a while, I found that is was having issues with passing argments by reference instead of by value. See here:

    http://msdn.microsoft.com/en-us/library/ee478101.aspx

    So I just added round brackets to the passed argument in VB Script, and it seemed to have solved the problem. So in your example, just doing this:

    Set foo = CreateObject("TestCSProject.Foo")
    Set bar = CreateObject("TestCSProject.Bar")
    Call bar.Method((foo))
    

    Should work as expected, without having to set the ClassInterface attribute, and without using Interfaces.

提交回复
热议问题