我有一个具有此功能的delphi dll:
function writeRate(data: variant):Double ; stdcall;
我使用此方法从c#调用函数:
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate double WriteRate(object data);
protected void UpdateRateChannel(string myData)
{
IntPtr pDll = NativeMethods.LoadLibrary("mydll.dll");
IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "writeRate");
WriteRate writeRate = (WriteRate)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(WriteRate ));
double response = writeRate(myData);
bool result = NativeMethods.FreeLibrary(pDll);
}
但我得到这个异常:
PInvokeStackImbalance was detected
如何调用dll?我以为问题出在变量类型中。
谢谢!
最佳答案
Delphi代码中的stdcall
与C#中的CallingConvention.StdCall
匹配。您应该修复您的委托定义。
关于c# - 从C#调用带有变量类型参数的delphi dll,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10532156/