Solved

CString and PSTR

Posted on 2000-03-18
7
560 Views
Last Modified: 2013-11-20
How can I convert from CString to PSTR?
I mean, I have an identifier m_Name which is a CString object. Actually, m_Name ist just a text input.
I want to pass it as a parameter to a method requiring PSTR parameters. What can I do??

Help:
PSTR
Pointer to a null-terminated Windows character string
CSTRING
CString object consists of a variable-length sequence of characters.
0
Comment
Question by:javigil1
7 Comments
 

Expert Comment

by:tullhead
Comment Utility
Try:

m_Name.GetBuffer(0);



0
 
LVL 5

Expert Comment

by:Wyn
Comment Utility
Use it directly.
0
 

Author Comment

by:javigil1
Comment Utility
Doesn't work (directly)!!

My code is:

PSTR text=m_Name;
(m_Name is a CString member variable)

When trying to compile, I always get this error:

error C440: 'initializing' : cannot convert from 'class CString' to 'char *'


The .GetBuffer(0) seems to work fine though.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Expert Comment

by:tullhead
Comment Utility
So if .GetBuffer(0) works fine, why did
you reject my answer?
0
 

Author Comment

by:javigil1
Comment Utility
Did I??
Sorry, Im new here, and maybe I made something wrong. I thought I hadn't rejected your answered, but rated it with A, cause it exactly what I needed. What can I do now? If you post it again I will rate it.
Sorry again.
0
 

Accepted Solution

by:
happylin earned 75 total points
Comment Utility
please try
PSTR text=(PSTR)(LPCTSTR)m_Name;

but u can't modify text

if u want modify text please use .GetBuffer(0). After modify u must call m_Name.ReleaseBuffer()
0
 

Expert Comment

by:tullhead
Comment Utility
hmmm....  I'm kinda new here too.  I think at this point, if you want to give me the points, then you have to reject happylin's answer, and then I'll post an "answer" which you can award.

On the other hand, its no big deal...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now