- 首先新建一個c++應用程序(我選的是控制檯應用程序+window) 2.0
- 配置屬性
- 引用.NET dll
#using "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll"
#using "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll"
#using "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll"
#using "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll"
#using "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll"
using namespace System;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Xml;
using namespace System::IO;
using namespace System::Windows::Forms;
簡單的使用示例:
// 全寫
System::String ^str = "This is the C # object";
System::Windows::Forms::MessageBox::Show(str);
// 簡寫
String ^str = "This is the C # object";
MessageBox::Show(str);
C#與C++混用,各取所長。