Click to See Complete Forum and Search --> : passing __gc form to __nogc object


jeffouille
February 1st, 2010, 02:57 PM
Hello,

I've got the following problem.

In my application i would like to pass an __gc form to an __nogc class. Like this.

public: __gc MyForm() {

public: Myclass * MyObject;

....... Load Of my form ......
MyObject = new Myclass( this);

};

Unfortunatly, with visual c++ .NET, it's impossible!

Any sugection?

Tank in advance for help.

Alex F
February 2nd, 2010, 02:40 AM
In C++/CLI there is gcroot keyword, but I don't know whether is is supported in managed C++.

jeffouille
February 2nd, 2010, 03:08 AM
It should working, but i don't know where place it in my code

Alex F
February 2nd, 2010, 05:35 AM
Add class member of type gcroot<MyForm*> to Myclass and try to initialize it with MyForm reference, using constructor parameter or directly.

jeffouille
February 2nd, 2010, 06:42 AM
Once declare as following, how could I use the form.

public MyClass {

Myclass();
gcroot<MyForm*> f;

}

Alex F
February 2nd, 2010, 06:47 AM
....... Load Of my form ......
MyObject = new Myclass();
MyObject->f = this;

jeffouille
February 2nd, 2010, 07:00 AM
I've got the following error :

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'MyAppli::MyForm __gc *const ' (or there is no acceptable conversion)

Alex F
February 2nd, 2010, 07:08 AM
This is compiled in C++/CLI 2005:


ref class RefClass;

class NativeClass
{
public:
NativeClass(){}
gcroot<RefClass^> m_pRefClass;

};

ref class RefClass
{
public:
RefClass()
{
pNativeClass = new NativeClass();
pNativeClass->m_pRefClass = this;
}

NativeClass* pNativeClass;
};


Look at gcroot definition of your C++ version.

jeffouille
February 2nd, 2010, 08:37 AM
I do not finc the solution, do you have any idea to resolve my problem.

Do you think the reason of the problem is the Refclass is a Form?