C++/CLI Syntax part1_在C#中結合C++類別去印出字串的練習




Project setting



Let us start to New a project

At first , I new a  " C# Console Application" program

In chinese we say 主控台應用程式

新增一個C# Console Application


Add New Project

新加入一個CLR 類別庫




小複習link : http://coolmandiary.blogspot.tw/2016/04/blog-post_30.html


Setting the same CPU Configuration

Go to the solution properties

Both of  Debug and release are set x64




Go to the project properties


Solution properties --> properties dependencies(專案相依性)










Let us try some simple code

In the ClassLibrary1.h Block



創建一個對於在託管堆中對象的應用(reference class)

還有這裡的class由於是相依於C#這個project
所以有ref這個字

  ref是創建一個位於託管堆上的引用類型,

對應的是value,它創建一個位於託管棧上的類型,都由垃圾回收器負責回收內存





以下有附上一些參考連結:

托管类类型的声明
https://msdn.microsoft.com/zh-cn/library/ms235220(VS.80).aspx


In the ClassLibrary1.cpp Block


The Class has one function

test()

to print the hello world string on the screen

寫好了這兩份(.cpp及.h檔)

我們先進行建置





Go back to the Program.cs

Add reference first




and Write the code below





這裡有個小重點  一定要先去Build先前那兩個C++的file之後添加參考才有用喔!!!




留言

這個網誌中的熱門文章

經得起原始碼資安弱點掃描的程式設計習慣培養(五)_Missing HSTS Header

經得起原始碼資安弱點掃描的程式設計習慣培養(三)_7.Cross Site Scripting(XSS)_Stored XSS_Reflected XSS All Clients

(2021年度)駕訓學科筆試準備題庫歸納分析_法規是非題