2013年11月26日星期二

开始使用C++/CLI编程

一直以来一直是使用C++和C#,最近接触了C++/CLI并开始使用它编写程序,已经写了两三千行程序,使用C++/CLI对一个C++和C#程序员来说简直是轻而易举,C++/CLI也会给我们带来很多好处,有了C++/CLI对于.NET平台上的C++来说就是多了一个非常好用的武器,C++在.NET平台中得到极大的补充,所谓“C++/CLI”是静态C++对象模型到CLI的动态组件对象编程模型的捆绑。简而言之就是如何用C++在·NET中编程,而不是C#或Visual Basic,它实现了ISOC++和.NET的无缝连接。像C#和CLI本身一样符合ISO标准。微软的.NET的基础CLR(Common Language Runtime,通用语言运行时)就是CLI的一个实例。
百度百科,维基百科:
http://baike.baidu.com/view/459502.htm?noadapt=1
http://zh.wikipedia.org/wiki/C%2B%2B/CLI

以下内容转载自《C++/CLI in action》

The Common Language Infrastructure (CLI) is an architecture that supports a dynamic language-independent programming model based on a Virtual Execution System.

The role of C++/CLI

role of c   cli

C++ has been paired with language extensions before, and the result hasn’t always been pretty. Visual C++ 2005 is the first version of a Microsoft C++ compiler that has implemented the C++/CLI specification. This means three things for the C++ developer:
■ C++ can be used to write applications that run on the .NET Framework. There is no need to learn a totally new language or to abandon all the C++ knowledge and experience built up through years of coding.
■ C++/CLI lets developers reuse their native C++ code base, saving the agony of having to rewrite all the existing code to enable it to run on the .NET Framework.
■ C++/CLI is designed to be the lowest-level language for the .NET Framework. For writing purely managed applications, it’s your most powerful choice; or, as I like to say, “C++/CLI actually lets you smell the CLR (Common Language Runtime).”


C++/CLI. C++ with some additional keywords and semantics that support .NET
One of the core aspects of the CLR is a unified type system called the Common Type System (CTS). The CTS defines the model followed by the CLR for the declaration and usage of CLI types.

hierarchy of NET frameworkThe common language specification

What is the .NET Framework?
The .NET Framework provides an abstraction layer on top of the native operating system that allows applications compiled into a special intermediate language called Microsoft Intermediate Language (MSIL) to run under a managed environment— where both execution and memory are managed by various parts of the framework. Its two primary components are the Common Language Runtime (CLR) and an extensive Base Class Library (BCL). The CLR is responsible for the execution of .NET applications, inducing memory management through its built-in Garbage Collector (see the section on memory management for more information), whereas the BCL provides various hierarchical class libraries for creating rich user interfaces (UIs), both for the desktop and for the Web—accessing data, security, web services, and many more commonly-performed programming chores.