_declspec(dllexport)  short encode(   /* (o) Number of bytes encoded */
   short *encoded_data,    /* (o) The encoded bytes */
   short *data                 /* (i) The signal block to encode*/
   )_declspec(dllexport) short decode(  
   short *decoded_data,        /* (o) Decoded signal block*/
   short *encoded_data /* (i) Encoded bytes */
   )  {
从网上找的 ilbc的c++代码,然后声明外部调用的接口
然后在C#端调用 DLL [DllImport(ILBCDLL)]
        /// Number of bytes encoded
        [SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
        private static extern short encode(   /* (o) */
          ref  short[] encoded_data,    /* (o) The encoded bytes */
          ref  short[] data                 /* (i) The signal block to encode*/
        );        [DllImport(ILBCDLL)]
        /// Number of decoded samples
        [SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
        private static extern short decode(       /* (o) */
       
          ref short[] decoded_data,        /* (o) Decoded signal block*/
          ref  short[] encoded_data        /* (i) Encoded bytes */        
        );但是在调用的时候,在encode地方报了下面的异常
Attempted to read or write protected memory. This is often an indication that other memory is corrupt
有什么办法解决,谢谢!

解决方案 »

  1.   

    C++和C#的类型不一样,你直译过来肯定不行。
    试下这样:[DllImport(ILBCDLL)]
            /// Number of bytes encoded
            [SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
            private static extern Int32 encode(   /* (o) */
              byte[] encoded_data,    /* (o) The encoded bytes */
              byte[] data                 /* (i) The signal block to encode*/
            );        [DllImport(ILBCDLL)]
            /// Number of decoded samples
            [SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
            private static extern Int32 decode(       /* (o) */
           
              byte[] decoded_data,        /* (o) Decoded signal block*/
              byte[] encoded_data        /* (i) Encoded bytes */        
            );
      

  2.   

    谢谢楼上的,这样也不行,而且这样也符要求,因为 private static extern Int32 encode(  /* (o) */ 
              byte[] encoded_data,    /* (o) The encoded bytes */ //这里是要传出来的
              byte[] data                /* (i) The signal block to encode*/ 
            );