using System.Runtime.InteropServices;
以后才能够挪用[DllImport]要领。
另一种要领是直接运用CLR,生成托管C++dll库。
建立流程
例程以下
C++ dll:
// CPPlibdemo.h #pragma once using namespace System; namespace CPPlibdemo { public ref class Class1 { // TODO: Add your methods for this class here. public: String ^getgreating(){ return "hello world"; } }; }
C#言语:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CPPlibdemo; namespace ConsoleApplication5 { class Program { static void Main(string[] args) { Class1 clrdemo = new Class1(); Console.Write(clrdemo.getgreating()); Console.ReadLine(); } } }
以上就是C#挪用C++ 动态链接库dll 的内容,更多相关内容请关注ki4网(www.ki4.cn)!