我有一个带有此功能的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
How do I call the dll? I supposed that the issue is in the variant type. thanks!