我现在要进行托管和非托管之间的通信
 public enum ItemType
    {
        String,
        Byte,
    }
    public class QueueItem
    {
        private ItemType type;        private int itemId;        private byte[] context;        //private int contextLength;      
        public QueueItem(ItemType type,int id,byte[] context)
        {
            this.type = type;
            this.itemId = id;
            this.context = new byte[context.Length];
            //this.contextLength = this.context.Length;
            //Buffer.BlockCopy(context, 0, this.context, 0, context.Length);
            //this.context = context;
            //PackCommands();
        }
        //public int ContextLength
        //{
        //    get
        //    {
        //        return this.contextLength;
        //    }
        //}
        public int ItemID
        {
            get
            {
                return itemId;
            }
        }
        public byte[] Context
        {
            get
            {
                return context;
            }
        }
        public ItemType Type
        {
            get
            {
                return type;
            }
        }
        
    }
这是个元素类 [DllImport("coredll.dll")]
        public static extern int SendMessage(System.IntPtr wnd, uint msg, UInt16 wparam, UInt16 lparam);
       
        public virtual void EnQueue(QueueItem item)
        {
             IntPtr _formHandl;
             if (_type == TransferType.ClientTransfer)
                _formHandl = PublicLib.NativeApi.NativeMethod.FindWindow(null, Mantis);
            else
                _formHandl = PublicLib.NativeApi.NativeMethod.FindWindow(null, Client);            _sendItem = System.Runtime.InteropServices.Marshal.AllocHGlobal(QueueItemTool.PackCommands(item.Context,item.Type).Length);
//在这以上都不用管,关键是下边这句话,总是过不去,我怀疑是ITEM的格式问题,不知道为什么
            System.Runtime.InteropServices.Marshal.StructureToPtr(item.Context, _sendItem, true);
            Microsoft.WindowsCE.Forms.Message msg = Microsoft.WindowsCE.Forms.Message.Create(
                _formHandl,
                WM_CUSTOMMSG,
               _sendItem, _sendItem);
            MessageWindow.PostMessage(ref msg);
           
            
        }