C++代码
#include<iostream>
using namespace std;
extern "C"
{
_declspec(dllexport) int FunctionInDLL(const wchar_t* p){
wcout << L"这是c++的库:\n";
wcout << p << L"'" << endl;
return 42;
}
}
C#代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace 调C__类库
{
class Program
{
[DllImport("ConsoleApplication1.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern int FunctionInDLL(string s);
static void Main(string[] args)
{
Console.WriteLine("C#");
int result = FunctionInDLL("这就是C#");
Console.WriteLine(result);
Console.ReadKey();
}
}
}