Solved

CString and PSTR

Posted on 2000-03-18
7
566 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 85
conditional code and condition difference 9 77
Use of condition with 'serial' in ansible 2 49
changeXy challenge 13 67
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

920 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

14 Experts available now in Live!

Get 1:1 Help Now