不会使用DllImport,连hello world都做不出?

我先写了一个简单的返回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());
    }
}

但是运行后却无法正常输出,也没有任何报错,怎么办?

用 Depand Walker 看下你的 dll,hello 这个函数导出了没有