By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

Dangerous Convertion?

P: n/a
Hi,
I want to convert CString to LPBYTE like
LPBYTE lpByte = (BYTE*)(LPCTSTR)cstring;
is it very dangerous to do that?
Jun 27 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Th*******@autodesk.com wrote:
Hi,
I want to convert CString to LPBYTE like
LPBYTE lpByte = (BYTE*)(LPCTSTR)cstring;
is it very dangerous to do that?
Depends. What's BYTE, LPBYTE, LPCTSTR, and CString?

Ask in an MS newsgroup.

That said, in general, you should avoid C-style casts in favor of the
new casts (static_cast, reinterpret_cast, dynamic_cast, const_cast).
Furthermore, yes, you have a very dangerous conversion, you're casting
away a const.
Jun 27 '08 #2

P: n/a
Th*******@autodesk.com wrote:
I want to convert CString to LPBYTE like
LPBYTE lpByte = (BYTE*)(LPCTSTR)cstring;
is it very dangerous to do that?
Yes, very dangerous. If you set a wrong bit there, your computer is
gonna blow up and flatten the house.

S,CNR

Lars
Jun 27 '08 #3

P: n/a
Thanks for help:)
Jun 27 '08 #4

P: n/a
On 5月30日, 下午2时48分, red floyd <no.spam.h...@example.comwrote:
Thomas...@autodesk.com wrote:
Hi,
I want to convert CString to LPBYTE like
LPBYTE lpByte = (BYTE*)(LPCTSTR)cstring;
is it very dangerous to do that?

Depends. What's BYTE, LPBYTE, LPCTSTR, and CString?

Ask in an MS newsgroup.

That said, in general, you should avoid C-style casts in favor of the
new casts (static_cast, reinterpret_cast, dynamic_cast, const_cast).
Furthermore, yes, you have a very dangerous conversion, you're casting
away a const.
Thanks for reminding, how about using GetBuffer(0) to return the
pointer
which allows me to modify. If it's correct, one more question: if the
_unicode
is turned on then GetBuffer() would return wchar_t*, then convert it
to
BYTE* is it also dangerous?
Jun 27 '08 #5

P: n/a
On 30 Mai, 08:48, red floyd <no.spam.h...@example.comwrote:
Thomas...@autodesk.com wrote:
Hi,
I want to convert CString to LPBYTE like
*LPBYTE lpByte = (BYTE*)(LPCTSTR)cstring;
is it very dangerous to do that?

Depends. *What's BYTE, LPBYTE, LPCTSTR, and CString?
[snip]
Furthermore, yes, you have a very dangerous conversion, you're casting
away a const.
@red floyd:
Hah, you have outsmarted yourself: If you don't know what LPBYTE and
LPCTSTR mean, how come that you know that OP casts away constness?

@Thomas:
It really depends (so it should be avoided). Remember that LPCTSTR may
be either a UNICODE string or a ASCII string, so that cast may do what
you want or not. Casting away the constness is also bad. Consider the
T2CA macro from atlconv.h (MS specific).

Regards,
Stuart
Jun 27 '08 #6

P: n/a
On May 30, 3:04 am, dertop...@web.de wrote:
On 30 Mai, 08:48, red floyd <no.spam.h...@example.comwrote:
Thomas...@autodesk.com wrote:
Hi,
I want to convert CString to LPBYTE like
LPBYTE lpByte = (BYTE*)(LPCTSTR)cstring;
is it very dangerous to do that?
Depends. What's BYTE, LPBYTE, LPCTSTR, and CString?
[snip]
Furthermore, yes, you have a very dangerous conversion, you're casting
away a const.

@red floyd:
Hah, you have outsmarted yourself: If you don't know what LPBYTE and
LPCTSTR mean, how come that you know that OP casts away constness?
I know damn well what they are. However, they are not defined by ISO/
IEC 14882:2003 (the C++ Standard) and they are therefore off-topic
here.
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.