3
I가 그 시간 파일이이있는 DLL :늦은 바인딩 C++ DLL은 - 함수는 항상 true를 돌려
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);
}
이상한 이유로 연결 함수는 반환 값이 C++에 상관없이 항상 true를 반환합니다. C#에서 호출 규칙을 StdCall로 변경하려고 시도했지만 문제가 계속 발생합니다.
아이디어가 있으십니까?
. 감사! – Nitay