Re: COM Interop problem with variants holding object references

From: Joe (x_at_xx.com)
Date: 08/05/04


Date: Thu, 5 Aug 2004 13:02:02 -0400

Hmmm, your example inspired me and so I did some playing around and
discovered that my code works fine in C# but fails in VB.NET. So, in short,
calling from VB6 into a .NET component and passing Variant parameters ByRef
works if the .NET component is written in C# and fails if the .NET component
is written in VB. For the record, my VB code fails no matter what type of
data is in the variant.

As far as your own original problem, I'm sorry that I can't help you out,
but I can certainly verify that you can get weird results through COM if
you're passing things ByRef unexpectedly.

Thanks again,
-- Joe

"Ken Kolda" <ken.kolda@elliemae-nospamplease.com> wrote in message
news:On5Fm5neEHA.3148@TK2MSFTNGP10.phx.gbl...
> Honestly, I don't know if it's possible since I've never tried. My issue
was
> more one where I want ByVal but it seems to be trying to do ByRef for some
> reason.
>
> That said, I did a quick test in C# and created a function as follows:
>
> public void TestByRef(ref object someObj, int x)
> {
> if (x == 0)
> someObj = new object();
> else
> someObj = 5;
> }
>
> I tried this from VB6.0 and it seemed to work as expected for both the
> object-valued variant and the scalar-valued variant. What kind of data is
> contained in your variant?
>
> Ken
>



Relevant Pages

  • Prorblem assigning _variant_t to _bstr when _variant_t is an integer
    ... I have a problem with a simple sql program I alm writing. ... It fails in this function: ... Somehow it seems like it is unable to assign the variant to the bstr ...
    (microsoft.public.data.ado)
  • Re: WebBrowser2 PutProperty issue with Vista and IE7
    ... set the code below fails. ... // Save this to a variant that will be referenced in IE Session ... You need to AddRef the pointer here. ... // remove our reference ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: Addpolyline function
    ... The code also fails. ... The main point is VB should be able to convert variable types on the fly ... array as variant, the coordinates are dimmed as integer, which might be why ... the AddPolyline code fails. ...
    (microsoft.public.excel.programming)
  • Re: [PATCH 01/32] Add an ERR_CAST() macro to complement ERR_PTR and co. [try #2]
    ... One like one variant, another like another variant. ... Both fails to say why. ... More majordomo info at http://vger.kernel.org/majordomo-info.html ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)

Quantcast