Solved

LPSTR/CString

Posted on 2000-04-11
3
1,411 Views
Last Modified: 2013-11-20
How do I convert a CString to a LPSTR?
CString ctmp = "Hello";
LPSTR tmp = ctmp;
The above will not compile.
0
Comment
Question by:hotwheels
3 Comments
 
LVL 1

Expert Comment

by:MT_MU
ID: 2704741
CString ctmp = "Hello";
LPSTR tmp = (char *)(const char*)ctmp;
0
 
LVL 4

Accepted Solution

by:
inpras earned 50 total points
ID: 2704804
Hi
      CString str;
      str = "My String";
      LPSTR str1;
      strcpy(str1, str);

Hope this helps
0
 
LVL 5

Expert Comment

by:vachooho
ID: 2704899
LPCTSTR is the "const char *"
LPSTR is the "char *"
fro ANSI builds
they are both fully interchangable
if you are not going to change the context (or going to if you want)

so no need to strcpy( ) it

just do casting

CString str = "string";
LPSTR lpstr = (LPSTR)(LPCTSTR)str;

will get the pointer to Cstring's buffer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question