std::vector<std::string > objs(numFiles, std::string(MAX_PATH, 0));
std::vector<MapiFileDesc> fileDesc(numFiles);
for (int i = 0; i < numFiles; ++i)
fileDesc[i].lpszPathName=objs[i].data();
// after the C API calls, if you do need to use the strings as C++ strings,
// resync the C++ string length with the C string data
// (not necessary if you just use them via c_str())
for (int i = 0; i < numFiles; ++i)
objs[i].resize(strlen(objs[i].c_str());
By the way, if you don't need to pass the whole array to C APIs but just single structs, you can make a single vector of a struct that stores both the MapiFileDesc
structure and the std::string
, binding strongly the lifetime of both objects and allowing the constructor to take care of linking lpszPathName
with the string data()
member; still, probably I wouldn't bother if this structure is used just in a single function.