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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SCI_GETTEXT - Scintilla, how do I get the text ?

SCI_GETTEXT - Scintilla, how do I get the text ?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondebugginghelp
11 Posts 4 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.
  • G Offline
    G Offline
    gabbana
    wrote on last edited by
    #1

    Hi, I am wondering how I can get the text from an scintilla text control ? This is my code, but the debugger says that data has a bad pointer and I have no text in it.

                        TCHAR \*data;
    		UINT nLength;
    		nLength = SendMessage(hWndEditor,SCI\_GETLENGTH,0,0);
    
    		// allocate buffer;
    
    		memset(&data,0,sizeof(TCHAR)\*nLength+1);
    
    		// get the data
    
    		data = (TCHAR\*)SendMessage(hWndEditor, SCI\_GETTEXT,nLength+1,0);
    
    		// show the data
    
    		MessageBox(NULL,data,L"MyApp",0);
    
    		// clear the buffer
    		free(data);
    

    Thanks for help. bye, gabbana

    CPalliniC 1 Reply Last reply
    0
    • G gabbana

      Hi, I am wondering how I can get the text from an scintilla text control ? This is my code, but the debugger says that data has a bad pointer and I have no text in it.

                          TCHAR \*data;
      		UINT nLength;
      		nLength = SendMessage(hWndEditor,SCI\_GETLENGTH,0,0);
      
      		// allocate buffer;
      
      		memset(&data,0,sizeof(TCHAR)\*nLength+1);
      
      		// get the data
      
      		data = (TCHAR\*)SendMessage(hWndEditor, SCI\_GETTEXT,nLength+1,0);
      
      		// show the data
      
      		MessageBox(NULL,data,L"MyApp",0);
      
      		// clear the buffer
      		free(data);
      

      Thanks for help. bye, gabbana

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      gabbana wrote:

      data = (TCHAR*)SendMessage(hWndEditor, SCI_GETTEXT,nLength+1,0);

      shouldn't that be

      nLength = SendMessage(hWndEditor, SCI_GETTEXT,nLength+1, (LPARAM)data);

      ? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      modified on Sunday, October 26, 2008 2:41 PM

      In testa che avete, signor di Ceprano?

      G 1 Reply Last reply
      0
      • CPalliniC CPallini

        gabbana wrote:

        data = (TCHAR*)SendMessage(hWndEditor, SCI_GETTEXT,nLength+1,0);

        shouldn't that be

        nLength = SendMessage(hWndEditor, SCI_GETTEXT,nLength+1, (LPARAM)data);

        ? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        modified on Sunday, October 26, 2008 2:41 PM

        G Offline
        G Offline
        gabbana
        wrote on last edited by
        #3

        Hmm, I get an error: cannot convert from TCHAR* to UINT And the last parameter i needed to cast (LPARAM)data.

        CPalliniC 1 Reply Last reply
        0
        • G gabbana

          Hmm, I get an error: cannot convert from TCHAR* to UINT And the last parameter i needed to cast (LPARAM)data.

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          In fact I forgot a cast. I fixed (there also was a wrong cast,by cut 'n' paste, actually) my previous reply, please see it again. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          G 1 Reply Last reply
          0
          • CPalliniC CPallini

            In fact I forgot a cast. I fixed (there also was a wrong cast,by cut 'n' paste, actually) my previous reply, please see it again. :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            G Offline
            G Offline
            gabbana
            wrote on last edited by
            #5

            Okay, but without luck. Iam not sure what the error exactly is, but if I have a breakpoint at the last SendMessage and look in the Debugger &data have a value of 0x00... and Bad Ptr And the MessageBox is empty. The code looks like this:

            		UINT length = SendMessage(hWndEditor, SCI\_GETLENGTH, 0, 0);
            		TCHAR \*data;
            		memset(&data, 0, sizeof(TCHAR)\*length+1);
            		length = SendMessage(hWndEditor, SCI\_GETTEXT,length+1,(LPARAM)data);
            		MessageBox(NULL,data,L"Test",0);
            		free(data);
            

            At the end of the function I also get this error: Stack around the variable 'data' was corrupted

            modified on Sunday, October 26, 2008 11:16 PM

            S 1 Reply Last reply
            0
            • G gabbana

              Okay, but without luck. Iam not sure what the error exactly is, but if I have a breakpoint at the last SendMessage and look in the Debugger &data have a value of 0x00... and Bad Ptr And the MessageBox is empty. The code looks like this:

              		UINT length = SendMessage(hWndEditor, SCI\_GETLENGTH, 0, 0);
              		TCHAR \*data;
              		memset(&data, 0, sizeof(TCHAR)\*length+1);
              		length = SendMessage(hWndEditor, SCI\_GETTEXT,length+1,(LPARAM)data);
              		MessageBox(NULL,data,L"Test",0);
              		free(data);
              

              At the end of the function I also get this error: Stack around the variable 'data' was corrupted

              modified on Sunday, October 26, 2008 11:16 PM

              S Offline
              S Offline
              SandipG
              wrote on last edited by
              #6

              gabbana wrote:

              TCHAR *data; memset(&data, 0, sizeof(TCHAR)*length+1);

              I think before memset you should allocate memory for data. You can insert following statement before memset.

              data = new TCHAR[length+1];

              I hope it helps.

              Regards, Sandip.

              G 1 Reply Last reply
              0
              • S SandipG

                gabbana wrote:

                TCHAR *data; memset(&data, 0, sizeof(TCHAR)*length+1);

                I think before memset you should allocate memory for data. You can insert following statement before memset.

                data = new TCHAR[length+1];

                I hope it helps.

                Regards, Sandip.

                G Offline
                G Offline
                gabbana
                wrote on last edited by
                #7

                I get the same error. What I found now is, that if i only allocate memory with your code and removing the memset and free functions I get no error, but the MessageBox and the gives me some crazy char like chinese. (I think I should mention that I use UNICODE)

                S 1 Reply Last reply
                0
                • G gabbana

                  I get the same error. What I found now is, that if i only allocate memory with your code and removing the memset and free functions I get no error, but the MessageBox and the gives me some crazy char like chinese. (I think I should mention that I use UNICODE)

                  S Offline
                  S Offline
                  SandipG
                  wrote on last edited by
                  #8

                  one thing i missed do not use free when you are allocating memory with new. use delete instead of free.

                  gabbana wrote:

                  (I think I should mention that I use UNICODE)

                  Have you set the corresponding properties for using unicode. In the documentation i see following messages. SCI_SETKEYSUNICODE(bool keysUnicode) SCI_GETKEYSUNICODE You can try setting keysUnicode to TRUE in message SCI_SETKEYSUNICODE I hope it helps.

                  Regards, Sandip.

                  modified on Monday, October 27, 2008 4:48 AM

                  G 1 Reply Last reply
                  0
                  • S SandipG

                    one thing i missed do not use free when you are allocating memory with new. use delete instead of free.

                    gabbana wrote:

                    (I think I should mention that I use UNICODE)

                    Have you set the corresponding properties for using unicode. In the documentation i see following messages. SCI_SETKEYSUNICODE(bool keysUnicode) SCI_GETKEYSUNICODE You can try setting keysUnicode to TRUE in message SCI_SETKEYSUNICODE I hope it helps.

                    Regards, Sandip.

                    modified on Monday, October 27, 2008 4:48 AM

                    G Offline
                    G Offline
                    gabbana
                    wrote on last edited by
                    #9

                    Okay, now I am using delete. The stack corrupted message already exists. The error must be the memset, because if i delete that line I am not getting an error. The problem with the chinse chars already exists! hWndEditor is the handle to sintilla text control. I declared it in my header file HWND hWndEditor and created the control in the WM_CREATE message:

                    hWndEditor = CreateWindowEx(0,
                    _T("Scintilla"),
                    _T(""),
                    WS_CHILD | WS_VISIBLE,
                    0,
                    0,
                    500,
                    500,
                    hWnd,
                    (HMENU)1,
                    (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
                    NULL);

                    EDIT: Yes i send the following message in WM_CREATE after the control is created: SendMessage(hWndEditor, SCI_SETKEYSUNICODE, true, 0);

                    G 1 Reply Last reply
                    0
                    • G gabbana

                      Okay, now I am using delete. The stack corrupted message already exists. The error must be the memset, because if i delete that line I am not getting an error. The problem with the chinse chars already exists! hWndEditor is the handle to sintilla text control. I declared it in my header file HWND hWndEditor and created the control in the WM_CREATE message:

                      hWndEditor = CreateWindowEx(0,
                      _T("Scintilla"),
                      _T(""),
                      WS_CHILD | WS_VISIBLE,
                      0,
                      0,
                      500,
                      500,
                      hWnd,
                      (HMENU)1,
                      (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
                      NULL);

                      EDIT: Yes i send the following message in WM_CREATE after the control is created: SendMessage(hWndEditor, SCI_SETKEYSUNICODE, true, 0);

                      G Offline
                      G Offline
                      gabbana
                      wrote on last edited by
                      #10

                      Does nobody has an idea how to fix the problem ? By the way: Is Scintilla a good choice, or would it be better to use the rich text edit control and write own functions to extent it, because i am learning c++, and probably it would be better for learning.

                      L 1 Reply Last reply
                      0
                      • G gabbana

                        Does nobody has an idea how to fix the problem ? By the way: Is Scintilla a good choice, or would it be better to use the rich text edit control and write own functions to extent it, because i am learning c++, and probably it would be better for learning.

                        L Offline
                        L Offline
                        Larry Mills Sr
                        wrote on last edited by
                        #11

                        I believed the reason for the "chinese" chars is because you have NOT established memory for the varable yet. Always, always zero out a varable before it is used: Example: CString str;(you've declared it and it resides in memory, but what is presently at that memory location?) just do this str = ""; or in Unicode: str = _T(""); Now that location is clean for str. I don't know anything about "Scintilla" I've always used the rich edit control methods. Codeproject has multiple examples that show how. A C++ programming language novice, but striving to learn

                        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