tags:

views:

96

answers:

5

I have a working c++ dll that works in one c# project that I am calling via the interop service. I have created another c# project and am trying to call the same .dll but keep getting a generic error message stating that the .dll cannot be found, both project are .net 2.0. What folder, and where do I specify in the project, should I put the .dll file in so that the project can find it?

Think of it as a reminder for me...

In the previous project I did not have a reference to it, I just had it in the /bin folder and doing the same thing for this project does not work.

Thanks R.

A: 

put the C++ (native) dll in the output directory of your C# project, bin\Debug or so

Ion Todirel
Or just add a project reference which will copy the DLL automatically.
Billy ONeal
A: 

Just as long as you put your working directory to the location of the DLL you should not have a problem.

Go to your project properties on the Debug tab and set the working directory to a directory that contains your DLL.

Brian R. Bondy
A: 

I usually add the DLL to the project as a file and have it copy on newer.

kenny
A: 

C# dll trying to access an unmanged dll by a relative path is governed by the same rules as any process loading a dll - that is the file has to be in the same directory as the executable or in one of paths defined in process' PATH variable.

In order to have your Visual Ssolution do that automatically for you there are number of things you can do:

  1. Add the unmanaged project as C# project dependency. This will copy the DLL into the path of the C# executable.

  2. Change the output path of C++ project to that one of c# executable.

  3. Build the C++ project and add the dll as a link to the C# project. Set in its properties to copy to the output directory.

Igor Zevaka
+1  A: 

Make sure all the DLLs that the DLL in question depends on, are also in the same directory as the exe that uses the DLL.

Yuriy Y. Yermilov