Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find PInvoke DLL error in Windows Mobile

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.

like image 342
Dilip Avatar asked Sep 21 '09 18:09

Dilip


2 Answers

To extend Jared's answer, four more common reasons to get a MissingMethodException while P/Invoking in the CF:

  1. You are missing dependencies of the native library you are calling into.
  2. The native assmebly was compiled for the wrong subsystem (i.e. desktop, not CE)
  3. The native assembly was compiled for the wrong processor (i.e. x86 and not ARM)
  4. 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?

like image 200
ctacke Avatar answered Nov 17 '22 12:11

ctacke


Given the error message there are usually one of 2 problems

  1. It can't find the DLL. The DLL is found by looking at the executing directory and the PATH environment variable
  2. 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.

like image 24
JaredPar Avatar answered Nov 17 '22 13:11

JaredPar