CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2010
    Posts
    7

    passing __gc form to __nogc object

    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.

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: passing __gc form to __nogc object

    In C++/CLI there is gcroot keyword, but I don't know whether is is supported in managed C++.

  3. #3
    Join Date
    Feb 2010
    Posts
    7

    Re: passing __gc form to __nogc object

    It should working, but i don't know where place it in my code

  4. #4
    Join Date
    Jul 2002
    Posts
    2,543

    Re: passing __gc form to __nogc object

    Add class member of type gcroot<MyForm*> to Myclass and try to initialize it with MyForm reference, using constructor parameter or directly.

  5. #5
    Join Date
    Feb 2010
    Posts
    7

    Re: passing __gc form to __nogc object

    Once declare as following, how could I use the form.

    public MyClass {

    Myclass();
    gcroot<MyForm*> f;

    }

  6. #6
    Join Date
    Jul 2002
    Posts
    2,543

    Re: passing __gc form to __nogc object

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

  7. #7
    Join Date
    Feb 2010
    Posts
    7

    Re: passing __gc form to __nogc object

    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)

  8. #8
    Join Date
    Jul 2002
    Posts
    2,543

    Re: passing __gc form to __nogc object

    This is compiled in C++/CLI 2005:

    Code:
    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.

  9. #9
    Join Date
    Feb 2010
    Posts
    7

    Re: passing __gc form to __nogc object

    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?
    Last edited by jeffouille; February 2nd, 2010 at 10:20 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured