I have an IDC_Edit text box set which will accept hexadecimal space-separated values that I'm wanting to convert into a WORD. I'm wanting the control to mimic the array, but I'm really unsure how to complete the conversion.
Basically, if I input:
"12 AB"
I need the resulting WORD to equal:
0x12AB
As someone who rarely dabbles with C++, let alone the WinAPI, I'm really stumped as to how to do this. My current code is:
HWND hTextInput = GetDlgItem(hWnd, IDC_EDIT);
DWORD dwInputLength = Edit_GetTextLength(hTextInput);
char* resultString = new char[dwInputLength+1];
memset(hTextInput , 0, dwInputLength+1);
WORD result = (resultString[0] << 8) | resultString[1];
This pulls the IDC_EDIT
control's text and length and turns it into a char*
array. This then attempts to convert into a WORD, but obviously this only currently takes the first two characters (12
) in this case.
How can I make this pull "12 AB"
into the char*
array as [0x12, 0xAB]
(rather than ["1", "2", "A", "B"]
) so that I can then shift the two bytes into a WORD?