just for those who have to deal with legacy application that supports COM,
OCX, and WINAPI(_stadcall) - c-style?,
I guess for some people it is an extrem easy task. for some, esp. to newbie
who don't have clue of terminoloty to search, it may take a lot of
searching and trial and error. Even though, as I speak, tehre are more and
more documentation available for those who know the right search
terminology.
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
' furthermore, they are designed for clients that normally start
' arrays with index of 1 rather zero.
Public Function Parse(ByVal sIn As String, <Out()> ByRef iCnt As Integer, _
<Out()> <MarshalAs(UnmanagedType.LPArray,
ArraySubType:=UnmanagedType.LPStr,
SizeParamIndex:=1)> ByRef sOut As String(), _
<Out()> <MarshalAs(UnmanagedType.LPArray,
ArraySubType:=UnmanagedType.LPStr,
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.GetUpperBound(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.GetUpperBound()=" & sOut.GetUpperBound(0) & vbCrLf & "values
are" & vbCrLf & sdebugMsg, MsgBoxStyle.OKOnly, "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 or comment. I, for one, would very much
appreciate.
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com