2

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?

Nick
  • 10,309
  • 21
  • 97
  • 201

2 Answers2

1

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.

gliderkite
  • 8,828
  • 6
  • 44
  • 80
0

You should also be able to add your DLL as a reference to your Project, then in the Properties for that file, select Copy Local > True.

screenshot

  • 3
    If it's native (hence the need to P/Invoke) you can't add a reference to it. You could add it is a Content item and set it's Build Action to 'Copy Always' or 'Copy When Changed' though. – ctacke Oct 17 '12 at 05:00