About data type cast: 
Author Message
 About data type cast:

Hi,all:
 I want to convert CString type to DWORD data type.Could you help me?


Fri, 18 Feb 2005 17:07:07 GMT  
 About data type cast:
You can't make such conversions because sizeof(CString) maybe more then 4
bytes. You can convert CString* to int with
reinterpret_cast<unsigned long>(&my_string);

Quote:
> Hi,all:
>  I want to convert CString type to DWORD data type.Could you help me?



Fri, 18 Feb 2005 20:00:01 GMT  
 About data type cast:


Quote:
> reinterpret_cast<unsigned long>(&my_string);

Hi,Eugene Korobko
 Thank you in advance.
CString strID="4294820851";
DWORD dwID=reinterpret_cast<unsigned long>(&strID);
In fact, the dwID is equal to 6616440.Why?


Fri, 18 Feb 2005 20:29:21 GMT  
 About data type cast:
    Ah.. So you want a NUMBER stored in a CString converted to a DWORD.  You
didn't mention that part, and we were figuring that you want a text string
converted.

CString strID = "4294820851";
 DWORD dwID=atoi((LPCTSTR) strID);

--
Truth,
James Curran [MVP]
www.NJTheater.com     (Professional)
www.NovelTheory.com  (Personal)
MVP = Where your high-priced consultant goes for free answers


Quote:


> > reinterpret_cast<unsigned long>(&my_string);

> Hi,Eugene Korobko
>  Thank you in advance.
> CString strID="4294820851";
> DWORD dwID=reinterpret_cast<unsigned long>(&strID);
> In fact, the dwID is equal to 6616440.Why?



Fri, 18 Feb 2005 21:24:43 GMT  
 About data type cast:


Quote:
>     Ah.. So you want a NUMBER stored in a CString converted to a
>     DWORD.  You
> didn't mention that part, and we were figuring that you want a text
> string converted.

> CString strID = "4294820851";
>  DWORD dwID=atoi((LPCTSTR) strID);

> --
> Truth,
> James Curran [MVP]
> www.NJTheater.com     (Professional)
> www.NovelTheory.com  (Personal)
> MVP = Where your high-priced consultant goes for free answers





>> > reinterpret_cast<unsigned long>(&my_string);

>> Hi,Eugene Korobko
>>  Thank you in advance.
>> CString strID="4294820851";
>> DWORD dwID=reinterpret_cast<unsigned long>(&strID);
>> In fact, the dwID is equal to 6616440.Why?

Hi:
  DWORD dwID=atoi((LPCTSTR) strID);
The atoi function returns int data.Does it need convert to DWORD?
Thank you .


Fri, 18 Feb 2005 21:58:35 GMT  
 About data type cast:
try

atol((LPCTSTR) strString);

Quote:
>-----Original Message-----


>>     Ah.. So you want a NUMBER stored in a CString
converted to a
>>     DWORD.  You
>> didn't mention that part, and we were figuring that you
want a text
>> string converted.

>> CString strID = "4294820851";
>>  DWORD dwID=atoi((LPCTSTR) strID);

>> --
>> Truth,
>> James Curran [MVP]
>> www.NJTheater.com     (Professional)
>> www.NovelTheory.com  (Personal)
>> MVP = Where your high-priced consultant goes for free
answers





>>> > reinterpret_cast<unsigned long>(&my_string);

>>> Hi,Eugene Korobko
>>>  Thank you in advance.
>>> CString strID="4294820851";
>>> DWORD dwID=reinterpret_cast<unsigned long>(&strID);
>>> In fact, the dwID is equal to 6616440.Why?

>Hi:
>  DWORD dwID=atoi((LPCTSTR) strID);
>The atoi function returns int data.Does it need convert
to DWORD?
>Thank you .
>.



Fri, 18 Feb 2005 22:10:35 GMT  
 About data type cast:
This won't compile in UNICODE builds.

Also, I would recommend strtoul instead of atoi because you have more
control if the input is invalid.

CString strID = "4294820851";
LPTSTR lpszEnd = NULL;
DWORD dwID = _tcstoul(strID,&lpszEnd,10);

// check lpszEnd to see if it parsed the whole string...


Quote:
>     Ah.. So you want a NUMBER stored in a CString converted to a DWORD.
You
> didn't mention that part, and we were figuring that you want a text string
> converted.

> CString strID = "4294820851";
>  DWORD dwID=atoi((LPCTSTR) strID);

> --
> Truth,
> James Curran [MVP]
> www.NJTheater.com     (Professional)
> www.NovelTheory.com  (Personal)
> MVP = Where your high-priced consultant goes for free answers



Mon, 21 Feb 2005 01:28:33 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. type casting to / from pointers to incomplete data types

2. type casting to / from pointers to incomplete data types

3. please explain this data type pointer cast...

4. Casting a data type to a dialog box with SetDlgItemText()

5. Type Casting between Base and Derived Type (Serialization of objects with Type members)

6. ATL data type for VB Object data Type

7. SQL timestamp data type - correspondency with c++ data type

8. Mapping ADO data types with C++ data types

9. OLE data types / standard data types

10. cast cstring type to integer type

11. Casting to/from STL types to MFC types

12. Why can't overload type cast to base type (object)

 

 
Powered by phpBB® Forum Software