Matriz de objeto personalizado de .NET a VB6

I've written a small library in C#.

In this library there are two classes that are ComVisible.

The first one has a method that provide a array of custom objects (declared in the second class).

I tested the library with a small c# application and everything work. Then I do the same thing VB6. The problem occurs when I call the method I descibed before. I get a Type Mismatch error.

Here's the BV6 code:

   Private Sub Command1_Click()
       Dim Flussi As FMDriver.FMDriver  
       Set Flussi = New FMDriver.FMDriver
       Dim temp() As FMDriver.FM
       temp = Flussi.GetElabData(station, codpar, data, tabella, nfunz, tiponfunz)

This is the custom class FM

public partial class FM
    public FM() { }

    public double Value { get; set; }

    public double IDisp { get; set; } 

Any idea? If from the response I extract only one element it works.


Another strange thing...

Dim pippo As FM
Set pippo = CreateObject("")
pippo.Value = 100
pippo.IDisp = 43    
pippo = Flussi.GetElabData( [..cut..] )(4)

In Pippo.Value there's the correct value that GetElabData return on the 4th position of the array but in Pippo.IDisp the value doesn't change, it remains 43instead of getting the new value.

preguntado el 30 de agosto de 12 a las 17:08

this is a complete sample that shows how to solve your problem i hope it could help you -

Si Dim temp() As Object or Dim temp As Variant, would that get around the Type Mismatch? -

Hassan Wasef, maybe you post on the wrong question? :) Rskar, if I use Object or Variant I get the same error. :( -

Whats the definition and code behind FMDriver.GetElabData()? -

[ComVisible(true)] public FM[] GetFMData( [...cut...] ) { List<FM> _Result = new List<FM>(); // [... bla bla bla ...] return _Result.ToArray<FM>() } -

1 Respuestas

In the end I created all my beautifull methods that returns custom obj (for .NET apps) and a couple of methods, dedicated to VB6, with the [ComVisible(true)] tag, that returns more siple arrays of values (part of the result of the other methods). So I think that returning custom Obj to VB6 it's not very reliable and sometimes it doesn't work at all.

respondido 29 nov., 12:10

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.