MindScape

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

看到dudu分享的贴代码方法立刻就来试验一下,效果的确很好可惜我机器上只有Office XP,所以没有颜色了。

至于这段snippet嘛,使用来示范如何在VB6中调用一个.NET写的COM组件,并传入、传出以及返回一个ByteArray的。
其实写出来的代码很简单的,但当刚开始确实十分麻烦,因为我找不到.NET中对应的Attribute(主要是InAttribute, OutAttribute ,对应关键字in, out,ref和IDL定义间的关系。
我现在想想[return:MarshalAs()]这个属性可能也不需要加的。你可以试一试告诉我结果


using System;

using System.Runtime.InteropServices;

 

namespace expose_to_COM

{

     public interface IInfo

     {

 

         [

              return: MarshalAs(UnmanagedType.SafeArray)

         ]

         byte[] GetBytes(ref byte[] bytes);

     }

 

     [ClassInterface(ClassInterfaceType.None)]

     public class Class1: IInfo

     {

         public Class1()

         {

         }

 

         public byte[] GetBytes(ref byte[] bytes)

         {

              byte[] _bytes = new byte[]{0x30,0x31,0x32,0x00};

              return _bytes;

         }

     }

}

 

 

posted on 2004-02-19 01:24  Jonny Yu  阅读(1188)  评论(0编辑  收藏  举报