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. Variants

Variants

Scheduled Pinned Locked Moved C / C++ / MFC
csharphelpquestion
7 Posts 2 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
    dannycarva
    wrote on last edited by
    #1

    Hello, I am a C#/VB programmer. I am trying to fix something that someone else wrote. There is a variable of type _variant_t. I need to take that value, and split it into 2 smaller variants. I am having problems doing this. If anyone can point me in the right direction, I would appreciate it. Here is the variable, "v", that I need to split into 2 variants. //-------------------------------------------------------- // "m_pResponseBuf->BufPtr()" is a pointer to the text in // a Response object. //-------------------------------------------------------- _variant_t v( m_pResponseBuf->BufPtr() ); m_Response->Write( v ); How would I take a portion of "v" and put the results into another variant? Thanks Danny

    L 1 Reply Last reply
    0
    • D dannycarva

      Hello, I am a C#/VB programmer. I am trying to fix something that someone else wrote. There is a variable of type _variant_t. I need to take that value, and split it into 2 smaller variants. I am having problems doing this. If anyone can point me in the right direction, I would appreciate it. Here is the variable, "v", that I need to split into 2 variants. //-------------------------------------------------------- // "m_pResponseBuf->BufPtr()" is a pointer to the text in // a Response object. //-------------------------------------------------------- _variant_t v( m_pResponseBuf->BufPtr() ); m_Response->Write( v ); How would I take a portion of "v" and put the results into another variant? Thanks Danny

      L Offline
      L Offline
      ldaoust
      wrote on last edited by
      #2

      A portion of v, from what you said, would then be a part of a string. To do string operations you can transfer the string into some more usable string object, do the operation you want then transfer the result into a variant. Usually a string contained in a variant is of type _bstr_t, so you can do: CString myString = (LPCTSTR)(_bstr_t)v; //Do operation on myString //Back into variant. _variant_t v2( (LPCTSTR)myString );

      D 1 Reply Last reply
      0
      • L ldaoust

        A portion of v, from what you said, would then be a part of a string. To do string operations you can transfer the string into some more usable string object, do the operation you want then transfer the result into a variant. Usually a string contained in a variant is of type _bstr_t, so you can do: CString myString = (LPCTSTR)(_bstr_t)v; //Do operation on myString //Back into variant. _variant_t v2( (LPCTSTR)myString );

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

        Hello and thanks for the response. Is CString only for MFC apps? I read that somewhere. This dll I am working on is does not use MFC. I'll see if I can do something similar to this, which probably doesn't work, but I'll give it a shot. std::string myString = (_bstr_t)v; myString = myString.substr(0,1000); _variant_t v2( (_bstr_t)myString ); Thanks!!

        L 1 Reply Last reply
        0
        • D dannycarva

          Hello and thanks for the response. Is CString only for MFC apps? I read that somewhere. This dll I am working on is does not use MFC. I'll see if I can do something similar to this, which probably doesn't work, but I'll give it a shot. std::string myString = (_bstr_t)v; myString = myString.substr(0,1000); _variant_t v2( (_bstr_t)myString ); Thanks!!

          L Offline
          L Offline
          ldaoust
          wrote on last edited by
          #4

          Indeed my example was using MFC. Your example using std might work, but their might be a problem with the last operation: _variant_t v2( (_bstr_t)myString ); not sure you can typecast an std::string with _bstr_t.


          Louis * google is your friend *

          D 1 Reply Last reply
          0
          • L ldaoust

            Indeed my example was using MFC. Your example using std might work, but their might be a problem with the last operation: _variant_t v2( (_bstr_t)myString ); not sure you can typecast an std::string with _bstr_t.


            Louis * google is your friend *

            D Offline
            D Offline
            dannycarva
            wrote on last edited by
            #5

            You're right. Didn't work. :( Thanks

            L 1 Reply Last reply
            0
            • D dannycarva

              You're right. Didn't work. :( Thanks

              L Offline
              L Offline
              ldaoust
              wrote on last edited by
              #6

              hint. myString.c_str() will return a "const char *". You can then assign that to the variant. _variant_t v2 (myString.c_str());


              Louis * google is your friend *

              D 1 Reply Last reply
              0
              • L ldaoust

                hint. myString.c_str() will return a "const char *". You can then assign that to the variant. _variant_t v2 (myString.c_str());


                Louis * google is your friend *

                D Offline
                D Offline
                dannycarva
                wrote on last edited by
                #7

                You're right! I tried that, but I did it wrong. I used: _variant_t v2 (myString.c_str); Now it works with the parenthesis. 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