我有一个带有这个功能的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?我认为问题出在变体类型中。谢谢!