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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:49:50+00:00 2026-06-08T02:49:50+00:00

I have an Ansi char array like and want to initialize a CStringW (WCHAR

  • 0

I have an Ansi char array like and want to initialize a CStringW (WCHAR specialization of CString template). But the CString object does not have copy the chars from the array.

CStringW sSample = "ABC";
int length = sSample.GetLength(); // returns 3
PCWSTR wcsSample = (PCWSTR)sSample;
wcout << (int)wcsSample[0];  // output: 0
  • Version: ATL/MFC version 8.0
  • Platform: Windows CE 5.0 (x86)

Do you see any workaround?

  • 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-06-08T02:49:51+00:00Added an answer on June 8, 2026 at 2:49 am

    Well, I found the answer myself. It’s a bug in the MFC method

    CStringT& operator=( __in_z_opt PCYSTR pszSrc )
    

    The method calculates the length of the required buffer and allocates the buffer. The calculation does not include the terminating null character. Thereafter it calls MultiByteToWideChar, passing the length as the cchWideChar parameter.

    The function MultiByteToWideChar returns 0 as failure indication, but this is ignored by the MFC. As a side effect, MultiByteToWideChar fills the output buffer on some platforms like Win32 and Windows CE 5.0 (SH4).

    But the Windows CE 5.0 (x86) does not fill the buffer. Although the allocated buffer is too small, the bug is not visible on most platforms but on Windows CE 5.0 (x86). Here you get an empty CString after the assignment.

    The defect in the MFC is present in all MFC variants. But it is covered by a behavior of MultiByteToWideChar that behaves different on platforms.

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

Sidebar

Related Questions

I have a C++ program which does some processing on a char search[500] array.
I have some ANSI C code that I developed on my Mac, but when
I would like to have a string (char*) parsed into a tm struct in
I have a code to mimic ls -la in ansi C, but when I
Say I have a two functions like the ones below: unsigned char PlusTwo(unsigned char
I have a UNIX application written in ansi C that writes data directly to
I have this RTF text: {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}} {\colortbl ;\red0\green0\blue0;\red255\green0\blue0;} \viewkind4\uc1\pard\qc\cf1\fs16 test \b bold \cf2\b0\i
I'm learning C in ansi c and I have a question. I what to
This is an ANSI C question. I have the following code. #include <stdio.h> #include
I have a structure [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct SERVER_USB_DEVICE { USB_HWID usbHWID;

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.