I have never worked with DLL import, so I have a fun problem.
I am trying to implement Ghostscript.NET in a hobby project. So I have made a project which is called GhostscriptSharp. This project has a file called Ghostscript32.cs, which imports DLL's like this:
#region Hooks into Ghostscript DLL
[DllImport("gsdll32.dll", EntryPoint = "gsapi_new_instance")]
private static extern int CreateAPIInstance(out IntPtr pinstance, IntPtr caller_handle);
[DllImport("gsdll32.dll", EntryPoint = "gsapi_init_with_args")]
private static extern int InitAPI(IntPtr instance, int argc, string[] argv);
[DllImport("gsdll32.dll", EntryPoint = "gsapi_exit")]
private static extern int ExitAPI(IntPtr instance);
[DllImport("gsdll32.dll", EntryPoint = "gsapi_delete_instance")]
private static extern void DeleteAPIInstance(IntPtr instance);
When I add a new console test project, reference the GhostscriptSharp project and have the gsdll32.dll in my root, and run the program like this, which works:
GhostscriptWrapper.GeneratePageThumb(TEST_FILE_LOCATION, SINGLE_FILE_LOCATION, 1, 100, 100);
However, I need this to work in a web project. So I added added the gsdll32.dll in the root, and added a reference to the GhostscriptSharp project. However, then I get the error here:
An exception of type 'System.DllNotFoundException' occurred in GhostscriptSharp.dll but was not handled in user code
Additional information: Unable to load DLL 'gsdll32.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Any ideas how to solve this?
This is an image of my solutions folder:
I will just answer it, even though the answer very extremely simple.
The reason if the dll file has to be in your bin folder. If it not by default.
I therefore made the following script, which makes it copy it correctly into the bin folder:
if exist "$(TargetDir)gsdll32.dll" goto :exit
copy "$(ProjectDir)\..\Packages\GhostscriptSharp\gsdll32.dll" "$(TargetDir)"
:exit