互操作:从C#到VB6 [英] Interop: C# to VB6

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

问题描述

我正在尝试将"missing"传递给VB6 COM DLL中的可选字符串参数,但它给了我无法从" object转换为" string".

以简化形式,我使用以下命令从C#调用:

对象o = someFunction(System.Type.Missing)

在VB6中,此函数声明为:

公共函数someFunction(可选ByVal arg As String ="Default")
.
.
.
最终功能

我可以传入字符串"Default"以获取所需的行为,但是我希望传递"missing",以便始终使用VB6 DLL中定义的默认参数值.

我是否可以将"missing"转换为字符串来欺骗编译器,或者还有其他更细微的方法?

I''m trying to pass "missing" to an optional string argument in a VB6 COM DLL but it is giving me "cannot convert from ''object'' to ''string''".

In simplified form, I''m calling from C# using:

object o = someFunction(System.Type.Missing)

In VB6, this function is declared as:

Public Function someFunction(Optional ByVal arg As String = "Default")
.
.
.
End Function

I can pass in the string "Default" to get the behaviour I want but I would prefer to pass missing so that I always use the default parameter value defined in the VB6 DLL.

Can I just cast "missing" to a string to fool the compiler or is there some more subtle way of doing this?

推荐答案

我对此表示怀疑.您最好根本不要使用VB6,因为十年后它已经过时了.我猜您可以尝试使用null,但是,如果它不能处理您不带参数的方法,那我将无法想象C#具有针对VB6运行的任何设计.
I doubt it. You''d be better not using VB6 at all, what with it being obsolete for a decade. You could try null, I guess, but if it can''t handle you calling the method with no parameters, I can''t imagine C# having any design given to running against VB6.


我从未在.Net中使用过VB dll.但是我想.Net中的字符串类型不只是像VB6中那样的字符串类型.这是一个对象类型,它也拥有其他属性.可能就是这样,为什么它会显示这样的错误.
I never used a VB dll in .Net. But I guess a string type in .Net is not just a string type like in VB6. It is a object type, it holds other properties also. May thats the reasom why its showing such a error.


这篇关于互操作:从C#到VB6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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