接受Byte数组,VB6到C#互操作 [英] Accepting a Byte array, vb6 to C# interop
问题描述
我做了comunicates VB6用加密封装的应用程序。在.NET和互操作的一部分,到现在为止,没有大碍,完全工作。
由于我的客户正在测试它,我只是有一个快速的问题:
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){ ... }
我用,到现在为止,无论是类型,我接触到COM或int和string,并没有任何问题,直到如今。
I used, until now, either types that I exposed to com or int and string, and no problems until now.
它是确定使用(.NET)字节
或chould我用 *字符
?
当我标记是可见的,并注册为COM互操作的程序集,它创建了一个包装,或者我应该使用一些非托管类型?
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?
嗯,这是一个维生素B6,而不是VBScript中。
Ah, it is a vb6, not vbscript.
太感谢了。
对于那些谁寻求答案:
public SomeObjectComVisible GetThat([MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_UI1)]byte[] array)
问题是阵列。 http://msdn.microsoft.com/en-us/library/z6cfh6e6.aspx 和 http://msdn.microsoft.com/en-us/library/75dwhxf7.aspx
the problem is with arrays. http://msdn.microsoft.com/en-us/library/z6cfh6e6.aspx and http://msdn.microsoft.com/en-us/library/75dwhxf7.aspx
任何非bittable类型可以是件苦差事。您可以指定自己的类型,因此使用它们,你就必须使用
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")]
在类的顶部
非常感谢大家。
大的帮助。
推荐答案
数组的封送的东西我用的时候经常与我的.Net code COM客户打交道的斗争。本文中,我发现,帮助我理解这个过程非常有用的。
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.
具体你可以看一下这篇文章其中谈到数组
Specifically you can look at this article which talks about arrays
注:我原来的答复,我们发现是不正确的部分的
因此,从看,它看起来像字节不blitable尚未 字节是。如果切换为byte []它可能会工作方式 你希望它。注:char是不是blitable,但字符是
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.
这篇关于接受Byte数组,VB6到C#互操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!