Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
CString sHandle;
DWORD ClientHandle;
 
sHandle = _T("134");
CStringA pszCharacterString (sHandle);
ClientHandle = atoi(pszCharacterString); //client handle is 134
 
This is working fine. But for this:
 
CString sHandle;
DWORD ClientHandle;
 
sHandle = _T("-134"); //a negative sign at front
CStringA pszCharacterString (sHandle);
ClientHandle = atoi(pszCharacterString); //this fails, client handle is 424967162
 

How do i implement it for CString _T("-134") to convert to DWord
Posted 3-Apr-12 7:58am
amarasat1.3K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

DWORDs are unsigned. so 424967162 is (DWORD)(int)(-134)
 
see also: Two's Complement[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

ClientHandle is of type DWORD which is an unsigned number. Just use an int as returned from atoi().
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 380
1 CPallini 375
2 BillWoodruff 314
3 George Jonsson 279
4 OriginalGriff 227
0 OriginalGriff 5,030
1 CPallini 4,225
2 Sergey Alexandrovich Kryukov 3,604
3 George Jonsson 2,831
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 3 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100