Passing array byref to com object

N

Neil Munro

I'm having some "type" difficulty in passing a .NET array (byref) to a COM
based API (Autodesk Inventor). In VB6 the code to return an array of
tolerance values is:

Dim ToleranceCount As Long
Dim ExistingTolerances() As Double
'oSurfBody is declared and assigned in the following
Call oSurfBody.GetExistingFacetTolerances(ToleranceCount,
ExistingTolerances)

In VB.NET, the object browser shows the syntax to be:

Public Overridable Sub GetExistingFacetTolerances(ByRef ToleranceCount As
Integer, ByRef ExistingTolerances As System.Array)

Passing the array gives me a Type Mismatch error no matter how I approach
it.

Dim ToleranceCount As Integer
Dim ExistingTolerances() As Single
or
Dim ExistingTolerances() As Double
or
Dim ExistingTolerances() As Object
or
Dim ExistingTolerances As Array = Array.CreateInstance(GetType(Single),
10000)
or Double, Object versions of the above

The following fails with Type Mismatch:

Call oSurfBody.GetExistingFacetTolerances(ToleranceCount ,
ExistingTolerances)

The requirement to assign a length when using CreateInstance seems rule out
that approach, the method wants an undimensioned array.

Can anyone point out what I'm missing about passing arrays byref to com
objects.

Thanks in advance.
Neil
 
C

Cor Ligthert

Neil,

The answer is mostly on your question that a VB6 long is a VBNet integer.

Cor

"Neil Munro"
I'm having some "type" difficulty in passing a .NET array (byref) to a COM
 
N

Neil Munro

Correct, and the other argument was declared as an integer in the .NET
version. I don't think that is the problem.

Neil
 

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