I am having a lot of trouble getting a basic scenario to work on windows mobile 5.0 emulator. I have a winforms app that eventually calls into native code. Deployment works fine and all the native DLLs are copied in the same folder as the winforms .exe. I also verified this is the case with Remote File Viewer tool.
However when I launch my app, it always fails with "Can't find PInvoke dll -- System.MissingMethodException" error (when the time comes to call into native code, the DllImport attribute is rendered useless). I know that the native dll is found in the same folder as the executable. What more should I do?
I am using VS 2008.
To extend Jared's answer, four more common reasons to get a MissingMethodException while P/Invoking in the CF:
- You are missing dependencies of the native library you are calling into.
- The native assmebly was compiled for the wrong subsystem (i.e. desktop, not CE)
- The native assembly was compiled for the wrong processor (i.e. x86 and not ARM)
- You don't have enough virtual memory for the DLL to load.
Have you verified the DLL entry points are undecorated with something like dumpbin?
Given the error message there are usually one of 2 problems
- It can't find the DLL. The DLL is found by looking at the executing directory and the PATH environment variable
- It can't find the function within the DLL. Have you checked to make sure both the declaration and definition of the DLL are both extern "C" and marked as
__declspec(dllexport)
Also, sanity check is to make sure the DLL name is spelled correctly and lacking the .dll suffix.
Your problem is due to the fact that WM5 memory managment is crap. DLLs are loaded from top of slot to bottom while apps are loaded from bottom to top. If you don't have enough space between your app and your DLL, you will receive a "can't pinvoke" error.
WM5 allocates 32 slots of 32Mb for applications to run into.
Each time WM5 allocates memory for dll, it uses a minimum of 64Kb block, so if your DLL is 32K, it will take 64k, if your DLL takes 68k then WM5 will allocate 2x64Kb — 128Kb.
When WM5 loads the DLL needed, it will always load at the bottom address of the previsouly loaded app, i.e. if app 1 has loaded 2×30kb DLLs, the first one will be loaded at address 0 to 64k, the second from 64 to 128, then your app will load its DLLs from 128kb, not 0, even if your apps runs into a separate slot.
In order to make things work, you will have to load your app earlier or remove non-needed apps from the windows starup folder.
The DLL what you are using doesn't have definition for the method what you are calling.
so the exception occurs..
it compiles fine.. only in run time problem occur..
solution is you need to make sure the definition is present in the DLL or not,else you need to go for some other dll.