2013-01-25 211 views
0

我有一个C++ \ CLI托管类方法,它接受一个out数组。我想把这个数组传递给底层的C++函数,它需要一个向量< char> &。这个C++函数用值填充数组。将[out]数组传递给C++函数

bool MyLib::GetBits([Out] array<unsigned char>^ %bits) 
{ 
    MyCppClass->GetBits(bits); // ???? 
    // ERROR: C2664: cannot convert from 'cli::array<Type> ^' to 'std::vector<_Ty> &' 
} 

'GetBits' is declared as MyCppClass::GetBits(vector<char> &bits); 
+1

And ...你想如何自动将ref C++/CLI类转换为C++类?无论如何,看看http://stackoverflow.com/questions/6846880/convert-systemarray-to-stdvector – ForEveR

+0

我想在这里可以使用类似于msclr :: interop :: marshal_as <>的东西。 – A9S6

回答

0

你有什么理由认为array<unsigned char>^ %bits可以转换为vector<char> &bits

您可以尝试修改MyCppClass,添加一个返回对静态向量的引用的成员。在GetBits中,您可以清除它,并通过向其中添加字符的位进行迭代。你也可以找到Marshaling in C++有用。