Reputation: 3197
If I reference an external unmanaged DLL in C# by the following:
[DLLImport("MyDLL.dll", ...
Where should the DLL be placed when I want to run the code from my IDE? Should it be in the bin\Debug
folder?
Upvotes: 0
Views: 635
Reputation: 27214
Anywhere locatable by the LoadLibrary
function. See Dynamic-Link Library Search Order for more information:
If
SafeDllSearchMode
is enabled, the search order is as follows:
- The directory from which the application loaded.
- The system directory. Use the
GetSystemDirectory
function to get the path of this directory.- The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
- The Windows directory. Use the
GetWindowsDirectory
function to get the path of this directory.- The current directory.
- The directories that are listed in the
PATH
environment variable. Note that this does not include the per-application path specified by the App Paths registry key. The App Paths key is not used when computing the DLL search path.
bin\Debug
satisfies the first point, assuming that you're only ever running the application in its Debug
configuration.
Upvotes: 1
Reputation: 283684
Yes, alongside the .exe
file produced by the compiler (which ends up in bin\Debug\
as you said) should be perfect.
Upvotes: 0
Reputation: 2095
Which compiling configuration you are using?
If you want to run the application from Visual Studio Debug/Run it would be in your project folder
If you want to run by double click, it should be near your exe which is in
bin\Debug
or
bin\Release
folder.
Upvotes: 1