Solved

CString and PSTR

Posted on 2000-03-18
7
576 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
ID: 2631959
Try:

m_Name.GetBuffer(0);



0
 
LVL 5

Expert Comment

by:Wyn
ID: 2632601
Use it directly.
0
 

Author Comment

by:javigil1
ID: 2633929
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

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

Author Comment

by:javigil1
ID: 2634261
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
ID: 2634598
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
ID: 2634793
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 67
ORA-01403: no data found 43 112
centeredAverage challenge 8 186
Modbus - whats the maximum I can store in one register? 4 82
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

726 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