Answered by:
Calling Managed Code from Unmanaged Code ?????

Question
-
I found this great example on this issue:
http://www.codeproject.com/managedcpp/unmanaged_to_managed.asp
unfortunatelly , it only works on v.s.net 2003 , and in order to compile it in v.s.net 2005 with the /clr option, you have to make a lot of changes in the code like replacing _gc with ref and alot of other things. I tried to do it, but after all the changes, it still didn't work?
can someone refer me to an example which is suited to the new visual c++ syntax or explain how to migrate from the managed c++ extensions to the new semantics??
thanks, Uri
Sunday, January 22, 2006 7:14 PM
Answers
-
Uriparan wrote: you can't add a reference from a native code and then refer specifically to the managed component methods , that's the all point. It was the same in VC++ 2003 too. To add a .NET reference, you need /clr compilation.
Alternatively, you can use CCW as I mentioned.
Sunday, January 22, 2006 9:53 PM
All replies
-
Calling managed code from native code is essentially as simple as enabling /clr compilation and adding a reference to the managed assembly. Once you do that, you can directly use the managed classes from your code.
Alternatively, if you do not want to enable /clr, you could use CCW, though you won't be able to use objects that do not have default constructors, and all the COM stuff may be a trifle confusing if you are not used to BSTRs and SAFEARRAYs.
Sunday, January 22, 2006 8:08 PM -
you can't add a reference from a native code and then refer specifically to the managed component methods , that's the all point.Sunday, January 22, 2006 9:28 PM
-
Uriparan wrote: you can't add a reference from a native code and then refer specifically to the managed component methods , that's the all point. It was the same in VC++ 2003 too. To add a .NET reference, you need /clr compilation.
Alternatively, you can use CCW as I mentioned.
Sunday, January 22, 2006 9:53 PM -
Hey, thanks, I managed to do it.I'll recommand your replyMonday, January 23, 2006 8:08 AM
-
no, it's not correct what you wrote.
you can use Rcw only if you're are trying to reference the nanaaged code from a Com object(you need to have a file extension tlb) , but if you're trying to reference it from a native c++ code ,, you can't use the Rcw.
also, you can't reference a c# class library project from a class library CLR project,
Monday, January 23, 2006 9:19 AM -
Uriparan wrote: no, it's not correct what you wrote.
you can use Rcw only if you're are trying to reference the nanaaged code from a Com object(you need to have a file extension tlb) , but if you're trying to reference it from a native c++ code ,, you can't use the Rcw.
also, you can't reference a c# class library project from a class library CLR project,
I was not talking of RCW, I was talking about CCW - they do opposite things.
And you can reference a C# lib from a C++/CLI lib. I don't understand why you say that's not possible.
C++/CLI can be used to do "everything" that can be done with any other CLI language.
Monday, January 23, 2006 3:31 PM -
Hi, you were right after all!
the link that I brougt at the top of this page was refering to a project that has been done on v.s.net 2003 before the CLR option was introduced in v.s.net 2005. that's why it's not straightforward solution.
thank you , I'll recommend your replies.
Tuesday, January 24, 2006 7:40 AM