I have successfully built an application in C# to interface a highspeed measurement sensor. The application uses a third party DLL file used to interface the external hardware, supplied by the hardware vendor. A sample code snippet on how to interface the classes in the DLL file is shown below;
[DllImport("LJV7_IF.dll")]
internal static extern int LJV7IF_Initialize();
[DllImport("LJV7_IF.dll")]
internal static extern int LJV7IF_Finalize();
[DllImport("LJV7_IF.dll")]
internal static extern uint LJV7IF_GetVersion();
[DllImport("LJV7_IF.dll")]
internal static extern int LJV7IF_UsbOpen(int lDeviceId);
[DllImport("LJV7_IF.dll")]
internal static extern int LJV7IF_EthernetOpen(int lDeviceId, ref LJV7IF_ETHERNET_CONFIG ethernetConfig);
Enphasis is laid on the use of "DLLImport" function. In order to access the DLL file, I created in folder called Library in the solution path an then added the command
copy $(SolutionDir)Library\LJV7_IF.dll $(TargetDir)LJV7_IF.dll
such that the DLL can be copied to the bin folder after successful build. As a result the application currently works.
When the application is Published using the in-built Publish option in Visual Studio
the generated setup installs but the DLL "LJV7_IF.dll" is not copied to the application output. When the installed application is run, the DLL file cannot be located. This is the error message I get,
The Error message specifies that the application cannot locate the DLL file.
QUESTION: Is there an alternative way to reference the DLL file such that when the executable file is created, the DLL is correctly located?



