TCHAR to int

I'm having a bit of a weird problem with this. I'm getting a key(numbers) from an edit crontrol. This comes as TCHAR, so then I convert it to an int.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//get key for decryption
if( ! GetWindowText( GetDlgItem( hWnd, ID_EDITBOX_IN_KEY ), keyTchar, App::szMessage ) )
{
	MessageBox( hWnd, L"Error getting message from\nID_EDITBOX_IN_KEY!", L"Error", MB_ICONEXCLAMATION );
	PostQuitMessage(0);
	break;
}

//convert from TCHAR to int
for( int i = 0; i < App::szKey; ++i )
{
	if( keyTchar[ i ] == NULL )
		break;

	key[ i ] = _ttoi( &keyTchar[ i ] );
}


While debugging, I've noticed that the key has been converted as follows:
Example key: 23515
key[0]: 23515
key[1]: 3515
key[2]: 515
key[3]: 15
key[4]: 5


Can someone tell me why it's converting like this, rather than individual keys?

Thanks for any help/info!
Just a wild guess here, but is your caps lock on, or num lock or any other key being held down ? Keyboard buffer is what I was thinking here and the conversion is narrowing it down.

As a I said, just a guess.
No, no keys are being held down. This is a Win32 App, so after clicking a button the code is executed.

http://s749.photobucket.com/albums/xx132/Bigdave876/Cpp/?action=view&current=me.jpg

The highlighted text is the only part that gets decrypted, as the keys are wrong until the last key is only 1 digit long.
I believe that since _ttoi take a tchar string &keyTchar[i] is passing the start of substrings. Just use int key = _ttoi(keyTchar) then use division and modulus to get individual digits if you need them.
Thanks. I was hoping for a simple fix, lol.

Either way, here's my code, in case someone needs something similar:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
	//create a key( digit ) counter
	int keyCount = 0;

	//convert from TCHAR to int
	for( int i = 0; i < App::szKey; ++i )
	{
		if( keyTchar[ i ] == NULL )
			break;

		key[ i ] = _ttoi( &keyTchar[ i ] );

		++keyCount;
	}

	//create an index counter
	int index = keyCount;

	////////Break the key in to single digits/////////
	for( int i = 0; i < index; ++i )
	{
		for( int j = 0; j < ( keyCount - 1 ); ++j )
			key[ i ] /= 10;

		--keyCount;
	}
	////////////////////////////////////////////////// 


why not use a native function like GetDlgItemInt()?
I didn't know that existed until now, lol.

I've only been teaching myself Win32 API for the last few days. So thanks!
Topic archived. No new replies allowed.