just for those who have to deal with legacy application that supports COM,
OCX, and WINAPI(_stadcal l) - c-style?,
I worked out the COM interface for function out array parameters.
For example
' Caller proto:
' Int32 lSz, lsz2
' String lstrOut[]
' Int32 lPos[]
' lSz = objClass.Parse( sIn, ref lsz2, ref lstrOut, ref lPos)
' the result lsz2 and lSz are same of course due to adj made here
Public Function Parse(ByVal sIn As String, <Out()> ByRef iCnt As Integer, _
<Out()> <MarshalAs(Unma nagedType.LPArr ay, ArraySubType:=U nmanagedType.LP Str,
SizeParamIndex: =1)> ByRef sOut As String(), _
<Out()> <MarshalAs(Unma nagedType.LPArr ay, ArraySubType:=U nmanagedType.LP Str,
SizeParamIndex: =1)> ByRef lPos As Integer()) As Integer
sOut = Split(sIn, vbTab)
Dim sdebugMsg As String = "0, >>", s As String
Dim i As Integer = 0
iCnt = 0
iCnt = sOut.GetUpperBo und(0)
Dim pos(iCnt) As Integer
If iCnt > 0 Then
pos(0) = 1
i = 1
For Each s In sOut
sdebugMsg &= s
If i < iCnt Then
pos(i) = s.Length + 1
sdebugMsg &= vbCrLf & pos(i) & vbTab
End If
Next
lPos = pos
iCnt += 1
Else
End If
' MsgBox("sOut.Ge tUpperBound()=" & sOut.GetUpperBo und(0) & vbCrLf & "values
are" & vbCrLf & sdebugMsg, MsgBoxStyle.OKO nly, "IeStringClass. Parse")
'MsgBox(sOut)
Return iCnt
End Function
Note that reversing index and iCnt position will not work! the index must
point to a parameter precding an array. When both arrays are of the same
size, the index of both arrays may point to the one used by first one
Further more for legacy application LPStr not LPWstr are likely the
choices - unless you know the legacy application supports unicode.
Please also note the sample code provided is just for demo not production
quality, nor of high performance. but it just works.
If anyone has experience to show a better way in terms of reliability, high
performance, please post, so we all can learn.