zoukankan      html  css  js  c++  java
  • C# 通过 参数返回 C++ 指针

    参数返回 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);
  • 相关阅读:
    《人件》阅读笔记五
    《人件》阅读笔记四
    《人件》阅读笔记三
    《人件》阅读笔记二
    《人件》阅读笔记一
    年报系统课堂讨论记录
    系统利益相关者描述案例
    Android开发学习记录--活动生命周期
    jQuery AJAX简介
    jQuery HTML简介
  • 原文地址:https://www.cnblogs.com/bkyrslf/p/12077908.html
Copyright © 2011-2022 走看看