Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6695755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:15:36+00:00 2026-05-26T06:15:36+00:00

This may or may not be a SWIG question. I am trying to return

  • 0

This may or may not be a SWIG question.

I am trying to return a std::wstring by value from a C++ function to C#. The returned string has a mixture of plain old English chars and Hebrew chars. The English chars come through fine, but the Hebrew chars are being converted to the question mark symbol at some point.

I am using SWIG to generate the marshalling code. Stepping through it all with a debugger, it gets to the following SWIG code…

static string CreateWString([MarshalAs(UnmanagedType.LPWStr)]IntPtr cString) {
    string str = System.Runtime.InteropServices.Marshal.PtrToStringUni(cString);
    return str;
}

At this point str looks perfect.

Next this is returned to the SWIG-generated C++ code which returns the str as a void*.

Then the void* becomes a .net string again in the calling code. In the calling code, all the hebrew chars are ? marks.

Any ideas what’s causing this?

Edit:

Further information

As soon as CreateWString returns to the C++ caller you can see the pointer in the debugger looks to be an ANSI string with ? marks in it. So it seems that .net is performing some sort of conversion on the string before it returns to the caller. Does that sound right? How can I control that?

Edit 2:
It seems I need to do MarshallAs on the return type CreateWString to stop .net from converting to a TCHAR type (?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:15:37+00:00Added an answer on May 26, 2026 at 6:15 am

    Modify the CreateWString definition to:

    [return: MarshalAs(UnmanagedType.LPWStr)]
    static string CreateWString([MarshalAs(UnmanagedType.LPWStr)]IntPtr cString)
    

    See the examples in the MarshalAsAttribute documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem an easy question, but not to me, also a search has
This may not be the typical stackoverflow question. A colleague of mine has been
This may not be a programming question, but I don't know where to ask
This may not be the kind of question one should ask on StackOverflow, but
Sorry, this may or may not be a programming question directly, but I am
This question may not directly relate to programming. I have noticed that the technology
This may be a silly question to a graphics guru (which I am not),
This may sound like a stupid question but I'm a beginner not just to
I know this may not be exactly a coder question, but I feel it
This may or may not be the dumbest question ever. I'm using Restlet. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.