title: How do I solve the .NET CF exception "Can't find PInvoke DLL"?
body: <p>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.</p>
  
  <p>I have a DLL named MyDll.dll. In the MyDll.h I have:</p>
  
  <pre><code>extern "C" __declspec(dllexport) int MyDllFunction(int one, int two);
  </code></pre>
  
  <p>The definition of MyDllFunction in MyDll.cpp is:</p>
  
  <pre><code>int MyDllFunction(int one, int two)
  {
      return one + two;
  }
  </code></pre>
  
  <p>The C# class contains the following declaration:</p>
  
  <pre><code>[DllImport("MyDll.dll")]
  extern public static int MyDllFunction(int one, int two);
  </code></pre>
  
  <p>In the same class I am calling MyDllFunction the following way:</p>
  
  <pre><code>int res = MyDllFunction(10, 10);
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>    [DllImport("coredll.dll")]
      protected static extern short GetAsyncKeyState(int vKey);
  </code></pre>
  
  <p>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.</p>