Pregunta

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.

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.

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

 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

¿Fue útil?

Solución 2

VB variants return as objects then are casted to the desired type. One word of warning when using VB 6 types from com, I was caught out by the long, vb6 long is a. net int! So although the com object had long in signature it was actually 32 bit signed integer value

Otros consejos

Feel free to experiment: do RegAsm.exe /tlb to generate a .TLB file, then use OleView.exe to view it. 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)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top