Get cursor position in Console

This is a discussion on Get cursor position in Console within the Windows Programming forums, part of the Platform Specific Boards category; I am using the GetConsoleScreenBufferInfo function in an attempt to get the position of the Console cursor (the text cursor, ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    38

    Question Get cursor position in Console

    I am using the GetConsoleScreenBufferInfo function in an attempt to get the position of the Console cursor (the text cursor, not the mouse cursor). The function however returns error number 12 (invalid access code). The handle to the console is being set with a GetStdHandle call which supposedly gives it generic read and write access. So what gives? Any suggestions (except to move to the GUI which isn't really an option here) are welcome.

    ________
    Rutabega

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    ERROR_INVALID_ACCESS means that the function has hit memory that doesn't belong to it. This function must be protected and doesn't crash like most WinApi functions in this situation.

    http://groups.google.com/groups?q=ER...reenBufferInfo

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    There are examples of this call in part 6 of my console tutorials here.

    I would check your use of the second parameter.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    38
    Thanks for your help, I got it to work correctly.

    It seems that the first example code I used had me declaring a PCONSOLE_SCREEN_BUFFER_INFO variable which is actually just a pointer. When I tried to pass the address of the variable to the GetScreenBufferInfo function, my compiler gave me an error. If I just passed the variable, it would compile but the function returned error number 12. So I was actually passing the function a NULL pointer since it hadn't been set to point to an actual screen buffer info structure.

    So I changed the variable type to just CONSOLE_SCREEN_BUFFER_INFO and am passing the address to the function and it works like a charm.

    Thanks again, and those are some great tutorials adrianxw.

    ________
    Rutabega

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Console, Terminal and Terminal Emulator
    By lehe in forum C Programming
    Replies: 4
    Last Post: 02-15-2009, 08:59 PM
  2. Full Screen Console
    By St0rmTroop3er in forum C++ Programming
    Replies: 1
    Last Post: 09-26-2005, 09:59 PM
  3. Problems with a simple console game
    By DZeek in forum C++ Programming
    Replies: 9
    Last Post: 03-06-2005, 01:02 PM
  4. Console Functions Help
    By Artist_of_dream in forum C++ Programming
    Replies: 9
    Last Post: 12-04-2004, 02:44 AM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 09:19 AM

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