NoProblemBabe NoProblemBabe - 1 year ago 96
C# Question

Accepting a Byte array, vb6 to C# interop

I am doing an application that comunicates vb6 with a cryptographic wrapper. The .net and interop part, up to now, is alright, fully working.

As my client is testing It, I just have a quick question:

public SomeObjectComVisible GetThat(byte[] array){ ... }

I used, until now, either types that I exposed to com or int and string, and no problems until now.

Is it ok to use (.net)
or chould I use

When I mark the assembly to be visible and register to com interop, it creates a wrapper for it, or should I use some unmanaged type?

Ah, it is a vb6, not vbscript.

thanks a million

for those who seek the answer:

public SomeObjectComVisible GetThat([MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_UI1)]byte[] array)

the problem is with arrays.

Any non bittable type can be a chore. You can specify your own types so they are used, you just have to make use of


on top of the class

Thank you very much you all.

Great help

Answer Source

Marshaling of arrays is something I struggle with often when dealing with COM clients of my .Net code. This article I find very useful in helping me understand the process.

Blittable and Non-Blittable Types

Specifically you can look at this article which talks about arrays

Note: part of my original answer which we found to be incorrect

So from looking at that it looks like "byte" isn't blitable yet "Byte" is. If you switch to Byte[] it will likely work the way you expect it to. Note: char isn't blitable but Char is.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download