将LPWSTR转换为v8 :: String

时间:2012-12-28 03:42:24

标签: c++ node.js v8

LPWSTR dscStr = "TEST STRING AAAAAA";

char buffer[5000];
wcstombs(buffer, dscStr, sizeof(dscStr));

return scope.Close(String::New(buffer)); // FAILED

我需要将LPWSTR(或LPCWSTR)转换为v8 :: String。

1 个答案:

答案 0 :(得分:1)

您发布的代码甚至不应该编译,因为您尝试将char const *分配给wchar_t *

这应该有效(我对v8::String一无所知,所以我假设最后一行的构造函数调用是正确的)

LPCWSTR dscStr = L"TEST STRING AAAAAA";
// LPCWSTR is an alias for wchar_t const *
// The L before the string literal indicates it is a wide string literal

char buffer[5000];
wcstombs( buffer, dscStr, wcslen(dscStr) );
// Need wcslen to compute the length of the string

return scope.Close(String::New(buffer));