Search code examples
c#c++windows-mobilepinvokemobile-emulator

Where to place native DLL to use Pocket PC emulator?


I'm developing a SmartDevice project in C# (Windows Mobile 6.1 - Visual Studio 2008 - Pocket PC) and I want to use PInvoke. I have a native DLL written in C++.

When I run the application on my device I place the native DLL in \Program Files\My Project directory (on my divice) and it works, but I need to use the emulator and I don't know where to place my navive DLL (on my computer) in this case.

I tried to the working directory with relative path, i tried to DllImport the absolute path:

[DllImport(@"C:\John\VMDLLDevice.dll", EntryPoint = "Write")]
public static extern bool Write(char[] FileName);

But when I pinvoke the native DLL i got an Exception because the emulator can't find the DLL.

Where have I to place my native DLL to use the emulator?


Solution

  • Suppose you have these two projects in the same Visual Studio solution:

    1. SmartDeviceProject1: the Pocket PC device application in C#.
    2. NativeDLL: the Win32 SmartDevice DLL in C++.

    Now you can follow the following steps:

    • Select the Pocket PC Emulator for both project, in the Visual Studio Device Option.
    • Deploy the projects; now in \\Program Files of your Emulator you can see the two new directories: SmartDeviceProject1 and NativeDLL (Start -> Programs -> File Explorer -> Program Files).

    Your NativeDLL.dll is in the NativeDLL directory, so use the following DllImport:

    [DllImport(@"..\NativeDLL\NativeDLL.dll", EntryPoint = "Write")]
    public static extern bool Write(char[] FileName);
    

    And now you can run your application using the emulator.

    MSDN additional Information: Using the Emulator in Smart Device Projects.