Hi,
fist I´d recommend the use of std::vector instead of char *. Then you can pass a reference of that vector to your function and fill in data:
If you want to pass binary data you have to specify the start and end address of the memory range to copy:Code:void GetSomething( std::vector<char>& Data ) { std::string SomeData = "C++"; // reserve space Data.reserve( Data.length() +1 ); // copy data std::copy( SomeData.begin(), SomeData.end(), back_inserter( Data ) ); } int main() { std::vector<char> Data; // get data GetSomeThing( Data ); // pointer to first data byte char *pszReturnString = &Data[0]; }
Hope this helps,Code:void GetSomething( std::vector<char>& Data ) { char *pcSomeMemoryBlock; int iDataLength; // reserve space Data.reserve( iDataLength ); // copy data std::copy( pcMemoryBlock, pcMemoryBlock + iDataLength, back_inserter( Data ) ); }
Guido




Reply With Quote