Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GetWindowTextA() function not working in Visual Studio 2005?

GetWindowTextA() function not working in Visual Studio 2005?

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studioquestion
7 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amarelia
    wrote on last edited by
    #1

    Hi I am using Visual Studio 2005. I have developed my project in VC++ which is a dialog based MFC application. Here on the Button Click event of one dialog i need to get the value inserted in one edit box. for that I have declared variable also and i use GetWindowTextA() functions for that and it throw assertions. Showsing NULL value in hWnd... I don't know why this happens........any idea? The same code works fine in Visual Studio 6.0 My Code looks like this : ========================= void CPswdWnd::OnBnClickedButton1() { // TODO: Add your control notification handler code here char sCurPswd[512]=""; m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion } My Variables are declared by righ clicking the Editbox and then "Add Variables" and then i have made the variable as "Control". Any idea? Thankx in advance Mahesh

    R J D 3 Replies Last reply
    0
    • A Amarelia

      Hi I am using Visual Studio 2005. I have developed my project in VC++ which is a dialog based MFC application. Here on the Button Click event of one dialog i need to get the value inserted in one edit box. for that I have declared variable also and i use GetWindowTextA() functions for that and it throw assertions. Showsing NULL value in hWnd... I don't know why this happens........any idea? The same code works fine in Visual Studio 6.0 My Code looks like this : ========================= void CPswdWnd::OnBnClickedButton1() { // TODO: Add your control notification handler code here char sCurPswd[512]=""; m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion } My Variables are declared by righ clicking the Editbox and then "Add Variables" and then i have made the variable as "Control". Any idea? Thankx in advance Mahesh

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      void CPswdWnd::OnBnClickedButton1()
      {
      // TODO: Add your control notification handler code here
      char sCurPswd[512]="";
      m_Pswd.GetWindowText(sCurPswd,strlen(sCurPswd)); //Here it give assertion

      }

      Without "A" at the end. The compiler decides then which one fits best. ~RaGE();

      J 1 Reply Last reply
      0
      • A Amarelia

        Hi I am using Visual Studio 2005. I have developed my project in VC++ which is a dialog based MFC application. Here on the Button Click event of one dialog i need to get the value inserted in one edit box. for that I have declared variable also and i use GetWindowTextA() functions for that and it throw assertions. Showsing NULL value in hWnd... I don't know why this happens........any idea? The same code works fine in Visual Studio 6.0 My Code looks like this : ========================= void CPswdWnd::OnBnClickedButton1() { // TODO: Add your control notification handler code here char sCurPswd[512]=""; m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion } My Variables are declared by righ clicking the Editbox and then "Add Variables" and then i have made the variable as "Control". Any idea? Thankx in advance Mahesh

        J Offline
        J Offline
        James R Twine
        wrote on last edited by
        #3

        It is likely ASSERTing because the you are passing the return from strlen(...) as the length of the buffer.  These are two different things.    You should be calling the function like: m_Pswd.GetWindowTextA(sCurPswd,512).    Peace!    ---   Modified at 10:34 Tuesday 14th February, 2006    Actually, the second parameter is the max number of characters to copy into the buffer.  This is important, because it does not mean the size of the buffer.  That is why using sizeof(...) as was also suggested would be incorrect in a UNICODE build. -=- James


        If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        DeleteFXPFiles & CheckFavorites (Please rate this post!) -- modified at 10:34 Tuesday 14th February, 2006    Actually, the second parameter is the max number of characters to copy into the buffer.  This is important, because it does not mean the size of the buffer.  That is why using sizeof(...) as was also suggested would be incorrect in a UNICODE build.

        1 Reply Last reply
        0
        • A Amarelia

          Hi I am using Visual Studio 2005. I have developed my project in VC++ which is a dialog based MFC application. Here on the Button Click event of one dialog i need to get the value inserted in one edit box. for that I have declared variable also and i use GetWindowTextA() functions for that and it throw assertions. Showsing NULL value in hWnd... I don't know why this happens........any idea? The same code works fine in Visual Studio 6.0 My Code looks like this : ========================= void CPswdWnd::OnBnClickedButton1() { // TODO: Add your control notification handler code here char sCurPswd[512]=""; m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion } My Variables are declared by righ clicking the Editbox and then "Add Variables" and then i have made the variable as "Control". Any idea? Thankx in advance Mahesh

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Amarelia wrote:

          m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion

          Use sizeof(sCurPswd)*sizeof(TCHAR) instead of strlen(sCurPswd).


          "The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli

          T 1 Reply Last reply
          0
          • R Rage

            void CPswdWnd::OnBnClickedButton1()
            {
            // TODO: Add your control notification handler code here
            char sCurPswd[512]="";
            m_Pswd.GetWindowText(sCurPswd,strlen(sCurPswd)); //Here it give assertion

            }

            Without "A" at the end. The compiler decides then which one fits best. ~RaGE();

            J Offline
            J Offline
            James R Twine
            wrote on last edited by
            #5

            Since the buffer the O.P. allocated is a char buffer, they need to be using it with the ANSI version of the function.  If their app is a UNICODE build, GetWindowText(...) will resolve to GetWindowTextW(...), and will not accept the char buffer.    Identifiers like GetWindowText that are #defined to different functions (the A or W versions) depending on the build type should only be expected to work correctly under different build types when using TCHAR as the character type.    Peace! -=- James


            If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
            Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            DeleteFXPFiles & CheckFavorites (Please rate this post!)

            1 Reply Last reply
            0
            • D David Crow

              Amarelia wrote:

              m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion

              Use sizeof(sCurPswd)*sizeof(TCHAR) instead of strlen(sCurPswd).


              "The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              DavidCrow wrote:

              Use sizeof()*sizeof(TCHAR) instead of strlen().

              Sorry you bug you Sir, Couldn't we use lstrlen for same?

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta VC Forum Q&A :- I/ IV

              D 1 Reply Last reply
              0
              • T ThatsAlok

                DavidCrow wrote:

                Use sizeof()*sizeof(TCHAR) instead of strlen().

                Sorry you bug you Sir, Couldn't we use lstrlen for same?

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                cheers, Alok Gupta VC Forum Q&A :- I/ IV

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                ThatsAlok wrote:

                Couldn't we use lstrlen for same?

                Sure you can use it, but it'll still return 0 just like strlen().


                "The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups