System.DllNotFoundException: "Unable to load DLL "E:\drvutil\Debug\drvutil.dll": The specified module could not be found.

Hi,

I migrated the project from VS2005 to VS2017, And when i am running the application, Unmanaged (C++ dll function) call is not happening from the Managed code (C# console application).


Below is my Managed code and from here i am calling the Unmanaged function (IsUPSPresent)

ValidateUPS\InstallerTasks.cs

namespace ValidateUPS
{
class InstallerTasks
{
[DllImport("drvutil.dll", CallingConvention = CallingConvention.Cdecl)]
[return:MarshalAs(UnmanagedType.Bool)]
public static extern Boolean IsEMRPresent();

}

public static int Main(String[] args)
{
int retVal = ERROR_FAILURE;
String install = "INSTALL";
try
{
if (args.Length == 1)
{

if (args[0].Equals(install))
{
if (IsUPSPresent())

And the Function definition in the Unmanaged code is like as shown below in drvutil.cpp

extern "C" BOOL __declspec(dllexport) IsUPSPresent()
{
BOOL bRetValue = FALSE;
BOOL bRetry = TRUE;
DWORD retry_comms;

if (GetApcUpsType())
{
bRetValue = TRUE;
}

I have marshelled the function return type and also using extern "C" BOOL __declspec. But i am getting the below error:

System.DllNotFoundException: "Unable to load DLL "E:\drvutil\Debug\drvutil.dll": The specified module could not be found.
But the dll is present in the specified path.

Please help me to resolve the error.
Topic archived. No new replies allowed.