Saturday, August 21, 2010

What is a point of .Net??? I can't use C# control in my C++ project?

is there something i miss???What is a point of .Net??? I can't use C# control in my C++ project?
Of course you can use C# in a C++ project. That is what the .NET Framework is all about!





Managed code is code that uses the NET Framework class library. Interoperability enables you to preserve and leverage existing investments in unmanaged code. Managed applications are created by using managed extensions for C++. However, these benefits are also available for unmanaged applications, C++ because these applications can access the classes of the NET Framework.





It is important to note that there are two flavors of C++: managed and unmanaged C++.





Code running under the control of the common language runtime (CLR) is called ';managed code';, and code running outside the CLR is ';unmanaged code';. COM, COM+, C++ components, ActiveX components, and Win32 API are examples of unmanaged code.





The .NET Framework enables interoperability with unmanaged code through platform invoke services, the System.Runtime.InteropServices namespace, and the CLR and through COM Interoperability (COM interop).








There are two ways to use COM components from managed code, i.e., wrappers:





1. For calling OLE Automation compatible COM components, use COM interop or tlbimp.exe. The CLR handles COM component activation and parameter marshaling.





2. For IDL based COM components, use IJW and C++. Every public managed class that implements IUnknown, IDispatch, and other standard COM interfaces can be called from unmanaged code through COM interop.





TWO EXAMPLES:





--------------------------------------鈥?br>




One.





You can't mix C++ and C# in the same Visual Studio project, but you can make a class library in one language, then reference that project / class library in a different project using the other language.





You can call a C++ DLL from C#.





--------------------------------------鈥?br>




TWO.





Problem...


Let's say that you have written a C# control that needs to be able to notify the parent application of certain events. If the application were also using the .NET platform you would just use a delegate. If however, the application is writen in unmanaged C++ then, you need to have some way to send a message or execute a callback from the control that the application can process.





Solution...


For a GUI control, post a notification message to the parent window (see WM_NOTIFY, BN_CLICKED for example).





For non-GUI components, a function pointer is much like a delegate. Remember to include an extra parameter set at the time of subscription, sizeof void* or larger, for the caller to pass his ';this'; pointer or some other data he wants.


____________________________





It is useful for a software developer to have access to forums where he/she can ask questions or provide advice:





http://www.msnewsgroups.net/





http://en.allexperts.com/q/C-3307/What is a point of .Net??? I can't use C# control in my C++ project?
C# and C++ are two ENTIRELY DIFFERENT languages. You can no more use C# in your C++ project than you can use Ada in your Visual Basic project.





I know they both have ';C'; in their name, but that is where the similarity ends. C# is more like a compiled Java for .Net
learn the .net objects.





go to


http://quickstarts.asp.net/QuickStartv20鈥?/a>
  • your cosmetics
  • No comments:

    Post a Comment