GetWindowTextLength

This is a discussion on GetWindowTextLength within the Windows Programming forums, part of the Platform Specific Boards category; I cant see what im doing wrong. Neither GetWindowTextLength(hwnd) nor GetWindowText(hwnd, buf2, length) returning anything. Code: #include <windows.h> #include <iostream> ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    812

    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;
    }
    Compiler MSVC++ 2013 with Code::Blocks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Do you have test code where your hwnd points to a window?

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    812
    Well i thought it pointed by default to the window of the program.

    Isnt it the case?
    Compiler MSVC++ 2013 with Code::Blocks.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well, no. It's just an uninitialized variable.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    812
    Ok, thank you Tabstop!

    So i have to find out how to point it somewhere.
    Compiler MSVC++ 2013 with Code::Blocks.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Since you're using main and not WinMain, perhaps you want to look here: How To Obtain a Console Window Handle &#40;HWND&#41;

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    812
    Great! Thanks a lot!
    Compiler MSVC++ 2013 with Code::Blocks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetWindowTextLength() = crash ?
    By willc0de4food in forum Windows Programming
    Replies: 2
    Last Post: 07-04-2005, 12:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21