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

  • Home
  • SEARCH
  • 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 670573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:16:44+00:00 2026-05-14T00:16:44+00:00

I need to convert CString to BYTE array. I don’t know why, but everything

  • 0

I need to convert CString to BYTE array. I don’t know why, but everything that I found in internet does not work 🙁
For example, I have

CString str = _T("string");

I’ve been trying so
1)

BYTE *pbBuffer = (BYTE*)(LPCTSTR)str;

2)

BYTE *pbBuffer = new BYTE[str.GetLength()+1];
memcpy(pbBuffer, (VOID*)(LPCTSTR)StrRegID, str.GetLength());

3)

BYTE *pbBuffer = (BYTE*)str.GetString();

And always pbBuffer contains just first letter of str

DWORD dwBufferLen = strlen((char *)pbBuffer)+1;

is 2

But if I use const string:

BYTE *pbBuffer = (BYTE*)"string";

pbBuffer contains whole string

Where is my mistake?

  • 1 1 Answer
  • 1 View
  • 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-14T00:16:45+00:00Added an answer on May 14, 2026 at 12:16 am

    Your CString is Unicode (two bytes per character) and you try to interpret it as ANSI (one byte per character). This leads to results you don’t expect.

    Instead of casting the underlying buffer into char* you need to convert the data. Use WideCharToMultiByte() for that.

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

Sidebar

Ask A Question

Stats

  • Questions 523k
  • Answers 523k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Check out Tidy.Net. It's a .Net implementation of Tidy. May 16, 2026 at 9:41 pm
  • Editorial Team
    Editorial Team added an answer lock_hash_recurse Catch the exception, then dump as you wish and… May 16, 2026 at 9:41 pm
  • Editorial Team
    Editorial Team added an answer Pretty easy. Use $.ajax, and check out the serialize() function… May 16, 2026 at 9:41 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Need to convert RGB or HEX colors to Long Int for another program that
I need to convert a navigable map to a 2D String array. Below given
I need to convert between python objects and c strings of various encodings. Going
Are there any converters available that converts Java code to C#? I need to
I need to convert the text in the textbox of my xaml code to
I need to convert a string like this: A &#039;quote&#039; is <b>bold</b> into: A
I need to convert an integer into a base64-character representation. I'm using OxA3's answer
I need to convert a String representation of a nested List back to a
I need to convert a date from this format: 2002-10-10T12:00:00-05:00 (xs:dateTime as defined in
I need to convert a SimpleXML object to a DOMDocument , to use it

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.