Mixed mode programming problem in C++/CLI

E

Edward Diener

In Managed C++ in order to share the functionality of a class between
its CLR code and native C++ code, in essence mixed mode programming for
a class, I would design the __gc class so its corresponding __nogc C++
class would be a nested class of the __gc class. The __gc class would
have a pointer to the __nogc C++ class as a private data member. Then
when the __gc class created an object of the native class, it would pass
itself as a pointer to the __nogc C++ class's constructor. The __nogc
class would put this pointer into a corresponding gcroot<>. Then the
__nogc class would be able to access all the members of its
corresponding __gc class via this pointer since, in the 2003 C++ update,
a nested class now has access to all the members of its enclosing class
via a pointer to that class, and VC++ implements that 2003 C++ item.

Now in C++/CLI using this same technique I am told that a ref class can
not have a nested native C++ class.

Oh brother !!!!!

How I am now supposed to access the public, protected, and private
members of a ref class from its corresponding native C++ class using
mixed mode programming in C++/CLI ?

If you tell me that I have to now redesign all my Managed C++ code so
that protected and private data members of my class must now be passed
to a corresponding native C++ class whenever it needs this
functionality, I will not be a happy camper.
 
E

Edward Diener

Edward said:
In Managed C++ in order to share the functionality of a class between
its CLR code and native C++ code, in essence mixed mode programming for
a class, I would design the __gc class so its corresponding __nogc C++
class would be a nested class of the __gc class. The __gc class would
have a pointer to the __nogc C++ class as a private data member. Then
when the __gc class created an object of the native class, it would pass
itself as a pointer to the __nogc C++ class's constructor. The __nogc
class would put this pointer into a corresponding gcroot<>. Then the
__nogc class would be able to access all the members of its
corresponding __gc class via this pointer since, in the 2003 C++ update,
a nested class now has access to all the members of its enclosing class
via a pointer to that class, and VC++ implements that 2003 C++ item.

Now in C++/CLI using this same technique I am told that a ref class can
not have a nested native C++ class.

Oh brother !!!!!

How I am now supposed to access the public, protected, and private
members of a ref class from its corresponding native C++ class using
mixed mode programming in C++/CLI ?

If you tell me that I have to now redesign all my Managed C++ code so
that protected and private data members of my class must now be passed
to a corresponding native C++ class whenever it needs this
functionality, I will not be a happy camper.

I can now see that the only solution in C++/CLI is:

1) Make the native C++ class a separate class in the same assembly
2) Change 'protected' members in my ref class which I want
to access from my native C++ class to 'protected public'.
3) Change 'private' members in my ref class which I want
to access from my native C++ class to 'internal'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top