473,581 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
+ 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 3568
Th*******@autod esk.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_cas t, dynamic_cast, const_cast).
Furthermore, yes, you have a very dangerous conversion, you're casting
away a const.
Jun 27 '08 #2
Th*******@autod esk.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...@e xample.comwrote :
Thomas...@autod esk.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_cas t, 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...@e xample.comwrote :
Thomas...@autod esk.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.d e wrote:
On 30 Mai, 08:48, red floyd <no.spam.h...@e xample.comwrote :
Thomas...@autod esk.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
2178
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 (e.g. background color). my datatest is removed. I compared it with diff program and it reorganized all source code.
0
1393
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
2231
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 a function that I can call to "as required by comparison functions" to convert any value to a mm value so that when I'm comparing Distance objects...
1
1619
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"?> <!-- For convertion from UTF-8 to ISO-8859-1 CaracterSet --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
0
324
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 help.... int b = -1; uint a,c = 0; Encoding encodingAscii = Encoding.GetEncoding(1250);
4
2092
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); // value="11/02/2004" al.Add(temp_str); // value="10:53:10" temp_str2=(string)al.ToArray(typeof(string));
8
3177
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); } string exc_string = (string)al.ToArray(typeof(string));
0
1415
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 converti le php en asp avec la moulinette windows http://81.56.65.81 J'y connais rien mais la bibliotheque de lecture du fichier d'echange (fichier.ini)...
233
8538
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 there is no problem but when I try to compile it with a linux compiler it complains that a_03.c:(.text+0x4d): warning: the `gets' function is...
0
7862
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7789
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8301
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8169
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5670
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5361
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2300
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 we have to send another system
1
1400
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.