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. Trace a CString

Trace a CString

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghtmlquestion
7 Posts 5 Posters 13 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.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I have few methods, in a CDocument class, which read from IHTMLElement get_tagName.

    						BSTR bstrTagName;
    						CString sTempTagName;
    						if (! FAILED(pElem->get\_tagName(&bstrTagName)))
    						{
    							sTempTagName = bstrTagName;
    							sTempTagName.MakeLower();
    							AfxMessageBox(sTempTagName);
    							SysFreeString(bstrTagName);
    						}
    

    which show in MessageBox html tags: input, div, span, and so on ... if I try

    						BSTR bstrTagName;
    						CString sTempTagName;
    						if (! FAILED(pElem->get\_tagName(&bstrTagName)))
    						{
    							sTempTagName = bstrTagName;
    							sTempTagName.MakeLower();
    							TRACE("%s\\n", sTempTagName);
    							SysFreeString(bstrTagName);
    						}
    

    I have in my debug window the first letter of every read tag: i d s and no entire html tag ... why in MessageBox I see whole word, but in TRACE macro I don't ?

    L D J 3 Replies Last reply
    0
    • _ _Flaviu

      I have few methods, in a CDocument class, which read from IHTMLElement get_tagName.

      						BSTR bstrTagName;
      						CString sTempTagName;
      						if (! FAILED(pElem->get\_tagName(&bstrTagName)))
      						{
      							sTempTagName = bstrTagName;
      							sTempTagName.MakeLower();
      							AfxMessageBox(sTempTagName);
      							SysFreeString(bstrTagName);
      						}
      

      which show in MessageBox html tags: input, div, span, and so on ... if I try

      						BSTR bstrTagName;
      						CString sTempTagName;
      						if (! FAILED(pElem->get\_tagName(&bstrTagName)))
      						{
      							sTempTagName = bstrTagName;
      							sTempTagName.MakeLower();
      							TRACE("%s\\n", sTempTagName);
      							SysFreeString(bstrTagName);
      						}
      

      I have in my debug window the first letter of every read tag: i d s and no entire html tag ... why in MessageBox I see whole word, but in TRACE macro I don't ?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The debugger does not always recognise that a character array may be Unicode, so you need to add the type to the variable name or address in the watch window.

      1 Reply Last reply
      0
      • _ _Flaviu

        I have few methods, in a CDocument class, which read from IHTMLElement get_tagName.

        						BSTR bstrTagName;
        						CString sTempTagName;
        						if (! FAILED(pElem->get\_tagName(&bstrTagName)))
        						{
        							sTempTagName = bstrTagName;
        							sTempTagName.MakeLower();
        							AfxMessageBox(sTempTagName);
        							SysFreeString(bstrTagName);
        						}
        

        which show in MessageBox html tags: input, div, span, and so on ... if I try

        						BSTR bstrTagName;
        						CString sTempTagName;
        						if (! FAILED(pElem->get\_tagName(&bstrTagName)))
        						{
        							sTempTagName = bstrTagName;
        							sTempTagName.MakeLower();
        							TRACE("%s\\n", sTempTagName);
        							SysFreeString(bstrTagName);
        						}
        

        I have in my debug window the first letter of every read tag: i d s and no entire html tag ... why in MessageBox I see whole word, but in TRACE macro I don't ?

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

        You may need to add ,s or ,u to the variable being watched in the Watch window.

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        _ 1 Reply Last reply
        0
        • D David Crow

          You may need to add ,s or ,u to the variable being watched in the Watch window.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #4

          In watch window I can see the variables with their values normally, the problem is when I want to see them with TRACE macro, in my debug window ...

          D 1 Reply Last reply
          0
          • _ _Flaviu

            I have few methods, in a CDocument class, which read from IHTMLElement get_tagName.

            						BSTR bstrTagName;
            						CString sTempTagName;
            						if (! FAILED(pElem->get\_tagName(&bstrTagName)))
            						{
            							sTempTagName = bstrTagName;
            							sTempTagName.MakeLower();
            							AfxMessageBox(sTempTagName);
            							SysFreeString(bstrTagName);
            						}
            

            which show in MessageBox html tags: input, div, span, and so on ... if I try

            						BSTR bstrTagName;
            						CString sTempTagName;
            						if (! FAILED(pElem->get\_tagName(&bstrTagName)))
            						{
            							sTempTagName = bstrTagName;
            							sTempTagName.MakeLower();
            							TRACE("%s\\n", sTempTagName);
            							SysFreeString(bstrTagName);
            						}
            

            I have in my debug window the first letter of every read tag: i d s and no entire html tag ... why in MessageBox I see whole word, but in TRACE macro I don't ?

            J Offline
            J Offline
            Jochen Arndt
            wrote on last edited by
            #5

            You are calling the TRACE macro with a char* format string but pass a CString which is wchar_t* with Unicode builds. Use one of these:

            // Use the _T() macro
            TRACE(_T("%s\n"), sTempTagName.GetString());

            // Pass type of string in format
            #ifdef _UNICODE
            TRACE("%ls\n"), sTempTagName.GetString());
            #else
            TRACE("%hs\n"), sTempTagName.GetString());
            #endif

            // Use TRACEn which is inserting the _T() macro
            TRACE1("%s\n", sTempTagName.GetString());

            Note also that I have used GetString() instead of the implicit CString LPCTSTR operator.

            1 Reply Last reply
            0
            • _ _Flaviu

              In watch window I can see the variables with their values normally, the problem is when I want to see them with TRACE macro, in my debug window ...

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

              _Flaviu wrote:

              the problem is when I want to see them with TRACE macro, in my debug window ...

              Try %S instead of %s.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              T 1 Reply Last reply
              0
              • D David Crow

                _Flaviu wrote:

                the problem is when I want to see them with TRACE macro, in my debug window ...

                Try %S instead of %s.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                T Offline
                T Offline
                tony attwood ntlworld com
                wrote on last edited by
                #7

                Thanks - I've been looking for a few days for this solution. Works a treat

                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