I seem to be misunderstanding the GetWindowText function. I though you are supposed to pass a buffer where the function can write the title, so that means that the buffer has to be (in UNICODE):
(size of the title) * 2 + 2
multiply by 2 because each UNICODE character is 2 bytes wide, and + 2 for the zero terminating sign.
Am I right so far?
But how in the world does this work?
Also after im done using the pointer to the title do I just call GlobalFree() to free the space?
LPWSTR lp = (LPWSTR)GlobalAlloc(GPTR, 1);
GetWindowText(hwnd, lp, GetWindowTextLength(hwnd)+1);
MessageBox(NULL, lp, lp, 0);