Adopting Byte array, vb6 to C # interop

I am making an application that comments on vb6 using a cryptographic shell. The .net and interop part, so far, is in order, fully working.
Since my client is testing it, I have a quick question:

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

I have used so far the types that I have shown com or int and string, and no problem so far.

Is it possible to use (.net) byte or use *char ?
When I note that the assembly is visible and registered in com interop, does it create a wrapper for it or do I need to use some unmanaged type?

Ah, this is vb6, not vbscript.

thanks a million

for those looking for an answer:

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

the problem is arrays. http://msdn.microsoft.com/en-us/library/z6cfh6e6.aspx and also http://msdn.microsoft.com/en-us/library/75dwhxf7.aspx

Any non-flying type can be a daunting task. You can specify your own types to be used, you just need to use

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

on top of the class

Thank you all.

Great help

+4
source share
3 answers

Array marching is something that I often encounter when I encounter COM clients of my .Net code. I find this article very helpful in helping me understand this process.

Blittable and Non-Blittable Types

In particular, you can see this article , which discusses arrays.

Note: the part of my original answer that we found incorrect

So, looking at this, it seems that the " byte " is still not turning pale msgstr " Byte ". If you switch to Byte [], most likely it will work as you expect it. Note: char cannot be changed, but char is.

+7
source

Try the following: -

 [ComVisible(true)] public SomeObjectComVisible GetThat([MarshalAs(UnmanagedType.AsAny)] byte[] array){ ... } 

If this does not work, you can try the different values โ€‹โ€‹of the UnmanagedType enumeration to see if you can find the one that works.

Alternatively, you may need to mark the parameter as ref, i.e.

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

(Or perhaps a combination of the above.)

NOTE. Make sure you update the .tlb file after each change.

+6
source

Very old thread, but for VB.NET for VB6, for example. ByRef byte since Byte () works with processing. If ByRef is omitted and bytes are passed to ByVal (default), VB6 throws a "Function marked as restricted or uses a type not supported in Visual Basic."

0
source

Source: https://habr.com/ru/post/1384315/


All Articles