Solved

CString and PSTR

Posted on 2000-03-18
7
584 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

 

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

Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

630 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