简体   繁体   English

通过从c#COM可见类中的c#方法引用返回vb变体

[英]return vb variant by reference from c# method in c# COM Visible class

I have not had much experience with COM interfaces, I have had to create a COM Visible class that contains a method DoStuff that will return by reference two VB Variant variables, they are actually a vb long and vb string but declared as variants. 我对COM接口没有太多的经验,我不得不创建一个包含方法DoStuff的COM Visible类,该方法将通过引用返回两个VB Variant变量,它们实际上是vb long和vb字符串,但声明为变体。

Currently I have something like: 目前我有类似的东西:

public void DoStuff(string someString, int someInt, ref long refLong, ref string refString)
{
    refLong = DesiredReturnLong;
    refString = DesiredReturnString;
}

I am having issues as the script that calls the COM interface expects VB Variants to be returned. 我遇到问题,因为调用COM接口的脚本希望返回VB变体。

How could I do this? 我该怎么办? I don't think I can just return objects like this (was my initial thought as VB type Variants were changed to objects in VB.net 我认为我不能像这样返回对象(最初的想法是将VB类型的Variants更改为VB.net中的对象

 public void DoStuff(string someString, int someInt, ref object refLong, ref object refString)
{
    ...
}

What should the method signature look like and what would I have to do to return the correct values? 方法签名应该是什么样?返回正确的值我该怎么做?

Thanks for any help 谢谢你的帮助

Feel free to experiment: do RegAsm.exe /tlb to generate a .TLB file, then use OleView.exe to view it. 随时尝试:执行RegAsm.exe /tlb生成.TLB文件,然后使用OleView.exe进行查看。 For a method signature like yours: 对于像您这样的方法签名:

public void DoStuff(string someString, int someInt, 
    ref object refLong, ref object refString) 

you should see the corresponding interface method like this: 您应该看到相应的接口方法,如下所示:

HRESULT DoStuff([in] BSTR someString, [in] long someInt, 
    [in, out] VARIANT* refLong [in, out] VARIANT* refString)

VB variants return as objects then are casted to the desired type. VB变体返回时将对象转换为所需的类型。 One word of warning when using VB 6 types from com, I was caught out by the long, vb6 long is a. 当从com使用VB 6类型时,一句话警告,我被long吸引住了,vb6 long是a。 net int! 净int! So although the com object had long in signature it was actually 32 bit signed integer value 因此,尽管com对象的签名很长,但实际上是32位带符号整数值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM