I am trying to wrap C++ code with NAPI (Node addon API). While writing the code, I faced the following problem.
When returning a string from napi side to js side, Non-English (Korean/Japanese/Chinese) strings are displayed as broken.
Is there any way to solve this? Any solutions or ideas would be appreciated!
The code is: (NAPI side)
#include <iostream>
#include "wrapper.h"
Napi::Value wrapper::getNameWrapper(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
std::string dcmFilePath = info[0].As<Napi::String>().Utf8Value();
Napi::String name = Napi::String::New(env, wrapper::getName(dcmFilePath));
return patientName;
}
std::string wrapper::getName(std::string dcmFilePath)
{
std::stringstream returnStringStream;
returnStringStream << "김한춘"; // Non-English string (Korean)_
return returnStringStream.str();
}
Napi::Object wrapper::Init(Napi::Env env, Napi::Object exports)
{
exports.Set("getName", Napi::Function::New(env, wrapper::getNameWrapper));
return exports;
}
(js side)
const wrapper = require('./build/Release/wrapper.node')
console.log('wrapper: ', wrapper)
let name = wrapper.getName('C:/Users/p1h2c/Desktop/R2DATA/金韓春/DCT0000.dcm')
console.log('getName: ', name) // I expected '김한춘' but show '김?�춘'
module.exports = wrapper