[RESOLVED] Converting DWORD to CString
I have a DWORD variable and want to convert to a CString.
Likewise, I would like to convert a CString to a DWORD.
I know how to do it for other variables using functions like
[code]
number = atoi(str); //string to number
str.Format("%d", number); //number to string
[/ccode]
I would appreciate any suggestions and example code.
Re: Converting DWORD to CString
Try this.
CString MyString;
DWORD SomeNum;
MyString.Format ("%d", SomeNum);
Lee
Re: Converting DWORD to CString
surely %d is a normal interger, not a DWORD?
And what about string to DWORD?
Re: Converting DWORD to CString
Sorry, you should use "%u" instead of "%d" since "%u" is for unsigned ints (which is a DWORD). As far as converting from DWORD to string, I do not know of any unsigned int versions of atoi().
Lee
Re: Converting DWORD to CString
Yes - %u
And I thought about it - I could use sscanf to convert from string to DWORD:
[code]
DWORD var;
CString MyStr = "1234";
sscanf(MyStr, "%u", &var);
[/ccode]
I think that would work ok.
Re: Converting DWORD to CString
Actually, there is a function called strtoul, which converts strings to unsigned longs.
unsigned long strtoul( const char *nptr, char **endptr, int base );
Lee