У меня есть DLL, которая имеет это в своем файле h:
extern "C" __declspec(dllexport) bool Connect();
и в файле c:
extern "C" __declspec(dllexport) bool Connect()
{
return false;
}
В c # у меня есть следующий код:
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool ConnectDelegate();
private ConnectDelegate DLLConnect;
public bool Connect()
{
bool l_bResult = DLLConnect();
return l_bResult;
}
public bool LoadPlugin(string a_sFilename)
{
string l_sDLLPath = AppDomain.CurrentDomain.BaseDirectory;
m_pDLLHandle = LoadLibrary(a_sFilename);
DLLConnect = (ConnectDelegate)GetDelegate("Connect", typeof(ConnectDelegate));
return false;
}
private Delegate GetDelegate(string a_sProcName, Type a_oDelegateType)
{
IntPtr l_ProcAddress = GetProcAddress(m_pDLLHandle, a_sProcName);
if (l_ProcAddress == IntPtr.Zero)
throw new EntryPointNotFoundException("Function: " + a_sProcName);
return Marshal.GetDelegateForFunctionPointer(l_ProcAddress, a_oDelegateType);
}
По какой-то странной причине, функция connect всегда возвращает true независимо от того, какое значение возвращается в C ++.
Я пытался изменить соглашение о вызовах на StdCall в C #, но проблема остается.
Есть идеи?