In C ++, I can initialize the <wstring> vector with wchar_t **, as in this example:
#include <windows.h>
#include <string>
#include <vector>
#include <cwchar>
using namespace std;
int main() {
int argc;
wchar_t** const args = CommandLineToArgvW(GetCommandLineW(), &argc);
if (args) {
const vector<wstring> argv(args, args + argc);
LocalFree(args);
}
}
However, is there a way to initialize wstring [] with wchar ** in D 2.0?
I can add the contents of wchar ** to wstring [] as follows:
import std.c.windows.windows;
import std.c.wcharh;
extern(Windows) {
wchar* GetCommandLineW();
wchar** CommandLineToArgvW(wchar*, int*);
void* LocalFree(void*);
}
void main() {
int argc;
wchar** args = CommandLineToArgvW(GetCommandLineW(), &argc);
if (args) {
wstring[] argv;
for (size_t i = 0; i < argc; ++i) {
wstring temp;
const size_t len = wcslen(args[i]);
for (size_t z = 0; z < len; ++z) {
temp ~= args[i][z];
}
argv ~= temp;
}
LocalFree(args);
}
}
But I would like to find a cleaner and easier way, like a C ++ version. (Performance is not a concern)
source
share