• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2958
  • Last Modified:

Cast from DWORD to string

A beginer questin:
How do I cast a from Dword to string ?
Thank's

AA
0
arnonayal
Asked:
arnonayal
  • 2
  • 2
1 Solution
 
tvanceplusCommented:
Here is some code that could do it.

/*code  myword already contains desired value*/

__int64 temp;
temp=myword;
char buffer[50];

_i64toa(temp,buffer,10);

CString str=buffer;

/*end code*/

Good Luck!
0
 
nietodCommented:
A DWORD is 32 bits, not 64, so you could use _itoa(), not __i64toa().  (Although i64toa() would work, its overkill.).

However this is not a portable solution--if that matters.  A portable solution would be to use sprintf() or to output the information to a string stream object and then obtain the string from the string stream object.
0
 
tvanceplusCommented:
It could be overkill. I was not sure whether or not the fact that DWORD was an unsigned value would cause overflow for the integer conversion function parameter.
0
 
nietodCommented:
Good point.  if the DWORD is outside of the signed int range you would need to use i64toa().
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now