VB6 Interop: Předání pole z C# do Visual Basicu

Na předání pole do VB6 nic není, jenom to nejde udělat automaticky, protože COM Mashaller vystaví stub jako pole typu System.Array.

Ukázka volané metody v VB6 my mohla vypadat takhle:

Public Sub Count(ByRef numbers() As Long)
Dim i As Integer
For i = 0 To UBound(numbers)
        ' do something
Next
End Sub

A příklad volání v C#:

 public void Count(List<int> numers)
        {
            System.Array arr = new int[numbers.Count];
            int i = 0;
            foreach (var item in numbers) {
                arr.SetValue(item, i++);
            }
            // Marhalling packs array as System.Array
            VB6Class.Count(ref arr);
        }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s