在过程中发现两种办法解决问题:一种是非托管C++创立的dll库,须要用静态方法调用。这种办法无奈在C#的reference中间接援用,而是要用动态调用的办法, 其余博客曾经介绍的很详尽,惟一须要补充的是,C#文件须要先:

`using System.Runtime.InteropServices;`

之后才能够调用[DllImport]办法。
另一种办法是间接应用CLR,生成托管C++dll库。
创立流程
例程如下
C++ dll:

// CPPlibdemo.h#pragma onceusing 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();        }    }}