I'm working on a function that calls a Win32 function called RmRegisterResources.
This function accepts a parameter of type LPCWSTR[] for a list of file paths, our resources.
I'm trying to assemble the LPCWSTR array, but it always initialize with only one member.
Here's what I'm doing:
void Test(std::vector<LPCWSTR> input)
{
size_t vecsize = input.size();
LPCWSTR* resourcelist = new LPCWSTR[vecsize];
for (size_t i = 0; i < input.size(); i++)
{
LPCWSTR single = input.at(i);
size_t strsize = wcslen(single);
resourcelist[i] = new WCHAR[strsize];
wcscpy_s((WCHAR*)resourcelist[i], strsize, single);
}
/*
The rest of the code...
*/
}
On the for loop's first iteration, it copies the first string with no problem.
On the second one, wcscpy_s doesn't fail, but I have no idea where it copied the string.
At the end, the call to RmRegisterResources works with just the first copied string, no problem.
What am I missing?
Disc.: I am not a developer, I'm a curious sys admin wanting to learn C++. I know the issue must be simple, and believe me, I have searched two days in a row for a solution.
On the documentation, Microsoft encourages passing multiple file names at once, because the operation is costly.
Thank you very much!
Edit:
The vector input.data() thing:
Edit2:
If I create the array with a constant value, it works. like this:
LPCWSTR string[2] = { L"Thisisastring", L"Thisisalso" }
However, trying to allocate memory either with functions like LocalAlloc, or with the new keyword I got this error.