I'm calling a DLL from both C# and C++. The goal is to establish a connection with a hardware prototype. If I call the DLL Method using C++ the connection is established! But I've to call the function using C# for various reasons.
How is it possible to get two different responses from the same method? The only difference is the programming language the method gets called from...
I'm thankful for every suggestion!
Here is the definition of the method to be called:
extern "C" __declspec(dllexport) bool establishCon()
{
LL_Init();
return establishConnection();
}
The the Method gets called in C++ in the following way:
HMODULE dll = LoadLibrary(L"LL_Controll.dll");
if (dll != NULL)
{
establishCon est = (establishCon)GetProcAddress(dll, "establishCon");
if (est != NULL)
{
bool res = est();
if (res == true)
{
printf("Worked");
}
else
{
printf("Failed!");
}
}
else
{
printf("Problem!");
}
}
else
{
printf("CantLoadDLL");
}
The C++ Call returns true!
In C# the method gets called in the following way:
[DllImport(@"D:\C\2018-02-21\OccupancyTest01\x64\Debug\LL_Controll.dll", CallingConvention=CallingConvention.Cdecl)]
public static extern bool establishCon();
public bool call_LL_Controll_estabCon()
{
return establishCon();
}
In this case false is returned.