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. Strange unicode rendering problem

Strange unicode rendering problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
6 Posts 3 Posters 0 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.
  • L Offline
    L Offline
    Luke Murray
    wrote on last edited by
    #1

    Hey all, I have a little project I am messing around wiht, it just wraps up some winapi functions in c++ classes. I just changed all the std::string's to std::wstring and all my literal string have L"string" now. And UNICODE and _UNICODE are define. Anyway, everything compiles and runs. the only proplem is nothing renders. Buttons do not show and text control do not show, the only thing that shows in the scroolbars for the textarea. Any ideas, I bet it is something simple i am missing. Hope you guy and girls have something to point me to. Cheers

    J 1 Reply Last reply
    0
    • L Luke Murray

      Hey all, I have a little project I am messing around wiht, it just wraps up some winapi functions in c++ classes. I just changed all the std::string's to std::wstring and all my literal string have L"string" now. And UNICODE and _UNICODE are define. Anyway, everything compiles and runs. the only proplem is nothing renders. Buttons do not show and text control do not show, the only thing that shows in the scroolbars for the textarea. Any ideas, I bet it is something simple i am missing. Hope you guy and girls have something to point me to. Cheers

      J Offline
      J Offline
      Johann Gerell
      wrote on last edited by
      #2

      Well, one thing that instantly comes to my mind, is that buffer byte sizes, that were previously calculated using std::string::size, must now be calculated using std::wstring::size * sizeof(wchar_t):

      const std::string s1("non unicode");
      const std::wstring s2("unicode");

      const size_t bytesize1 = s1.size() * sizeof(char);
      const size_t bytesize2 = s2.size() * sizeof(wchar_t);

      and, of course, bytesize1 != bytesize2. This in combination with memcpy, memset, etc. is a common trap when changing to unicode. -- The Blog: Bits and Pieces

      J 1 Reply Last reply
      0
      • J Johann Gerell

        Well, one thing that instantly comes to my mind, is that buffer byte sizes, that were previously calculated using std::string::size, must now be calculated using std::wstring::size * sizeof(wchar_t):

        const std::string s1("non unicode");
        const std::wstring s2("unicode");

        const size_t bytesize1 = s1.size() * sizeof(char);
        const size_t bytesize2 = s2.size() * sizeof(wchar_t);

        and, of course, bytesize1 != bytesize2. This in combination with memcpy, memset, etc. is a common trap when changing to unicode. -- The Blog: Bits and Pieces

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

        If your code always used the underlying string type's value_type, you would be always able to determine per-element size (and thus any buffer size requirements) correctly - there is no requirement that basic_string only contain narrow or wide character types:

        typedef std::basic_string< int > IntStr;

        int iValue = 1024;
        IntStr isInt( &iValue );
        const std::wstring s2( L"unicode" );
        const std::string s1( "non unicode" );
        const size_t stByteSize1 = s1.size() * sizeof( std::string::value_type ); // 11
        const size_t stByteSize2 = s2.size() * sizeof( std::wstring::value_type ); // 14
        const size_t stByteSize3 = isInt.size() * sizeof( IntStr::value_type ); // 4

        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!
        Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        DeleteFXPFiles & CheckFavorites (Please rate this post!)

        L J 2 Replies Last reply
        0
        • J James R Twine

          If your code always used the underlying string type's value_type, you would be always able to determine per-element size (and thus any buffer size requirements) correctly - there is no requirement that basic_string only contain narrow or wide character types:

          typedef std::basic_string< int > IntStr;

          int iValue = 1024;
          IntStr isInt( &iValue );
          const std::wstring s2( L"unicode" );
          const std::string s1( "non unicode" );
          const size_t stByteSize1 = s1.size() * sizeof( std::string::value_type ); // 11
          const size_t stByteSize2 = s2.size() * sizeof( std::wstring::value_type ); // 14
          const size_t stByteSize3 = isInt.size() * sizeof( IntStr::value_type ); // 4

          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!
          Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
          DeleteFXPFiles & CheckFavorites (Please rate this post!)

          L Offline
          L Offline
          Luke Murray
          wrote on last edited by
          #4

          Thanks Johann and James. I look for size calculation errors tonight, I beleive that may be part of the problem. As for memory functions, I am not using them currently (i'll double check though). Thanks

          1 Reply Last reply
          0
          • J James R Twine

            If your code always used the underlying string type's value_type, you would be always able to determine per-element size (and thus any buffer size requirements) correctly - there is no requirement that basic_string only contain narrow or wide character types:

            typedef std::basic_string< int > IntStr;

            int iValue = 1024;
            IntStr isInt( &iValue );
            const std::wstring s2( L"unicode" );
            const std::string s1( "non unicode" );
            const size_t stByteSize1 = s1.size() * sizeof( std::string::value_type ); // 11
            const size_t stByteSize2 = s2.size() * sizeof( std::wstring::value_type ); // 14
            const size_t stByteSize3 = isInt.size() * sizeof( IntStr::value_type ); // 4

            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!
            Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            DeleteFXPFiles & CheckFavorites (Please rate this post!)

            J Offline
            J Offline
            Johann Gerell
            wrote on last edited by
            #5

            I answered nitpickingly correct at first, but decided that it would be easier to read the answer if I used char/wchar_t and size_t, because your

            const size_t stByteSize1 = s1.size() * sizeof(std::string::value_type);
            const size_t stByteSize2 = s2.size() * sizeof(std::wstring::value_type);

            is only half correct:

            const std::string::size_type stByteSize1 = s1.size() * sizeof(std::string::value_type);
            const std::wstring::size_type stByteSize2 = s2.size() * sizeof(std::wstring::value_type);

            is correct. And now it's easy to see, for the sake of this exercise, that char/wchar_t and size_t makes reading and understanding easier. But still not correct.

            James R. Twine wrote:

            typedef std::basic_string< int > IntStr;

            Ohhh... dangerous! Using that correctly to get expected results, means that you probably also need to have a char_traits specialization for int to get where you want. -- The Blog: Bits and Pieces

            J 1 Reply Last reply
            0
            • J Johann Gerell

              I answered nitpickingly correct at first, but decided that it would be easier to read the answer if I used char/wchar_t and size_t, because your

              const size_t stByteSize1 = s1.size() * sizeof(std::string::value_type);
              const size_t stByteSize2 = s2.size() * sizeof(std::wstring::value_type);

              is only half correct:

              const std::string::size_type stByteSize1 = s1.size() * sizeof(std::string::value_type);
              const std::wstring::size_type stByteSize2 = s2.size() * sizeof(std::wstring::value_type);

              is correct. And now it's easy to see, for the sake of this exercise, that char/wchar_t and size_t makes reading and understanding easier. But still not correct.

              James R. Twine wrote:

              typedef std::basic_string< int > IntStr;

              Ohhh... dangerous! Using that correctly to get expected results, means that you probably also need to have a char_traits specialization for int to get where you want. -- The Blog: Bits and Pieces

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

              You are correct about needing to use the class' size_type type to get the correct variable type.    The example I gave for using a string class for int types was contrived - I just wanted to demonstrate the use of value_type.  But you are correct there as well - more would need to be done to make a completely usable IntStr 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!
              Tip for new SUV drivers: 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
              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