我该如何解决.NET CF例外"找不到的PInvoke DLL"?

问题描述:

这是所有的C#大师。我一直在敲打我的脑袋在这一段时间了,试着在网上有没有用各类咨询。该行动是发生在Windows Mobile 5.0的。

This is to all the C# gurus. I have been banging my head on this for some time already, tried all kinds of advice on the net with no avail. The action is happening in Windows Mobile 5.0.

我有一个名为MYDLL.DLL DLL。在MyDll.h我有:

I have a DLL named MyDll.dll. In the MyDll.h I have:

extern "C" __declspec(dllexport) int MyDllFunction(int one, int two);

MyDllFunction在MyDll.cpp的定义是:

The definition of MyDllFunction in MyDll.cpp is:

int MyDllFunction(int one, int two)
{
    return one + two;
}

中的C#类包含了如下声明:

The C# class contains the following declaration:

[DllImport("MyDll.dll")]
extern public static int MyDllFunction(int one, int two);

在同一个类中我打电话MyDllFunction以下方式:

In the same class I am calling MyDllFunction the following way:

int res = MyDllFunction(10, 10);

而这正是血腥的事情一直给我无法找到的PInvoke DLL'MYDLL.DLL'。我已验证我其实可以做的PInvoke的系统调用,如GetAsyncKeyState(1),声明为:

And this is where the bloody thing keeps giving me "Can't find PInvoke DLL 'MyDll.dll'". I have verified that I can actually do the PInvoke on system calls, such as "GetAsyncKeyState(1)", declared as:

    [DllImport("coredll.dll")]
    protected static extern short GetAsyncKeyState(int vKey);

该MYDLL.DLL是在同一文件夹中的可执行文件,我也曾尝试把球送入/ Windows文件夹没有更改,也没有成功。任何意见或解决方案大大AP preciated。

The MyDll.dll is in the same folder as the executable, and I have also tried putting it into the /Windows folder with no changes nor success. Any advice or solutions are greatly appreciated.

也许这似乎是一个明显的东西来检查,但在编译的本机DLL正确的CPU架构? IIRC,Windows Mobile的运行于多CPU架构。

Maybe this seems like an obvious thing to check, but are you compiling the native DLL for the correct CPU architecture? IIRC, Windows Mobile runs on multiple CPU architectures.