2

I am using VS 2008 to develop an application that uses a .dll with P/Invoke. I can successfully use the dll when I use an absolute path. For example, this DOES work:

[DllImport("C:\\myDLL.dll")] internal static extern bool isReady();

this DOES NOT work:

[DllImport("myDLL.dll")] internal static extern bool isReady();

I have tried adding a reference folder and adding the dll to the project folder but neither work. I need to deploy this application on other computers and need to make sure this .dll is included. Thanks for the help!


I forgot to mention when I try to do that I get this error:

Microsoft Visual Studio A reference to 'C:\Users\dlugokja\Documents\Visual Studio 2008\Projects\DinamapN.sln(1)\DinamapN\DinamapN\DinaWin.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component. OK

user7116
  • 63,008
  • 17
  • 141
  • 172
john
  • 1,189
  • 2
  • 15
  • 20
  • When you put a path in your code, use the syntax @"C:\folder\myDLL.dll" that way you don't need to use double slashes – TravisO Jan 23 '09 at 19:28

2 Answers2

4

The solution we use at work is the following:

  1. Add the DLL to your project
  2. Edit the properties of the DLL to be 'Content' and 'Copy Always'
  3. Reference the DLL in your P/Invoke statements as @"mydll.dll"
user7116
  • 63,008
  • 17
  • 141
  • 172
-2

Why not just right click project file, "Add reference" and browse to the dll?

Jacob Adams
  • 3,944
  • 3
  • 26
  • 42