If the argument is for input only , use std::string , like this
std::string text("Hello"); w32function(text.c_str());
If the argument is input / output , use std::vector<char> instead:
std::string input("input"); std::vector<char> input_vec(input.begin(), input.end()); input_vec.push_back('\0'); w32function(&input_vec[0], input_vec.size());
If the argument is for output only , also use std::vector<Type> as follows:
// allocates _at least_ 1k and sets those to 0 std::vector<unsigned char> buffer(1024, 0); w32function(&buffer[0], buffer.size()); // use 'buffer' vector now as you see fit
You can also use std::basic_string<TCHAR> and std::vector<TCHAR> if necessary.
You can read more on this topic in Scott Meyers' Effective STL Book.
Dmitry
source share