sorry, didn't want to paste entire project and I can't right now from my phone.
I assign the temp array to lpFile just fine. I got the const error when I tried to pass lpFile as the dest in StringCchCopy()
So what I do now is HeapAlloc the temp array in the nested loop then point lpFile to that. From there I can't free the temp array. Do I need to just free lpFile when I'm done with it or the whole SHELLEXECUTEINFO structure?
This should be more clear
// Code here to open ini file and save the text in sText
// Now we should have a valid UCS-16 LE string in sText
SHELLEXECUTEINFOW rInfo = {0};
rInfo.cbSize = 60;
rInfo.nShow = 1;
while (*sEndPtr) // Loop while the end of line pointer doesn't point to \0
// Code her to get a line of text from sText and store the substrings into sSetting and sLine
if (wcscmp(sSetting, L"lpFile") == 0) {
// I can malloc an array and point rInfo.lpFile to it here but
// if I try to do this
// wcscpy(rInfo.lpFile, sLine);
// I get an error that wcscpy expected wchar_t * but received const wchar_t *
// Instead, I malloc a temp array and point rInfo.lpFile to it
wchar_t *sTemp = malloc(sizeof(wchar_t) * iSize);
wcscpy(sTemp, sLine);
rInfo.lpFile = sTemp;
// If I try to free(sTemp) here it works but
// when I try to read from rInfo.lpFile later, it is overwritten/corrupted
} // end if
} // end while
ShellExecuteExW(rInfo);
// Now that I'm done with rInfo I can free that memory
// If I try to free sTemp here, I get an error that it is undeclared or undefined or whatever
// To properly clean it up, do I need to free(rInfo.lpFile) or simply free(rInfo) or is there something else I'm missing?