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. Managed C++/CLI
  4. Managed stream to unmanaged VARIANT

Managed stream to unmanaged VARIANT

Scheduled Pinned Locked Moved Managed C++/CLI
questioncsharpc++helptutorial
4 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.
  • P Offline
    P Offline
    picazo
    wrote on last edited by
    #1

    Another data type conversion question: Is it possible to pass a c# stream to a C++/CLI wrapper method which in turn converts it to VARIANT type and passes it to an unmanaged C++ method? Here are the two pieces of code that I would like to see working together:

    // C#
    Stream csStream = ...
    managed.ManagedMethod( csStreamVar );
    
    // Unmanaged C++
    UnmanagedClass::UnmanagedMethod( VARIANT unmanStream )
    {
    ...
    }
    

    Can someone help me fill the following C++/CLI wrapper method that converts the stream to VARIANT?

    ManagedClass::ManagedMethod( Stream^ manStream )
    {
       ... How to convert? ...
       unmanaged.UnmanagedMethod( ...???... );
    }
    

    Thanks,

    ----------------- Genaro

    L 1 Reply Last reply
    0
    • P picazo

      Another data type conversion question: Is it possible to pass a c# stream to a C++/CLI wrapper method which in turn converts it to VARIANT type and passes it to an unmanaged C++ method? Here are the two pieces of code that I would like to see working together:

      // C#
      Stream csStream = ...
      managed.ManagedMethod( csStreamVar );
      
      // Unmanaged C++
      UnmanagedClass::UnmanagedMethod( VARIANT unmanStream )
      {
      ...
      }
      

      Can someone help me fill the following C++/CLI wrapper method that converts the stream to VARIANT?

      ManagedClass::ManagedMethod( Stream^ manStream )
      {
         ... How to convert? ...
         unmanaged.UnmanagedMethod( ...???... );
      }
      

      Thanks,

      ----------------- Genaro

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      picazo wrote:

      Is it possible

      Yes but you have to know what is in the stream to know how to configure the VARIANT, unless of course you have some Magic++ library that does that for you. :rolleyes:

      led mike

      P 1 Reply Last reply
      0
      • L led mike

        picazo wrote:

        Is it possible

        Yes but you have to know what is in the stream to know how to configure the VARIANT, unless of course you have some Magic++ library that does that for you. :rolleyes:

        led mike

        P Offline
        P Offline
        picazo
        wrote on last edited by
        #3

        Can you give me an example of how you would do this if the stream is to contain well-formatted xml.

        ----------------- Genaro

        L 1 Reply Last reply
        0
        • P picazo

          Can you give me an example of how you would do this if the stream is to contain well-formatted xml.

          ----------------- Genaro

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          picazo wrote:

          Can you give me an example of how you would do this if the stream is to contain well-formatted xml

          No, I will show an example of how things work, I will not do your work for you by providing you an example of how I "would" do it.

          System::Xml::XmlDocument^ doc = gcnew System::Xml::XmlDocument();
          System::IO::StringReader^ stream = gcnew System::IO::StringReader("<halp><halpme value=\"22\"/></halpme>");
          doc->Load(stream);
          System::String^ managedStr = doc->DocumentElement->Name;
          System::String^ sval =
          ((System::Xml::XmlElement^)doc->DocumentElement->FirstChild)->GetAttribute("value");
          int nval = System::Convert::ToInt32( sval);
          _variant_t variant(nval);

          std::cout << nval << std::endl;
          std::cout << (int)variant << std::endl;

          led mike

          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