If I wanted to fill a vector with a struct, and in the struct I need to dynamically allocate/relocate the WCHAR arrays, how would I populate this?
I can’t use std::wstring because I’m going to be using the members with the Windows API.
And functions like RegQueryValueEx require a LPBYTE to receive the data.
Or is there some other STL container I should be using?
Example Code:
typedef struct {
WCHAR *str1;
WCHAR *str2;
DWORD SomeOtherStuff;
} MYSTRUCT;
vector<MYSTRUCT> myvector;
Use
std::vector<WCHAR>for the structure members. This will give your structure the necessary copy/move semantics to put it in avectorand, when you need a raw pointer for some API, it’s avaiable as&str1[0].Remember to make sure it’s large enough (either by initialising it to the required size, or calling
resize()) before doing anything that will access the data. Also remember that pointers and iterators to the data will become invalid when the vector is resized.