[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 615
  • Last Modified:

CString and PSTR

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
javigil1
Asked:
javigil1
1 Solution
 
tullheadCommented:
Try:

m_Name.GetBuffer(0);



0
 
WynCommented:
Use it directly.
0
 
javigil1Author Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
tullheadCommented:
So if .GetBuffer(0) works fine, why did
you reject my answer?
0
 
javigil1Author Commented:
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
 
happylinCommented:
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
 
tullheadCommented:
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now