将数组从C#传递到C++;库并返回数组

将数组从C#传递到C++;库并返回数组,c#,c++,arrays,interop,C#,C++,Arrays,Interop,我试图包装C++库,用于在C.W.WPF项目中使用。作为其中的一部分,我需要通过并返回从C到C++的大数组,并返回一个大数组。通过阵列似乎是这样实现的: namespace CppWrapper { public ref class CppWrapperClass { public: void DoStuff(int* pInt, int arraySize); private: computingClass* p

我试图包装C++库,用于在C.W.WPF项目中使用。作为其中的一部分,我需要通过并返回从C到C++的大数组,并返回一个大数组。通过阵列似乎是这样实现的:

namespace CppWrapper {

    public ref class CppWrapperClass
    {
    public:
        void DoStuff(int* pInt, int arraySize);
    private:        
        computingClass* pCC;
    };
}
         int noElements = 1000;
         int[] myArray = new int[noElements];

         for (int i = 0; i < noElements; i++)
            myArray[i] = i * 10;

         unsafe
         {
            fixed (int* pmyArray = &myArray[0])
            {

               CppWrapper.CppWrapperClass controlCpp = new CppWrapper.CppWrapperClass();
               controlCpp.DoStuff(pmyArray, noElements);
            }

         }
然后这样叫:

namespace CppWrapper {

    public ref class CppWrapperClass
    {
    public:
        void DoStuff(int* pInt, int arraySize);
    private:        
        computingClass* pCC;
    };
}
         int noElements = 1000;
         int[] myArray = new int[noElements];

         for (int i = 0; i < noElements; i++)
            myArray[i] = i * 10;

         unsafe
         {
            fixed (int* pmyArray = &myArray[0])
            {

               CppWrapper.CppWrapperClass controlCpp = new CppWrapper.CppWrapperClass();
               controlCpp.DoStuff(pmyArray, noElements);
            }

         }
int-noElements=1000;
int[]myArray=新的int[noElements];
for(int i=0;i
如何返回数组


注:如能就实现这一目标的最佳方式提供任何反馈,我将不胜感激。很奇怪,从C到C++,这并不容易。我发现用JNI包装库要容易得多无效DoStuff(数组^ ARR);<代码>去掉所有不必要的C代码,只需添加对DLL的引用并直接调用DoStuff()。足够简单吗?如果由于外部依赖而无法使用CLI,您仍然可以像这样传递数组: