将LPWSTR转换为v8::String

Convert LPWSTR to v8::String

本文关键字:String v8 LPWSTR 转换      更新时间:2023-10-16
LPWSTR dscStr = "TEST STRING AAAAAA";
char buffer[5000];
wcstombs(buffer, dscStr, sizeof(dscStr));
return scope.Close(String::New(buffer)); // FAILED

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

你发布的代码甚至不应该编译,因为你试图将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));