使用c#中的variant类型参数调用delphi dll

1 c# delphi dll

我有一个这个函数的delphi dll:

function writeRate(data: variant):Double ; stdcall;
Run Code Online (Sandbox Code Playgroud)

我用这个方法从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);
}
Run Code Online (Sandbox Code Playgroud)

但我得到这个例外:

PInvokeStackImbalance was detected
Run Code Online (Sandbox Code Playgroud)

我该如何调用dll?我认为该问题属于变体类型.谢谢!

Den*_*nis 5

stdcall在Delphi代码中匹配CallingConvention.StdCallC#.您应该修复您的委托定义.