I
Ivan Vecerina
We are trying to use a .NET form ("Form") from a non-managed C++
class ("Engine").
The Engine class needs to create the form once (e.g. at construction),
then will be displaying the Form and running a modal loop a few
times. At destruction, the form will be closed and disposed of.
So I wanted to store a kind of pointer or reference to the
garbage-collected Form within the Engine class.
How do we achieve that?
The following naive solution is rejected by the compiler:
using MyNetTest::Form; // a .NET form generated using the Designer
class Engine {
public:
//...
private:
Form^ dlg; //ERROR C3265
};
Error message:
error C3265: cannot declare a managed 'dlg' in an unmanaged 'Engine'
may not declare a global or static variable, or a member of a native
type that refers to objects in the gc heap
There has to be some kind of built-in smart pointer/wrapper
that I can use to make Form a member of Engine, right?
What is the solution?
Thanks,
Ivan
class ("Engine").
The Engine class needs to create the form once (e.g. at construction),
then will be displaying the Form and running a modal loop a few
times. At destruction, the form will be closed and disposed of.
So I wanted to store a kind of pointer or reference to the
garbage-collected Form within the Engine class.
How do we achieve that?
The following naive solution is rejected by the compiler:
using MyNetTest::Form; // a .NET form generated using the Designer
class Engine {
public:
//...
private:
Form^ dlg; //ERROR C3265
};
Error message:
error C3265: cannot declare a managed 'dlg' in an unmanaged 'Engine'
may not declare a global or static variable, or a member of a native
type that refers to objects in the gc heap
There has to be some kind of built-in smart pointer/wrapper
that I can use to make Form a member of Engine, right?
What is the solution?
Thanks,
Ivan