这是给所有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文件夹中,但没有任何改变和成功。非常感谢您提供的任何建议或解决方案。