tags:

views:

292

answers:

2

Is there in Windows API or in MFC any analog to atoh() function?

atoh() converts a string containing a hexadecimal number into an unsigned number like

unsigned x = atoh("A");

and x = 10 after the operation.

In Windows I have a CString, containing "A". How can I convert it to int?

+2  A: 

unsigned long ten = strtoul("a", NULL, 16); should handle it, if you can get a plain old char *-representation out of the CString. The accepted solution using strtoul() does a signed conversion.

unwind
For compatibility with CString, which can be either based on char or wchar_t, #include <tchar.h> and use _tcstoul.
ChrisN
+5  A: 
long x = strtoul("A", (char **) NULL, 16);
// x will be 10 decimal
divideandconquer.se
This is signed, not unsigned. Sigh. I'm getting petty in the hunt for rep points. :|
unwind
@unwind, that's true... just change it to strtoul for him :)
Jason Coco