From: ma on
Hello,
How can I convert a cstring into a constant char * correctly? I used the
following code but it is not working properly.

(const char *)FileDlg.GetPathName().GetBuffer()



what is the correct way of doing this?



Regards




From: Jonathan Wood on
One way is:

CString s;
LPCTSTR psz = s;

The following should also work:

psz = FileDlg.GetPathName();

If you still have problems, perhaps you can be a little more specific about
the problems you are having.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"ma" <ma(a)nowhere.com> wrote in message
news:%230$KaAm5GHA.3452(a)TK2MSFTNGP05.phx.gbl...
> Hello,
> How can I convert a cstring into a constant char * correctly? I used
> the following code but it is not working properly.
>
> (const char *)FileDlg.GetPathName().GetBuffer()
>
>
>
> what is the correct way of doing this?
>
>
>
> Regards
>
>
>
>


From: Ajay Kalra on
> How can I convert a cstring into a constant char * correctly? I used the
> following code but it is not working properly.
>
> (const char *)FileDlg.GetPathName().GetBuffer()
>
>
>

You can use LPCTSTR in MBCS build instead of GetBuffer/ReleaseBuffer.
For UNICODE, you can use T2A macro to do the same.

---
Ajay

From: Bogdan on
You normally do not use GetBuffer() method unless you intend to change the
string's content. Since you are trying to cast it to a (const char*) then
I'm assuming that this is not the case.

CString has a LPCTSTR conversion operator so casting the way Jonathan
described will work. If you do not want to use LPCTSTR (not sure why) then
make sure to use (const char*) or (const wchar_t*) - depending on your
compiler settings.

I suspect that your project is configured for UNICODE in which case you
should use (const wchar_t*) or simply LPCTSTR.

If you DO intend to change the content of the string then cast it to LPTSTR
(or char*/wchar_t*).


"ma" <ma(a)nowhere.com> wrote in message
news:%230$KaAm5GHA.3452(a)TK2MSFTNGP05.phx.gbl...
> Hello,
> How can I convert a cstring into a constant char * correctly? I used
> the following code but it is not working properly.
>
> (const char *)FileDlg.GetPathName().GetBuffer()
>
>
>
> what is the correct way of doing this?
>
>
>
> Regards
>
>
>
>


From: David Wilkinson on
ma wrote:

> Hello,
> How can I convert a cstring into a constant char * correctly? I used the
> following code but it is not working properly.
>
> (const char *)FileDlg.GetPathName().GetBuffer()
>
>
>
> what is the correct way of doing this?
>
>
>
> Regards
>

ma:

Before you ask this question you should be sure you understand the
issues related to CString in an ANSI or UNICODE build. If you do
understand them, then you will probably know the answer to your question.

David Wilkinson
 |  Next  |  Last
Pages: 1 2
Prev: Manifest file
Next: Custom drawn list control