Thread: GetWindowText() not working with Vista???

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    230

    GetWindowText() not working with Vista???

    Hi,
    I've been using the function GetWindowText() for a while now on Windows XP. When I upgraded to Vista Ultimate 64-bit, I started getting different output from the function. Instead of saving all the text, it only saves the first character.

    After hours of trial and error, I decided to try the same code I was using under Vista (and was compiled using VC++ 2008) on Windows XP again, and it worked fine!

    Has anyone heard of such a problem or how to fix it?
    I might not be a pro, but I'm usually right

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I don't know... ansi/unicode issues?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Have you tried compiling under 64-bit Vista?
    Mainframe assembler programmer by trade. C coder when I can.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    yes. I'm compiling using MSVC++ 2008 on Vista. I installed it off the DVD and made sure it installed all the required 64-bit features. But I'm not sure I'm compiling FOR 64-bit, because my profile is still Debug (Win32)...
    I might not be a pro, but I'm usually right

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    32- or 64-bit shouldn't make any difference, but if you are reading back a Unicode string where you expect to get a ANSI string, then you will get the first character (because european/ASCII characters are using the first 256 characters, so the second half of a 16-bit character is '\0' when read as two 8-bit characters).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    Yes I think that is the problem. When I put the mouse on the function in MSVC++ 2008, I get the following popup under the mouse:
    Code:
    #define GetWindowText GetWindowTextW
    so do I just need to remove - or disable - that definition???
    I might not be a pro, but I'm usually right

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    If you want to disable unicode and use ANSI throughout your program, put some #undef UNICODE or something before including other headers.

    If you only want to use that function as ANSI then simply call GetWindowTextA().
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    Worked with #undef UNICODE

    EDIT: sorry for the double post...
    I might not be a pro, but I'm usually right

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    Worked with #undef UNICODE
    Thanks
    I might not be a pro, but I'm usually right

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by maxorator View Post
    If you want to disable unicode and use ANSI throughout your program, put some #undef UNICODE or something before including other headers.

    If you only want to use that function as ANSI then simply call GetWindowTextA().
    That's more like a hack. What you really want is to go into project settings and set character set to multi-byte.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    Fixed it up. Thanks Elysia
    I might not be a pro, but I'm usually right

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. corruption, decay, Vista Gateway laptop
    By CodeMonkey in forum Tech Board
    Replies: 5
    Last Post: 06-13-2009, 01:50 PM
  2. Newbee Q: reg. MFC dlg button & Vista UAC shield icon
    By colbyringeisen in forum Windows Programming
    Replies: 3
    Last Post: 12-29-2008, 05:16 PM
  3. get "application data" directory in xp, vista
    By sgh in forum Windows Programming
    Replies: 8
    Last Post: 05-12-2008, 02:48 AM
  4. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 08:08 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM