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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:37:58+00:00 2026-05-13T23:37:58+00:00

I am use next type of strings: LPCSTR, TCHAR, String i want to convert:

  • 0

I am use next type of strings:
LPCSTR, TCHAR, String i want to convert:

  1. from TCHAR to LPCSTR
  2. from String to char

I convert from TCHAR to LPCSTR by that code:

RunPath = TEXT("C:\\1");
LPCSTR Path = (LPCSTR)RunPath;

From String to char i convert by that code:

SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Title = "Сохранение файла-настроек";
saveFileDialog1->Filter = "bck files (*.bck)|*.bck";
saveFileDialog1->RestoreDirectory = true;
pin_ptr<const wchar_t> wch = TEXT("");
if ( saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK ) {  
    wch = PtrToStringChars(saveFileDialog1->FileName);
} else return;
ofstream os(wch, ios::binary);

My problem is that when i set “Configuration Properties -> General
Character Set in “Use Multi-Byte Character Set” the first part of code work correctly. But the second part of code return error C2440. When i set “Configuration Properties -> General
Character Set in “Use Unicode” the second part of code work correctly. But the first part of code return the only first character from TCHAR to LPCSTR.

  • 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-13T23:37:59+00:00Added an answer on May 13, 2026 at 11:37 pm

    I’d suggest you need to be using Unicode the whole way through.

    LPCSTR is a “Long Pointer to a C-type String”. That’s typically not what you want when you’re dealing with .Net methods. The char type in .Net is 16bits wide.

    You also should not use the TEXT(“”) macro unless you’re planning multiple builds using various character encodings. Try wrapping all your string literals with the _W(“”) macro instead and a pure unicode build if you can.

    See if that helps.

    PS. std::wstring is very handy in your scenario.

    EDIT

    You see only one character because the string is now unicode but you cast it as a regular string. Many or most of the Unicode characters in the ASCII range has their same number as in ASCII but have the second of their 2 bytes set to zero. So when a unicode string is read as a C-string you only see the first character because C-strings are null ( zero ) terminated. The easy ( and wrong ) way to deal with this is to use std:wstring to cast as a std:string then pull the C-String out of that. This is not the safe approach because Unicode has a much large character space then your standard encoding.

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

Sidebar

Related Questions

I use next code to print current time Calendar cal = Calendar.getInstance(); System.out.println(cal.getTime()); I
In Flash Builder (flex 4) I try to use next code to set selected
I have the next query that I run via SQLCMD.EXE use [AxDWH_Central_Reporting] GO EXEC
I allocate a color entry with the next code, then I use it to
I can get all those url's whose content/type is text/html, but If I want
I am planning to use Drizzle in my next C# Mono app. Since there
My question is next: How to use pixel instead point for control? For example
I am looking to use/buy a OCR solution for my next iPhone app. Searching
I use the ASPxGridView with paging, pager settings is next: <SettingsPager Mode=ShowPager Position=Bottom Visible=true>
I've been thinking about using SQLite for my next project, but I'm concerned that

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.