Passing a VB.NET Array as a VARIANT to a COM Server

G

Gregory Hassett

Hello, I am calling into a legacy COM server from VB.NET.
The method that I am calling expects an array. Here is the
example syntax provided by the author of this COM
automation object -- this syntax would (allegedly) work in
VB6. The object is called RhinoScript:

RhinoScript.AddLine Array(0, 0, 0), Array(10, 0, 0)

Now, this syntax causes VB.NET to choke at compile-time. I
have replaced it with the following (and have tried several
other ways of creating the array, as well):

Dim a As Array =
Array.CreateInstance(GetType(Int32), 0, 0, 0)
Dim b As Array =
Array.CreateInstance(GetType(Int32), 10, 0, 0)

RhinoScript.AddLine(a, b)

This compiles, but at runtime I get an error "parameter
type mismatch -- parameter must be an array."

I suspect that I am passing a CLR Collection Object (Array)
when the legacy COM Automation Server wants an old-style
SafeArray in a VARIANT. How do I circumvent this problem?
 
P

Peter Huang

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