3

My Project1 is here \Project1\Bin\Debug\application.exe and my dlls are in \Project1\Debug\3rdparty.dll

How to get path that include this dll in my code?

[DllImport("????????/3rdparty.dll")]

what should i write at question marks (?????) My solution includes other c++ projects inside. So whenever i compiled c++ project, it refresh dll in project1\Debug (some how i am not familiar with c++) I need to use that dlls in DllImport [Path]. If i tried to add reference, it gives me error. This might be really easy question, but i am not able to solve it for some reason.

Anwered by Hans Pasant in comment section :

Change the Output Directory setting in the C++ project to $(SolutionDir)bin\$(ConfigurationName) so that the native DLL ends up in the same folder as your managed program. Just use [DllImport("3rdparty.dll")] in your C# code. – Hans Passant

L.E.
  • 646
  • 2
  • 8
  • 21
  • 2
    Change the Output Directory setting in the C++ project to $(SolutionDir)bin\$(ConfigurationName) so that the native DLL ends up in the same folder as your managed program. Just use [DllImport("3rdparty.dll")] in your C# code. – Hans Passant Nov 29 '11 at 20:38
  • Please accept the answer as solution if it worked. This can be beneficial to other community members reading this thread – Oswald Oct 25 '17 at 16:57

1 Answers1

1
  1. In the 'Solution Explorer', right click on 'References'.
  2. Click 'Add Reference'.
  3. Select the 'Browse' tab and select your 3rdparty.dll.
  4. After its added, right click the 3rdparty.dll under 'References' and change 'Copy Local' to true.
  5. Then just specify your DllImport like normal [DllImport("3rdparty.dll")]

This will only work if its a .NET assembly. Since it looks like you are using a C++ DLL, you will need to look at Using C++ Class DLL in C# Application

Community
  • 1
  • 1
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
  • 1
    I already tried this but got error message "The Refereance to dll could not be added" – L.E. Nov 29 '11 at 20:16
  • See here: http://stackoverflow.com/questions/3456758/a-reference-to-the-dll-could-not-be-added. Only .Net assemblies can be added as a reference. – SwDevMan81 Nov 29 '11 at 20:19
  • thanks for info. i dont only .NET assemblies can be added as ref. – L.E. Nov 29 '11 at 20:22