unicode fix
This commit is contained in:
parent
c5cc9556e6
commit
a586acf8a4
16
binding.gyp
16
binding.gyp
@ -2,7 +2,21 @@
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "winutils",
|
||||
"sources": [ "index.cc" ]
|
||||
"sources": [ "index.cc" ],
|
||||
|
||||
'conditions': [
|
||||
[ 'OS=="win"', {
|
||||
'defines': [
|
||||
'UNICODE=1',
|
||||
'_UNICODE=1',
|
||||
'_SQLNCLI_ODBC_',
|
||||
],
|
||||
'libraries': [
|
||||
'odbc32.lib'
|
||||
],
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
12
index.cc
12
index.cc
@ -202,17 +202,19 @@ void elevate(const v8::FunctionCallbackInfo<Value>& args) {
|
||||
|
||||
String::Utf8Value exePathArg(args[0]);
|
||||
std::string exePath(*exePathArg);
|
||||
std::wstring w_exePath = s2ws(exePath);
|
||||
|
||||
String::Utf8Value cmdLineArg(args[1]);
|
||||
std::string cmdLine(*cmdLineArg);
|
||||
std::wstring w_cmdLine = s2ws(cmdLine);
|
||||
|
||||
SHELLEXECUTEINFO shExInfo = {0};
|
||||
shExInfo.cbSize = sizeof(shExInfo);
|
||||
shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
|
||||
shExInfo.hwnd = 0;
|
||||
shExInfo.lpVerb = "runas";
|
||||
shExInfo.lpFile = exePath.c_str();
|
||||
shExInfo.lpParameters = cmdLine.c_str();
|
||||
shExInfo.lpVerb = L"runas";
|
||||
shExInfo.lpFile = w_exePath.c_str();
|
||||
shExInfo.lpParameters = w_cmdLine.c_str();
|
||||
shExInfo.lpDirectory = 0;
|
||||
shExInfo.nShow = SW_SHOW;
|
||||
shExInfo.hInstApp = 0;
|
||||
@ -241,12 +243,12 @@ void GetSystem32Path(const v8::FunctionCallbackInfo<Value>& args) {
|
||||
int size = WideCharToMultiByte(CP_UTF8, 0, szPath, -1, NULL, 0, NULL, NULL);
|
||||
if (size > 0) {
|
||||
buffer.resize(size);
|
||||
WideCharToMultiByte(CP_UTF8, 0, szPath, -1, static_cast<BYTE*>(&buffer[0]), buffer.size(), NULL, NULL);
|
||||
WideCharToMultiByte(CP_UTF8, 0, szPath, -1, &buffer[0], buffer.size(), NULL, NULL);
|
||||
}
|
||||
else {
|
||||
isolate->ThrowException(Exception::TypeError(
|
||||
String::NewFromUtf8(isolate, "Failed to convert string")));
|
||||
return
|
||||
return;
|
||||
}
|
||||
std::string string(&buffer[0]);
|
||||
#else
|
||||
|
8
utils.h
8
utils.h
@ -71,9 +71,9 @@ std::wstring s2ws(const std::string& s)
|
||||
{
|
||||
int len;
|
||||
int slength = (int)s.length() + 1;
|
||||
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
|
||||
len = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), slength, 0, 0);
|
||||
wchar_t* buf = new wchar_t[len];
|
||||
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
|
||||
MultiByteToWideChar(CP_UTF8, 0, s.c_str(), slength, buf, len);
|
||||
std::wstring r(buf);
|
||||
delete[] buf;
|
||||
return r;
|
||||
@ -84,9 +84,9 @@ std::string ws2s(const std::wstring& s)
|
||||
{
|
||||
int len;
|
||||
int slength = (int)s.length() + 1;
|
||||
len = WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, 0, 0, 0, 0);
|
||||
len = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), slength, 0, 0, 0, 0);
|
||||
char* buf = new char[len];
|
||||
WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, buf, len, 0, 0);
|
||||
WideCharToMultiByte(CP_UTF8, 0, s.c_str(), slength, buf, len, 0, 0);
|
||||
std::string r(buf);
|
||||
delete[] buf;
|
||||
return r;
|
||||
|
Loading…
x
Reference in New Issue
Block a user