Click here to Skip to main content
12,356,154 members (71,477 online)
Rate this:
 
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.4K
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 3 Apr 2012
Copyright © CodeProject, 1999-2016
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