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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:18:10+00:00 2026-06-04T05:18:10+00:00

Possible Duplicate: Convert lptstr to char* I need to convert an LPTSTR p to

  • 0

Possible Duplicate:
Convert lptstr to char*

I need to convert an LPTSTR p to CHAR ch[]. I am new to C++.

#include "stdafx.h"
#define _WIN32_IE 0x500
#include <shlobj.h>
#include <atlstr.h>
#include <iostream>
#include <Strsafe.h>

using namespace std;

int main(){
    int a;
    string res;
    CString path;
    char ch[MAX_PATH];
    LPTSTR p = path.GetBuffer(MAX_PATH);
    HRESULT hr = SHGetFolderPath(NULL,CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, p);

/* some operation with P and CH */

    if(SUCCEEDED(hr))
    { /* succeeded */
        cout << ch;
    } /* succeeded */
    else
    { /* failed */
        cout << "error";
    } /* failed */
    cin >> a;
    return 0;
}

Thanks in advance.

  • 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-04T05:18:11+00:00Added an answer on June 4, 2026 at 5:18 am

    LPTSTR is a (non-const) TCHAR string. Depends if it is Unicode or not it appears. LPTSTR is char* if not Unicode, or w_char* if so.

    If you are using non-Unicode strings LPTSTR is just a char*, otherwise do:

    size_t size = wcstombs(NULL, p, 0);
    char* CharStr = new char[size + 1];
    wcstombs( CharStr, p, size + 1 );
    

    Also, this link can help:

    Convert lptstr to char*

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

Sidebar

Related Questions

Possible Duplicate: Convert std::string to const char* or char* Simple question but I'm new
Possible Duplicate: How can I convert ereg expressions to preg in PHP? I need
Possible Duplicate: How do I convert byte[] to stream in C#? I need to
Possible Duplicate: Convert from char* to NSString? I have char myChar = 'r' How
Possible Duplicate: C++ convert int and string to char* Hello, i am making a
Possible Duplicate: Convert std::string to const char* or char* is there any to get
Possible Duplicate: Convert a String In C++ To Upper Case Hi, I need a
Possible Duplicate: Convert std::string to const char* or char* void setVersion(char* buf, std::string version)
Possible Duplicate: Convert NSString of a date to an NSDate I need some help
Possible Duplicate: Convert std::string to const char* or char* i've got a line from

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.