I have a VB6 assembly which I need to use in my .NET application and generated the Interop DLL for usage with .NET via tlbimp.exe.
The VB6 assembly has a function that has a byref array parameter. I don't want to change anything in the VB6 assembly, so I hope there is a solution to get the following working.
It is filling the array and I want to use it in my .NET code (c# or vb.net).
Example of the VB6 function (file NativeClass.cls):
Public Function GetData(ByRef data() As String) As Integer
Dim tResults() As String
Dim sRecordCount As String
Dim lCount As Long
' load data
sRecordCount = dataDummyObject.RecordCount
ReDim tResults(sRecordCount, 2)
' fill the array in a loop
For lCount = 0 To sRecordCount - 1
tResults(lCount, 0) = dataDummyObject.Fields("property1")
tResults(lCount, 1) = dataDummyObject.Fields("property2")
If (sRecordCount - 1 - lCount) > 0 Then
Call dataDummyObject.MoveNext
End If
End For
data = tResults
GetData = sRecordCount
End Function
Now I want to use it from VB.NET:
Private _nativeAssembly As New NativeClass()
Public Function GetDataFromNativeAssembly() As String()
Dim loadedData As String() = Nothing
_nativeAssembly.GetData(loadedData)
Return loadedData
End Function
C# version:
private NativeClass _nativeAssembly = null;
public string[] GetDataFromNativeAssembly()
{
string[] loadedData = null;
_nativeAssembly.GetData(loadedData);
return loadedData;
}
But when executing the code I get following Exception:
System.Runtime.InteropServices.SafeArrayRankMismatchException: SafeArray of rank 2 has been passed to a method expecting an array of rank 1.
I really need help to solve this problem! Thanks for any piece of advice!