0

Does the NodeJS N-API have any concept or support for C++ wstring? I can't find entries for something like

Napi::WString

The documentation makes no mention of a WString. But wstring is commonly used on Windows APIs. I'm curious how it's typically handled?

Shane Gannon
  • 6,770
  • 7
  • 41
  • 64
  • I think you can interoperate with utf16 LE strings. e.g.: https://github.com/uriegel/extension-fs/blob/066592aa93d687acdf467b22849b4236c91b5f37/wstring.h – Wyck Oct 25 '22 at 20:12

1 Answers1

1

Napi types match the internal V8 types - and there is only one internal string type - which happens to use UTF-16 encoding. There are multiple definitions for Napi::String::New and one of them expects a char16_t * input. If your encoding is the same - which is usually the case for 16 bit chars - then you don't need anything else. But still, take care because wchar does not specify an encoding - only a character size.

mmomtchev
  • 2,497
  • 1
  • 8
  • 23