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. VARIANT to CString

VARIANT to CString

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiondata-structureshelp
5 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.
  • D Offline
    D Offline
    Davitor
    wrote on last edited by
    #1

    Hi how can i chane VARIANT to CString?

    VARIANT var=pRange->GetValue();
    CString strp;
    str=CString(var.bstrVal);

    some time i got exception

    Unhandled exception at 0x7c80a30a in test.exe: 0xC0000005: Access violation reading location 0x001e2000.

    Call stack show

    test.exe!ATL::ChTraitsCRT<char>::GetBaseTypeLength(const wchar_t * pszSource=0x001e1f98) Line 284 + 0x1e bytes C++

    in cstring.h class pointing

    static int __cdecl GetBaseTypeLength( _In_z_ LPCWSTR pszSource ) throw()
    {
    // Returns required buffer length in XCHARs
    return ::WideCharToMultiByte( _AtlGetConversionACP(), 0, pszSource, -1, NULL, 0, NULL, NULL )-1;
    }

    Can any one tell me region behind of exception. Plz help me

    C 1 Reply Last reply
    0
    • D Davitor

      Hi how can i chane VARIANT to CString?

      VARIANT var=pRange->GetValue();
      CString strp;
      str=CString(var.bstrVal);

      some time i got exception

      Unhandled exception at 0x7c80a30a in test.exe: 0xC0000005: Access violation reading location 0x001e2000.

      Call stack show

      test.exe!ATL::ChTraitsCRT<char>::GetBaseTypeLength(const wchar_t * pszSource=0x001e1f98) Line 284 + 0x1e bytes C++

      in cstring.h class pointing

      static int __cdecl GetBaseTypeLength( _In_z_ LPCWSTR pszSource ) throw()
      {
      // Returns required buffer length in XCHARs
      return ::WideCharToMultiByte( _AtlGetConversionACP(), 0, pszSource, -1, NULL, 0, NULL, NULL )-1;
      }

      Can any one tell me region behind of exception. Plz help me

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Maybe your VARIANT doesn't contain a string but something else?

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

      D 1 Reply Last reply
      0
      • C Code o mat

        Maybe your VARIANT doesn't contain a string but something else?

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

        D Offline
        D Offline
        Davitor
        wrote on last edited by
        #3

        Thanks for reply. Can you give me idea to solve that problem?

        C S 2 Replies Last reply
        0
        • D Davitor

          Thanks for reply. Can you give me idea to solve that problem?

          C Offline
          C Offline
          Code o mat
          wrote on last edited by
          #4

          Well, as i said, it could be that your VARIANT contains something else than a string, like an integer for example, check this[^] out and you will see there can be a lot of datatypes a VARIANT can hold. So -based on what you see there- you should either skip non-string values or maybe convert what you can to a string if you really need to work with a string.

          > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

          1 Reply Last reply
          0
          • D Davitor

            Thanks for reply. Can you give me idea to solve that problem?

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

            Use VariantChangeType[^] to convert the VARIANT to one holding a BSTR representation of the data before trying to use the BSTR.

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

            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