I'm trying to convert the list of strings into a single string in this form: "Pscript.dll\0QMS810.ppd\0Pscriptui.dll\0Pscriptui .hlp\0Pstest.txt\0\0". However, I'm having some trouble adding the null characters properly. Here is my code and my problem is listed in the comments. Any suggestions?
Code:
// Process the vector into null terminated strings
void func(const vector<wstring> pAdditionalFiles)
{
LPTSTR pDependentFiles = NULL;
if(pAdditionalFiles.size())
{
// Allocate memory file for the pointers
pDependentFiles = new TCHAR[pAdditionalFiles.capacity()];
pDriverInfo->pDependentFiles = new TCHAR[pAdditionalFiles.capacity()];
_tcscpy(pDependentFiles, L"");
for(int i=0; i<pAdditionalFiles.size(); i++)
{
_tcscat(pDependentFiles, pAdditionalFiles[i].c_str());
_tcscat(pDependentFiles, L"\0"); // each filename needs to be null-terminated (get exception errors if I use '\0' as the source
}
_tcscat(pDependentFiles, L"\0"); // another null-terminator needed to end the list
}
}