使用可变数量的ref参数调用COM函数 [英] Call COM function with variable number of ref params

查看:60
本文介绍了使用可变数量的ref参数调用COM函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下签名的函数的DLL:

int TheFunction(字符串arg1,params object []参数)

我的调查使我意识到该DLL是tldimp.exe(类型库导入器)的产品,并且是我要调用的实际基础库(我无法更改)的.NET包装器.问题在于,TheFunction应该更改参数"中的一个或多个值.换句话说,每个参数都应由ref传递.我非常相信自己没有更改包装DLL的方法就无法进行这项工作.

我使用ildasm.exe来查看此包装DLL的MSIL代码,并得到以下信息:

I have a DLL with a function that has the following signature:

int TheFunction(string arg1, params object[] Parameters)

My investigation has led me to realize that the DLL is a product of tldimp.exe (the Type Library Importer) and is a .NET wrapper to the actual base library I'm calling (which I can't change). The problem is that TheFunction is supposed to change one or more values in Parameters. In other words each argument should be passed by ref. I've pretty much convinced myself there is no way to make this work without changing the wrapper DLL. 

I used ildasm.exe to look at the MSIL code for this wrapper DLL and got the following:

<身体> 的结尾
.method.publichidebysignewslot摘要虚拟
实例int32 TheFunction([in]字符串marshal(bstr)子例程,
的[in] [out] object [] marshal(safearrayvariant)参数)运行时管理的preservesig内部调用
{
.custom实例void [mscorlib] System.Runtime.InteropServices.DispIdAttribute ::.ctor(int32)=((01 00 04 04 00 00 00 00 00 00)
.param [2]
.custom实例void [mscorlib] System.ParamArrayAttribute ::.ctor()=((01 00 00 00))
}//方法IQueue :: TheFunction
.method public hidebysig newslot abstract virtual   
        instance int32  TheFunction([in] string  marshal( bstr) Subroutine,  
                                       [in][out] object[]  marshal( safearray variant) Parameters) runtime managed preservesig internalcall  
{  
  .custom instance void [mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = ( 01 00 04 00 00 00 00 00 )   
  .param [2]  
  .custom instance void [mscorlib]System.ParamArrayAttribute::.ctor() = ( 01 00 00 00 )   
} // end of method IQueue::TheFunction  
 

推荐答案

参数中有更多值.换句话说,每个参数都应由ref.

传递.为什么这些参数被ref传递?
我认为,如果非托管方法想要指向该参数的指针,则导入程序将使该参数被引用传递.

传入arg1和参数会引发什么异常?


 The problem is that TheFunction is supposed to change one or more values in Parameters.In other words each argument should be passed by ref.

Could you please be more specific about the statement? Why are these argument passed by ref?
I think the importer will make the parameter be passed by reference if the unmanaged method want a pointer to the parameter.

What exception raised when arg1 and  Parameters was passed in?



这篇关于使用可变数量的ref参数调用COM函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆