使用 VB.NET,有没有办法在调用 dll 中的函数时传递引用参数。
假设我想将 arg2 作为参考参数传递,我该怎么做?
method.Invoke(obj, New [Object]() {arg1, arg2, arg3})
换句话说,我想将 arg2 指向被调用函数中的其他内容。
如果目标函数定义为ByRef
它会自动工作,否则你不能。
像这样称呼它:
method.invoke(obj, arg1, arg2, arg3)
在您的情况下,您实际上发送了一个参数(一个对象数组)
Yes, the parameters in your object array will hold the values that were set inside the method call. One thing to be aware of is that if arg1, arg2 and arg3 are value types (like Int32) then the actual arg1 variable will not have been updated because its value was copied into the array not its reference.
To get around this, create the object array before the function call, then pull the values out of the array afterwards. Like this
Dim paramArray = New [Object]() {arg1, arg2, arg3}
method.Invoke(obj, paramArray)
arg1 = paramArray[0]
arg2 = paramArray[1]
arg3 = paramArray[2]