My console app currently makes reference to an unmanaged DLL by using its absolute file path:
public const string dll_path = @"C:\UnmanagedDllPath\externalDLL.dll"
The dll works fine, but now I'm trying to change the file location to somewhere inside my project and include it in the build process. In my first trial, I tried to simply change the file location to the somewhere inside the project. My project structure is:
ProjectName
--PathA <-- cwd
--PathB
--Resources
-- externalDLL.dll
This is my understanding of what should be the proper relative path:
public const string dll_path = @"..\\Resources\\externalDLL.dll"
The project builds, but whenever it needs to reference a function of the dll, I get an 'System.EntryPointNotFoundException: Unable to load DLL' error.
Next, after doing some research, I figured out that I need to change the dll file properties to: Copy to Output Directory. After building, I can now see the file in the bin directory (in its root, at the same level of the .exe), but I still does not work when I change the file path to:
public const string dll_path = "externalDLL.dll"
The error appears in the first call to the dll function, after I changed the dll_path::
string key = 'x';
string user = 'y';
string pwd = 'z';
DLLInitializeLogin(key, user, pwd);
[DllImport(dll_path, CallingConvention = CallingConvention.StdCall)]
public static extern sbyte DLLInitializeLogin(
[MarshalAs(UnmanagedType.LPWStr)] string activationKey,
[MarshalAs(UnmanagedType.LPWStr)] string user,
[MarshalAs(UnmanagedType.LPWStr)] string password);
I'm not sure what else I may be missing...