作業系統: 64位win 7
Visual Studio: 2012
.Net Framework: 4.5
實作方式是: 使用C#開發一個dll, 在C++的控制台程式中調用C#中的方法。
1:建立C# 的 Class Library project。 名字為: CShartLibrary
2. 改動Class1.cs的檔案内容(僅僅是自己主動産生的檔案)
内容例如以下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CShartLibrary
{
public class Class1
{
public void helloworld()
{
Console.WriteLine("Hello World");
}
}
}
3. 編譯産生DLL 檔案CShartLibrary.dll 位于 CShartLibrary\bin\Debug
4. 建立C++的Project。(類型: Win32 Project; 名字 CppProject)
5. 改動項目屬性
6. 将上面産生CShartLibrary.dll 放入CppProject\CppProject中, 與CppProject.cpp 同檔案夾
7. 假設要Ctrl + F5 直接執行的話。 還要将CShartLibrary.dll放入 CppProject\x64\Debug 這個檔案夾中。
(注意: 僅僅有一層CppProject 檔案夾哦)