C++ .NET object instantiation

  • Thread starter Thread starter Greg Freeman
  • Start date Start date
G

Greg Freeman

I'm missing something obvious with C++ instantiation
of .NET objects. (accessing managed code from unmannaged
code) Anyone suggest good examples in C++ (not C#)?
I'm trying to create an XmlTextWriter object, but the
class is undeclared. How do you declare a class in .NET
C++?

-Greg
 
Here is the sample in managed C++:

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;
using namespace System::Xml;

static void WriteQuote(XmlWriter* pWriter, String* symbol,
double price, double change, long volume)
{
pWriter->WriteStartElement("Stock");
pWriter->WriteAttributeString("Symbol", symbol);
pWriter->WriteElementString("Price", XmlConvert::ToString(price));
pWriter->WriteElementString("Change", XmlConvert::ToString(change));
pWriter->WriteElementString("Volume", XmlConvert::ToString(volume));
pWriter->WriteEndElement();
}

int _tmain()
{
XmlTextWriter* pWriter = new XmlTextWriter(Console::Out);
pWriter->Formatting = Formatting::Indented;
WriteQuote(pWriter, "MSFT", 74.125, 5.89, 69020000);
pWriter->Close();
return 0;
}
 
Back
Top