views:

511

answers:

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

A: 

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

Jacob Adams
Because it isn't a managed or COM DLL.
sixlettervariables
Where does it say that in the question???
Jacob Adams
He's using P/Invoke, which isn't a COM PIA or way you call managed assemblies.
sixlettervariables
+2  A: 

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"
sixlettervariables