Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Windows: another attempt to support unicode argv

  • Loading branch information...
commit d52f5020cecc16349cce902e9f869d33a9213752 1 parent 9364699
Bert Belder piscisaureus authored
Showing with 42 additions and 0 deletions.
  1. +1 −0  node.gyp
  2. +41 −0 src/node_main.cc
1  node.gyp
View
@@ -160,6 +160,7 @@
'FD_SETSIZE=1024',
# we need to use node's preferred "win32" rather than gyp's preferred "win"
'PLATFORM="win32"',
+ '_UNICODE=1',
],
'libraries': [ '-lpsapi.lib' ]
},{ # POSIX
41 src/node_main.cc
View
@@ -21,6 +21,47 @@
#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[]) {
return node::Start(argc, argv);
}
+#endif
Please sign in to comment.
Something went wrong with that request. Please try again.