码迷,mamicode.com
首页 > 编程语言 > 详细

C# 通过 参数返回 C++ 指针

时间:2019-12-21 20:53:48      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:unicode   toc   ntp   amp   col   test   nbsp   span   string   

 

 

参数返回 C++ 指针

C++ 代码

 Extern_C  BASECORELIBRARY_API  char  *  GetFileByteArray(wchar_t * BinfilePath, wchar_t *BinfileName,int indexFile, int * length , char  **at11t)
 {


     char *chBinfilePath= nullptr, *chBinfileName = nullptr;
     wchar_tTranstoChar(BinfilePath, &chBinfilePath);
     wchar_tTranstoChar(BinfileName, &chBinfileName);

     char a[] = "13345zh中文 hello";

     int  fileCount = sizeof(a);
         /// sizeof(char*);
     char  * att = new char[fileCount];

     memcpy(att, a, fileCount);
    
     *length = fileCount-1;

     free(chBinfilePath);
     free(chBinfileName);
      *at11t = att;
     return  att;
    // return  fileCount;
 }

 

 

 

 

C# 代码

        [DllImport("BASECORELIBRARY.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr GetFileByteArray(string BinfilePath, string BinfileName, int indexFile,ref  int length, ref IntPtr test);


   IntPtr piBuf2 = IntPtr.Zero;

 IntPtr piBuf = InvokeDLL.GetFileByteArray(newFilePath, toBinName, 0, ref length, ref piBuf2);
            
            byte[] arrayBuf = new byte[length];
            Marshal.Copy(piBuf,arrayBuf,0, length);

 

C# 通过 参数返回 C++ 指针

标签:unicode   toc   ntp   amp   col   test   nbsp   span   string   

原文地址:https://www.cnblogs.com/bkyrslf/p/12077908.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!