Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Windows: another attempt to support unicode argv
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Feb 16, 2012
1 parent 9364699 commit d52f502
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions node.gyp
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions src/node_main.cc
Expand Up @@ -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

0 comments on commit d52f502

Please sign in to comment.