help needed passing array to COM caller by marshalling

J

jg

I have searched marshaling articles from MSDN and Google but I am stuck
with solving my problem to marshal arrays to COM caller from my managed COM
class

I built a .net COM class in VB and tested it from an application built with
C tool.. It worked well except for those functions in the VB com class with
arrays.
I had no trouble with scalar parameters passing back and forth between the
COM class and the legacy caller

I got a vague message of
"Error calling external object function etst at line ...."

here is the problematic function in my VB COM class
' array TO COM LPStr
Public Function etst(ByVal iCnt As Integer, _
<MarshalAs(UnmanagedType.LPArray, ArraySubType:=UnmanagedType.LPStr,
_
SizeParamIndex:=0)> ByRef strMatchReslts() As String) As Integer
' ???what is wrong with this??
Dim strMyC As String() = {"abcdef string 1", "abcdef string 2", _
"abcdef string 3", "abcdef string 4", "abcdef string 5"}
strMatchReslts = strMyC
Return strMyC.GetUpperBound(0)
End Function
in my .net test com class

However after compilation of this test Com class, I tried call from a com
client ( the syntax may look a bit odd because I am using it from an OO
application tool that was buildt with C from some vendor)
long lsz = 5, l
String strArr[]
for l = 1, 1, lsz
strArr[l] = fill(100)
next

/* ...... after steting up and intializing myCOMObj
.... use myCOMObj call some simple test function within COM class with non
array arguments
... and they worked
*/

// so myCOMObj has been setup correctly wihtotu question

long iActualSzReturned
iActualSzReturned = myCOMObj .

myComObj.eTst(lsz, Ref strArr) // no such thing as Out in this language.
Ref is the one to use
// ooops I got runtime error here, unfortunately, it does not tell me
// the exact message
// other then Error calling external object function etst at line 15
// which is the above statment
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top