473,473 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dangerous Convertion?

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
6 3549
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
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
Thanks for help:)
Jun 27 '08 #4
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Petr Studenovsky | last post by:
Hello I made small GUI test program in Visual Basic NET for SQL communication. I need some help with these problems. problem 1) If I change some settings in datagrid from properties window...
0
by: Konstantin Kivi | last post by:
I have problems getting character set convertion to work in 4.1.4 gamma under linux. Can sombody point me to the online recource other than standard MySQL doc so that I get more information.
6
by: Chiller | last post by:
I'm in the process of writing a class that performs functions on a Distance object. The object is created by entering details as "Distance a (5, km)" or "Distance b (3, cm)" etc. I wish to write...
1
by: Vidar | last post by:
I have a problem in dotNET XSL convertion object. (XMLTRANSFORM) It won't convert UTF-8 to ISO-8859-1 I use this stylesheet for konvertion: <?xml version="1.0" encoding="ISO-8859-1"?> <!--...
0
by: McKoy | last post by:
Hi, I'm translating some code from C++ to C#, but I don't know how to change the code below to get it working under C# ...., I've tried explicity convertion, but without any results :( Please...
4
by: juli | last post by:
Good afternoon! I have an error while trying to convert to DateTime ,here is the code and the error: ArrayList al = new ArrayList(); temp_str=Line.Split(' '); al.Add(temp_str); //...
8
by: juli | last post by:
I am trying to convert an object of a class which is derived from collectionbase class.It's not working: while ((line = file.ReadLine()) != null && line.IndexOf(" ")!=-1) { al.Add(line); }...
0
by: isore | last post by:
Convertion php to asp.net : PB lecture fichier .ini URGENT URGENT URGENT URGENT URGENT URGENT J'ai un code en php (http://parisports.free.fr) mais le client veut le même en asp.net J'ai...
233
by: Julian | last post by:
'evening. I'm not new to C and have been programming in it since I was 8 but here's a strange problem I've never seen before. When I compile a program from our C course with a windows compiler...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.