I am working with specific hardware and got .lib and .dll from the h/w vendor. Need to use native dll function from C# so I am trying to use C++/CLI concept in between.
My native code is building fine and producing .lib and .dll file, I used this file with C++/CLI DLL and it also build well and giving .dll file. when using this file in C# , I am getting error like:-
Unhandled Exception: System.IO.FileLoadException: A procedure imported by 'CLI_DLL.dll' could not be loaded.
at C_sharp_Code.Program.Main(String[] args)
Important thing is when I am trying to access native dll from CLR console application, it is working fine but when i am calling native function from CLR DLL then dll is building fine but giving below error when using same from C# console application.
C++/CLI .h file
#pragma once
using namespace System;
extern "C" _declspec(dllimport) bool N_Enabale_Port();
namespace CLI_DLL {
public ref class Class1
{
// TODO: Add your methods for this class here.
public:
bool M_Enabale_Port();
};
}
C++/CLI CPP
#include "stdafx.h"
#include "CLI_DLL.h"
bool CLI_DLL::Class1::M_Enabale_Port()
{
bool temp = N_Enabale_Port();
return temp;
}
C# Code
using CLI_DLL;
namespace C_sharp_Code
{
class Program
{
static void Main(string[] args)
{
try
{
Class1 obj = new Class1();
bool x = obj.M_Enabale_Port();
Console.WriteLine(x);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
Any Advice where I am missing something..