NoProblemBabe NoProblemBabe - 15 days ago 10
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:

[ComVisible(true)]
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)
byte
or chould I use
*char
?

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.
http://msdn.microsoft.com/en-us/library/z6cfh6e6.aspx
and
http://msdn.microsoft.com/en-us/library/75dwhxf7.aspx

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

[ComVisible(true),
ClassInterface(ClassInterfaceType.None),
ProgId("SomeNamespace.SomeClass"),
Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")]


on top of the class

Thank you very much you all.

Great help

Answer

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.

Comments