I'm trying to take a value from an edit box and display it in the edit box as hex. I'm using this code:

CString buffer;
int intbuf;
intbuf = atoi(buffer);
buffer.Format("%02X", intbuf);

If I include the last line of code here I get a stack overflow error. If I don't include it, I can run through the debugger and the buffer CString is converted to hex just like I want, I just can't display it because I get that error. Any help is appreciated as to why I get the error. Thanks for the help!!!