Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

DWORDs are unsigned. so 424967162 is (DWORD)(int)(-134)

see also: Two's Complement[^]
 
Share this answer
 
ClientHandle is of type DWORD which is an unsigned number. Just use an int as returned from atoi().
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900