設為首頁收藏本站

艾歐踢論壇

 找回密碼
 立即註冊

QQ登錄

只需一步,快速開始

搜索
熱搜: 活動 交友 discuz
查看: 692|回復: 0
打印 上一主題 下一主題

Microsoft Visual C++/CLI Step by Step (1)

[複製鏈接]
跳轉到指定樓層
樓主
發表於 2016-1-4 07:15:28 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
Creating a project

1. In Visual Studio, on the File menu, point to New, and then click Project. (Alternatively, you can press Ctrl+Shift+N.)

2. In the navigation pane on the left, under Templates, click Visual C++, and then click CLR.
In the center pane, click CLR Console Application and then, toward the bottom of the dialog box, in the Name box, type HelloWorld.

3. Click the Location list and select a location for your new project or click Browse and navigate to an appropriate directory.

4. Click OK to create the project.
The wizard correctly initializes all the compiler settings for a console project.

using namespace System;  
int main()
{
  Console::WriteLine("Hello, World!");   
return 0;
}

// Hello World.cpp: 主要專案檔。
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"Hello World");
    return 0;
}

^ 代表一个指向 托管对象的句柄
array<> 代表是一个托管数组
array< string^> 就是一个托管字符串数组
Because native C++ pointers (*) and references (&) cannot be tracked precisely, a handle-to object declarator is used.

Member selection through a handle (^) uses the pointer-to-member operator (->).

因此看起來
^是可追踨handle , 它是新的文法取代舊的 __gc *
它和指標(pointer)類似,但可追踨handle會儲存位址,並且當堆積做記憶體空間重整,移動其所參考的物件時,記憶體回收機制會自動地更新儲存的位址。
"^"這個附號是用於 Managed C++ 的 "*" pointer。
"%"這個附號是用於 Managed C++ 的 "&" reference。

這兩個符號和傳統的 pointer 和 reference 分別在於附帶了 Tracking 功能,並且能夠 Automatic Garbage Collection。
暫時只有微軟的 C++ 會用到。

當您使用主控台應用程式範本建立專案時,會自動加入這些參照和檔案:

•至 .NET Framework 命名空間的參考:

◦System—這個命名空間包含了主要類別和基底類別,而這些類別會定義最常使用的值和參考資料型別、事件和事件處理常式、介面、屬性以及例外狀況處理。

◦mscorlib—支援 .NET Framework 開發的組件 DLL。

•原始程式檔:

◦主控台 (.cpp 檔) —主要原始程式檔和您新建應用程式的進入點。它識別專案 .dll 檔案及專案命名空間。在這個檔案中提供個人的程式碼。

◦AssemblyInfo.cpp—包含您可用來修改專案組件中繼資料的資訊 (亦即屬性、檔案、資源、型別、版本資訊、簽章資訊等) 的檔案。如需詳細資訊,請參閱組件內容。

◦Stdafx.cpp—用於建置名稱為 Win32.pch 的先行編譯標頭檔 (Precompiled Header File) 及名稱為 StdAfx.obj 的先行編譯型別檔。

•標頭檔:

◦Stdafx.h—用於建置名稱為 Win32.pch 的先行編譯標頭檔 (Precompiled Header File) 及名稱為 StdAfx.obj 的先行編譯型別檔。

◦resource.h—產生的 app.rc 的 Include 檔。

•資源檔:

◦app.rc—程式的資源指令碼檔。

◦app.ico—程式的圖示檔。

•ReadMe.txt —專案描述檔。






分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 轉播轉播 分享分享 分享淘帖
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

小黑屋|Archiver|手機版|艾歐踢創新工坊    

GMT+8, 2024-5-16 16:04 , Processed in 0.249410 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表