-
GetWindowTextLength
I cant see what im doing wrong.
Neither GetWindowTextLength(hwnd) nor GetWindowText(hwnd, buf2, length)
returning anything.
Code:
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
HWND hwnd;
char *buf2;
int length;
length=GetWindowTextLength(hwnd);
buf2 = new TCHAR[length+1];
int nChars = GetWindowText(hwnd, buf2, length);
cout << "Windowtext: " << buf2 << "\n";
cout << length << " characters.\n";
delete[] buf2;
return 0;
}
-
Do you have test code where your hwnd points to a window?
-
Well i thought it pointed by default to the window of the program.
Isnt it the case?
-
Well, no. It's just an uninitialized variable.
-
Ok, thank you Tabstop!
So i have to find out how to point it somewhere.
-
Since you're using main and not WinMain, perhaps you want to look here: How To Obtain a Console Window Handle (HWND)
-