0

I have a C++\CLI managed class method that takes an out array. I want to pass this out array to the underlying C++ function that takes a vector< char >&. This C++ functions fills the array with values.

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);
A9S6
  • 6,575
  • 10
  • 50
  • 82
  • 1
    And... How you want to automatically convert ref C++/CLI class to C++ class? Anyway, look at http://stackoverflow.com/questions/6846880/convert-systemarray-to-stdvector – ForEveR Jan 25 '13 at 12:15
  • I was thinking if there something similar to msclr::interop::marshal_as<> that I can use here. – A9S6 Jan 28 '13 at 05:14

1 Answers1

0

Have you any reason to expect that array<unsigned char>^ %bits can be converted to vector<char> &bits?

You can try to modify MyCppClass, adding a member that returns a reference to a static vector. In GetBits you can clear it, and iterate through bits adding the chars to it. You may also find Marshaling in C++ useful.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
qPCR4vir
  • 3,521
  • 1
  • 22
  • 32