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. WideChar to Variant conversion

WideChar to Variant conversion

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 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.
  • S Offline
    S Offline
    Suneet 03
    wrote on last edited by
    #1

    Can anyone tell how to convert a widechar string to VARIANT I have an unsigned char* string , I am converting it to widechar using MultiByteToWideChar. How to convert it to VARIANT ? The data is getting lost if i use ColeVariant.

    A 1 Reply Last reply
    0
    • S Suneet 03

      Can anyone tell how to convert a widechar string to VARIANT I have an unsigned char* string , I am converting it to widechar using MultiByteToWideChar. How to convert it to VARIANT ? The data is getting lost if i use ColeVariant.

      A Offline
      A Offline
      Aamir Butt
      wrote on last edited by
      #2

      If you paste your code here, that would be more helpful but simply u can do it by setting the vt of variant to VT_BSTR and then create a bstr. Put the string in BSTR by using ::SysAllocString and set that BSTR in the variant. Something like: BSTR bstrString = ::SysAllocString(str); VARIANT var; var.vt = VT_BSTR; var.bstrval = bstrString; Regards,

      "Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"

      S 1 Reply Last reply
      0
      • A Aamir Butt

        If you paste your code here, that would be more helpful but simply u can do it by setting the vt of variant to VT_BSTR and then create a bstr. Put the string in BSTR by using ::SysAllocString and set that BSTR in the variant. Something like: BSTR bstrString = ::SysAllocString(str); VARIANT var; var.vt = VT_BSTR; var.bstrval = bstrString; Regards,

        "Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"

        S Offline
        S Offline
        Suneet 03
        wrote on last edited by
        #3

        I have sumthng like this VARIANT getData() { unsigned char* puc_Data = " SOME TEXT "; // I am converting the above unsigned char to whar_t* using MultiByteToWideChar(CP_UTF8,..,puc_Data,len,wchar_t*,len); // I want to take this wchar string and convert it to VARIANT // Doing it thru COleVariant ColeVariant var(wchar string ); // Data is getting lost sumwhere here ... return var; Can anyone suggest wat i m doing wrong??

        R 1 Reply Last reply
        0
        • S Suneet 03

          I have sumthng like this VARIANT getData() { unsigned char* puc_Data = " SOME TEXT "; // I am converting the above unsigned char to whar_t* using MultiByteToWideChar(CP_UTF8,..,puc_Data,len,wchar_t*,len); // I want to take this wchar string and convert it to VARIANT // Doing it thru COleVariant ColeVariant var(wchar string ); // Data is getting lost sumwhere here ... return var; Can anyone suggest wat i m doing wrong??

          R Offline
          R Offline
          Roger Broomfield
          wrote on last edited by
          #4

          Why not just do this and let COleVariant do what it is designed to do?

          ColeVariant getData()
          {
          char* puc_Data = " SOME TEXT ";
          ColeVariant var(puc_Data);
          return var;
          }

          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