这是给所有 C# 大师的。我已经为此苦苦挣扎了一段时间,在网上尝试了各种建议,但无济于事。该操作发生在 Windows Mobile 5.0 中。
我有一个名为 MyDll.dll 的 DLL。在 MyDll.h 我有:
extern "C" __declspec(dllexport) int MyDllFunction(int one, int two);
MyDll.cpp中MyDllFunction的定义是:
int MyDllFunction(int one, int two)
{
return one + two;
}
C# 类包含以下声明:
[DllImport("MyDll.dll")]
extern public static int MyDllFunction(int one, int two);
在同一个类中,我通过以下方式调用 MyDllFunction:
int res = MyDllFunction(10, 10);
这就是该死的东西不断给我“找不到 PInvoke DLL 'MyDll.dll'”的地方。我已经验证我实际上可以在系统调用上执行 PInvoke,例如“GetAsyncKeyState(1)”,声明为:
[DllImport("coredll.dll")]
protected static extern short GetAsyncKeyState(int vKey);
MyDll.dll 与可执行文件位于同一文件夹中,我也尝试将其放入 /Windows 文件夹中,没有任何更改也没有成功。非常感谢任何建议或解决方案。