COM互操作方法签名 [英] COM Interop Method Signature

查看:73
本文介绍了COM互操作方法签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调用COM dll的C#程序,该程序具有一种称为"test"的方法.带有2个参数:第一个参数通过ByVal传递,第二个参数通过ByRef传递.

I have a C# program that call a COM dll that have a method called "test" with 2 parameter: first parameter is passed ByVal, the second one is passed ByRef.

这是COM dll的作用:

This is what COM dll do:

Public Sub test(ByVal a As String, ByRef b As String)
 a = "a"
 b = "b"
End Sub


这是C#程序的作用:


This is what C# program do:

test.Class1 x = new test.Class1();
string a = "1";
string b = "2";
x.test(a, ref b);

我注意到,如果我删除"ref"关键字,编译器不会告诉我我错过了"ref".关键字并传递参数ByVal.这个 如果我想念"ref"消息,可能会是一个大问题.关键字,因为直到我知道他想要"ref"关键字时,我才永远不会注意到它.关键词.您知道为什么编译器会出现这种行为吗?

I notice that if I remove "ref" keyword, the compiler doesn't advice me that I missed the "ref" keyword and pass the parameter ByVal. This can be a big problem if I miss the "ref" keyword because I can't never notice it until I know that he want "ref" keyword. You know why the compiler have this behavior?

推荐答案

您好 法比奥·帕加诺(Fabio Pagano)

Hi Fabio Pagano,

>>我注意到,如果我删除了"ref"关键字,编译器不会建议我错过了"ref".关键字并传递参数ByVal.

>>I notice that if I remove "ref" keyword, the compiler doesn't advice me that I missed the "ref" keyword and pass the parameter ByVal.

在这里,我添加一个VB类库,然后在C#控制台中使用它,如下图所示.用波浪线指出错误的点,鼠标会提示错误的点,生成时也可以报告错误. 它很好用. 如果您需要我尝试其他方法,请告诉我.


这篇关于COM互操作方法签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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