Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

411
Views
Pass string from C++ to JS using emscripten

I am trying to send string from C++ to JS using emscripten but I'm not able to convert it appropriately in JS.

C++

    EMSCRIPTEN_KEEPALIVE const char* accessDetails()
    {
        return func().c_str();
    }

func returns std::string.

I'm getting some garbage value number. How can I get the string in JS?
Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When calling a raw WebAssembly function like that you only basic types are supported. In this case you are returned a pointer which is just a number (pointer are number in JS just like they are in C/C++). You can use that pointer to read bytes out of WebAssembly memory and produce a JS string from them using, for example, UTF8ToString(number), or you can use one of the higher level binding systems such as embind to take care of it for you.

See https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html for more information.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!