我先写了一个简单的返回hello world字符串的c代码:
const char *hello() { return "hello world"; }
使用gcc --shared a.c -o a.dll
编译。
然后写了如下C#代码调用它:
using System;
using System.Runtime.InteropServices;
class Program {
[DllImport("a")]
static extern string hello();
static void Main() {
Console.WriteLine(hello());
}
}
但是运行后却无法正常输出,也没有任何报错,怎么办?