COM Interop - MarshalAs

M

Michael Moreno

Hello,

I have a .Net DLL that I use as a COM Server.

I would like to return a SafeArray of double to a VB 6 client.

I have declared this interface

Public Interface ITest
...
Function RetSafe() As <MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType:=VarEnum.VT_R8)> Double()
End Interface

And have implemented a test code:

Public Function RetSafe() As Double() Implements ITest.RetSafe
Dim v As Double()
Dim i As Int16

ReDim v(10)

For i = 0 To v.Length
v(i) = i
Next

RetSafe = v
End Function

In the client, when I do

Dim v as variant
....
v = Test.RetSafe

I get a big crash.

I could not find a way to return a SafeArray in a function. Any idea
how to do it please?

thanks
 
M

Michael Moreno

The answer is simple : just return an array and COM interop does the
job.
 

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