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 1000163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:28:04+00:00 2026-05-16T07:28:04+00:00

I want an option to convert a string to wide string with two different

  • 0

I want an option to convert a string to wide string with two different behaviors:

  1. Ignore illegal characters
  2. Abort conversion if illegal character occurs:

On Windows XP I could do this:

bool ignore_illegal; // input

DWORD flags = ignore_illegal ? 0 : MB_ERR_INVALID_CHARS;

SetLastError(0);

int res = MultiByteToWideChar(CP_UTF8,flags,"test\xFF\xFF test",-1,buf,sizeof(buf));
int err = GetLastError();

std::cout << "result = " << res << " get last error = " << err; 

Now, on XP if ignore illegal is true characters I would get:

result = 10 get last error = 0

And in case of ignore illegal is false I get

result = 0 get last error = 1113 // invalid code

So, given big enough buffer it is enough to check result != 0 ;

According to documentation http://msdn.microsoft.com/en-us/library/dd319072(VS.85).aspx
there are API changes, so how does this changes on Vista?

  • 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-16T07:28:04+00:00Added an answer on May 16, 2026 at 7:28 am

    I think what it does is replacing illegal code units by the replacement character (U+FFFD), as mandated by the Unicode standard. The following code

    #define STRICT
    #define UNICODE
    #define NOMINMAX
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    
    #include <cstdlib>
    #include <iostream>
    #include <iomanip>
    
    
    void test(bool ignore_illegal) {
        const DWORD flags = ignore_illegal ? 0 : MB_ERR_INVALID_CHARS;
        WCHAR buf[0x100];
        SetLastError(0);
        const int res = MultiByteToWideChar(CP_UTF8, flags, "test\xFF\xFF test", -1, buf, sizeof buf);
        const DWORD err = GetLastError();
        std::cout << "ignore_illegal = " << std::boolalpha << ignore_illegal
            << ", result = " << std::dec << res
            << ", last error = " << err
            << ", fifth code unit = " << std::hex << static_cast<unsigned int>(buf[5])
            << std::endl;
    }
    
    
    int main() {
        test(false);
        test(true);
        std::system("pause");
    }
    

    produces the following output on my Windows 7 system:

    ignore_illegal = false, result = 0, last error = 1113, fifth code unit = fffd
    ignore_illegal = true, result = 12, last error = 0, fifth code unit = fffd
    

    So the error codes stay the same, but the length is off by two, indicating the two replacement code points that have been inserted. If you run my code on XP, the fifth code point should be U+0020 (the space character) if the two illegal code units have been dropped.

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

Sidebar

Related Questions

I want to define a function: def convert(x: Option[String]): Option[String] = ... When x
I have string on the format $0Option one$1$Option two$2$Option three (etc) that I want
I want to convert string representation of real number to real type. I know
If I have something like a List[Option[A]] and I want to convert this into
I want to be able to convert big ints into their full string derivatives.
I want to hide an option in my form unless a specific option is
I want to add the option when the menu is called with the right
I want to make INSTALLS option for my project.That i want is when i
I want to remove the option Invite Only from Membership Requests in Organic Groups.
I want to create a facebook share option after payment is succeeded. I am

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.