Browse Source

Windows: another attempt to support unicode argv

v0.8.7-release
Bert Belder 13 years ago
parent
commit
d52f5020ce
  1. 1
      node.gyp
  2. 41
      src/node_main.cc

1
node.gyp

@ -160,6 +160,7 @@
'FD_SETSIZE=1024', 'FD_SETSIZE=1024',
# we need to use node's preferred "win32" rather than gyp's preferred "win" # we need to use node's preferred "win32" rather than gyp's preferred "win"
'PLATFORM="win32"', 'PLATFORM="win32"',
'_UNICODE=1',
], ],
'libraries': [ '-lpsapi.lib' ] 'libraries': [ '-lpsapi.lib' ]
},{ # POSIX },{ # POSIX

41
src/node_main.cc

@ -21,6 +21,47 @@
#include <node.h> #include <node.h>
#ifdef _WIN32
int wmain(int argc, wchar_t *wargv[]) {
// Convert argv to to UTF8
char** argv = new char*[argc];
for (int i = 0; i < argc; i++) {
// Compute the size of the required buffer
DWORD size = WideCharToMultiByte(CP_UTF8,
0,
wargv[i],
-1,
NULL,
0,
NULL,
NULL);
if (size == 0) {
// This should never happen.
fprintf(stderr, "Could not convert arguments to utf8.");
exit(1);
}
// Do the actual conversion
argv[i] = new char[size];
DWORD result = WideCharToMultiByte(CP_UTF8,
0,
wargv[i],
-1,
argv[i],
size,
NULL,
NULL);
if (result == 0) {
// This should never happen.
fprintf(stderr, "Could not convert arguments to utf8.");
exit(1);
}
}
// Now that conversion is done, we can finally start.
return node::Start(argc, argv);
}
#else
// UNIX
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
return node::Start(argc, argv); return node::Start(argc, argv);
} }
#endif

Loading…
Cancel
Save