views:

86

answers:

1

Hello Im using v8 engine embedded in C++ program and I met a string problem.

Well of course v8 engine fully support utf8 string, but i just dont know how.

char path[ 1024 ]; 

GetCurrentDirectory( 1024, (LPWSTR)path );

script->Path = String::New(path);

However, the result is the only character "D", for String::New only accepts char* and utf_16*

I checked the v8 document and found no way to make a utf8 string, can anybody help me?

+2  A: 

Since you had to cast "path" to LPWSTR, it looks like you are calling the wide-string (unicode) Win32 API for GetCurrentDirectory, which is UTF-16. Try declaring "path" as wchar_t instead. If utf_16 is a typedef for wchar_t, it may work directly with String::New.

Adam Mitz
thx for your hint, that's the final working code: WCHAR path[ 1024 ]; GetCurrentDirectory( 1024, (LPWSTR)path ); script->Path = String::New((uint16_t*)path, wcslen(path));
Cauly