Use of managed variables in non-ref class
-
Hi, I am currently working on extending an existing C++ project with new functions. The existing project is made using C++, without using managed variables. I would like to insert some of my function which I have written in C++/CLI, so with managed variables. Is it possible to declare a managed variable within a class, without making the class a ref class? If I have to make it a ref class it produces a load of errors, as it is connected with parts of existing code that cannot deal with that. Any ideas would be more than welcome! Thanks, Arjen
-
Hi, I am currently working on extending an existing C++ project with new functions. The existing project is made using C++, without using managed variables. I would like to insert some of my function which I have written in C++/CLI, so with managed variables. Is it possible to declare a managed variable within a class, without making the class a ref class? If I have to make it a ref class it produces a load of errors, as it is connected with parts of existing code that cannot deal with that. Any ideas would be more than welcome! Thanks, Arjen
Arjen Tjallema wrote:
Is it possible to declare a managed variable within a class, without making the class a ref class? If I have to make it a ref class it produces a load of errors, as it is connected with parts of existing code that cannot deal with that. Any ideas would be more than welcome!
Yes, you can. You need to use a
gcroot
. See http://msdn.microsoft.com/en-us/library/481fa11f(VS.80).aspx[^]Regards, Nish
Blog: blog.voidnish.com
-
Hi, I am currently working on extending an existing C++ project with new functions. The existing project is made using C++, without using managed variables. I would like to insert some of my function which I have written in C++/CLI, so with managed variables. Is it possible to declare a managed variable within a class, without making the class a ref class? If I have to make it a ref class it produces a load of errors, as it is connected with parts of existing code that cannot deal with that. Any ideas would be more than welcome! Thanks, Arjen
It is possible to recompile native code as managed code. You can build wrapper class to expose unmanaged C++ code in CLI. Then you can use managed infrastructure in your code. Check G. Hogenson "C++/CLI" book.
-
It is possible to recompile native code as managed code. You can build wrapper class to expose unmanaged C++ code in CLI. Then you can use managed infrastructure in your code. Check G. Hogenson "C++/CLI" book.
Thanks a lot, I'll go find out more about it. Regards, Arjen