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. What datatype??

What datatype??

Scheduled Pinned Locked Moved C / C++ / MFC
question
11 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.
  • G gothic_coder

    Chinese character is coming from "GetValue().bstrVal".. Take a look of following code..

    bstrString_Dest = m_cpRecordsetSearch->Fields->GetItem("DestinationValue")->GetValue().bstrVal;

    bstrString_Dest is declared as _bstr_t..

    bstr_t bstrString_Dest

    I tried with const whar_t *

    const whar_t * bstrString_Dest

    but no success.. My question is what data type should i use to hold chinese character in bstrString_Dest???? Thanks all..

    P Offline
    P Offline
    Perspx
    wrote on last edited by
    #2

    I'd highly recommend you read these two articles:

    • Complete Guide to C++ Strings, Pt I
    • Complete Guide to C++ Strings, Pt II

    These should answer your question and will be invaluable for the future, however make sure to read part I first as part II relies on knowledge obtained there.

    1 Reply Last reply
    0
    • G gothic_coder

      Chinese character is coming from "GetValue().bstrVal".. Take a look of following code..

      bstrString_Dest = m_cpRecordsetSearch->Fields->GetItem("DestinationValue")->GetValue().bstrVal;

      bstrString_Dest is declared as _bstr_t..

      bstr_t bstrString_Dest

      I tried with const whar_t *

      const whar_t * bstrString_Dest

      but no success.. My question is what data type should i use to hold chinese character in bstrString_Dest???? Thanks all..

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #3

      A _bstr_t should certainly hold Chinese characters (it's effectively a managed wchar_t) - what's the problem that you're seeing?

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      G 1 Reply Last reply
      0
      • S Stuart Dootson

        A _bstr_t should certainly hold Chinese characters (it's effectively a managed wchar_t) - what's the problem that you're seeing?

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        G Offline
        G Offline
        gothic_coder
        wrote on last edited by
        #4

        _bstr_t did hold chinese character.. But when i see the data using watch or print to any file it shows "????" only... Chinese fonts are definately installed in my system..As i'm reading from database and i can vivdly see chinese character in database. Do i further need to typecast it?? Thanks..

        S 1 Reply Last reply
        0
        • G gothic_coder

          _bstr_t did hold chinese character.. But when i see the data using watch or print to any file it shows "????" only... Chinese fonts are definately installed in my system..As i'm reading from database and i can vivdly see chinese character in database. Do i further need to typecast it?? Thanks..

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #5

          How are you writing it to a file?

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          G 1 Reply Last reply
          0
          • S Stuart Dootson

            How are you writing it to a file?

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            G Offline
            G Offline
            gothic_coder
            wrote on last edited by
            #6

            Now using this..

            (char *)(wchar_t*)bstrString_Dest

            S 1 Reply Last reply
            0
            • G gothic_coder

              Now using this..

              (char *)(wchar_t*)bstrString_Dest

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #7

              As I asked before, "How are you writing it to a file?"

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              G 1 Reply Last reply
              0
              • S Stuart Dootson

                As I asked before, "How are you writing it to a file?"

                Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                G Offline
                G Offline
                gothic_coder
                wrote on last edited by
                #8

                I'm writing in ini file..Also i'm displaying in messagebox..Say the data is "Abc(Some chinese character)"

                MessageBoxW(0, (wchar_t*)bstrString_Dest, 0, 0);

                The messagebox prints "Abc(square brackets)".

                WritePrivateProfileString(pszSection,pszKey,(char *)(wchar_t*)bstrString_Dest,
                pszinipath);

                And this prints "A" only...

                S 1 Reply Last reply
                0
                • G gothic_coder

                  I'm writing in ini file..Also i'm displaying in messagebox..Say the data is "Abc(Some chinese character)"

                  MessageBoxW(0, (wchar_t*)bstrString_Dest, 0, 0);

                  The messagebox prints "Abc(square brackets)".

                  WritePrivateProfileString(pszSection,pszKey,(char *)(wchar_t*)bstrString_Dest,
                  pszinipath);

                  And this prints "A" only...

                  S Offline
                  S Offline
                  Stuart Dootson
                  wrote on last edited by
                  #9

                  gothic_coder wrote:

                  The messagebox prints "Abc(square brackets)".

                  It's probably using non-Unicode font? The following code prints the expected ideaographs with Visual Studio 2008 and Windows 7

                  MessageBoxW(L"丁丂七", L"Test", MB_OK);

                  gothic_coder wrote:

                  WritePrivateProfileString(pszSection,pszKey,(char *)(wchar_t*)bstrString_Dest, pszinipath);

                  That's the ANSI call, so it's no surprise that you can't write Unicode successfully with that call. However, I don't think WritePrivateProfileString will write Unicode anyway.

                  Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                  G 1 Reply Last reply
                  0
                  • S Stuart Dootson

                    gothic_coder wrote:

                    The messagebox prints "Abc(square brackets)".

                    It's probably using non-Unicode font? The following code prints the expected ideaographs with Visual Studio 2008 and Windows 7

                    MessageBoxW(L"丁丂七", L"Test", MB_OK);

                    gothic_coder wrote:

                    WritePrivateProfileString(pszSection,pszKey,(char *)(wchar_t*)bstrString_Dest, pszinipath);

                    That's the ANSI call, so it's no surprise that you can't write Unicode successfully with that call. However, I don't think WritePrivateProfileString will write Unicode anyway.

                    Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

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

                    Alright.. when i copy

                    MessageBoxW(L"丁丂七", L"Test", MB_OK);

                    It comes as

                    MessageBoxW(L"???", L"Test", MB_OK);

                    So it has something to do with my VC 6 setting..Isn't it.. Can someone throw light on it.. And please Stuart tell me how do i write the data on file (Notepad)??? Thanks

                    G 1 Reply Last reply
                    0
                    • G gothic_coder

                      Alright.. when i copy

                      MessageBoxW(L"丁丂七", L"Test", MB_OK);

                      It comes as

                      MessageBoxW(L"???", L"Test", MB_OK);

                      So it has something to do with my VC 6 setting..Isn't it.. Can someone throw light on it.. And please Stuart tell me how do i write the data on file (Notepad)??? Thanks

                      G Offline
                      G Offline
                      gothic_coder
                      wrote on last edited by
                      #11

                      Well

                      MessageBoxW(0, (wchar_t *)bstrString_Dest, 0, 0);

                      giving me right data... Now the problem is how do i print this data to file?? Notepad?? Thanks..

                      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