guys,
how do you you all settle the above problem with a breeze..
i thought that __nogc class will give way to mix the unmanaged and managed types and declaration?
Printable View
guys,
how do you you all settle the above problem with a breeze..
i thought that __nogc class will give way to mix the unmanaged and managed types and declaration?
The keyword __nogc on a class or struct indicates that it is an unmanaged C++ class or struct.Quote:
i thought that __nogc class will give way to mix the unmanaged and managed types and declaration?
To use manages types in unmanaged code you need to use the GCHandle struct.Quote:
cannot declare a managed variable in unmanaged classs
To declare a managed variable reference in an unmanaged class you have to use the gcroot<> templated class e.g.
It behaves like a smart pointer i.e. it has overloads for ->, = etc etc (as shown in the Test() method above).Code:class CMyUnmanagedClass
{
public:
CMyUnmanagedClass(System::String *psString)
{
m_psString = psString;
}
void Test()
{
System::Diagnostics::Debug::WriteLine(m_psString);
}
private:
gcroot<String *> m_psString;
} ;
Okay ?
You can also use gcroot in STL declarations : this is how you can have a std::vector of String * (for instance) e.g.
Darwen.Code:std::vector<gcroot<String *> > asStrings;