Managed stream to unmanaged VARIANT
-
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
-
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
-
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
-
Can you give me an example of how you would do this if the stream is to contain well-formatted xml.
----------------- Genaro
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