Search code examples
c++stringtypesv8

Convert v8::String to LPCWSTR?


So I'm passing a string value as function argument from runtime:

Handle<Value> xObj::Whatever(const Arguments& args){ ... // etc.

args[0] should definitely be string:

      if(!args[0]->IsString()) { ThrowException(... // etc.

Now that we have that, how do I convert it into something useful like LPCWSTR, wchar_t, char[] or whatever?

      MessageBox(NULL, args[0], L"Your value, sir.",0); // no way
      MessageBox(NULL, args[0]->ToString(), L"Your value, sir.",0); // also no
      /// then how?

Solution

  • v8::String::Value(args[0]) can be casted to a uint16_t const*, which either is, or can be casted to LPCWSTR. (This depends on compiler setting /Zc:wchar_t-)