0

我真的被困在这里了。我希望有人能帮助我。如何将此函数转换为 C#?

void __declspec(dllexport) __cdecl test(float *avrSwap, int *aviFAIL, char *accInfile, char *avcOutname, char *avcMsg)
4

1 回答 1

1
[DllImport("dllname", CallingConvention=CallingConvention.Cdecl, EntryPoint="test")]
private static void Test(
    [In, Out, MarshalAs(UnmanagedType.LPArray, SizeConst=1024)] float[] avrSwap,
    out int aviFAIL,
    [In, MarshalAs(UnmanagedType.LPStr)] string accInfile,
    [In, MarshalAs(UnmanagedType.LPStr)] string avcOutname,
    [Out, MarshalAs(UnmanagedType.LPStr)], StringBuilder avcMsg
);

//Wrapper that correctly initializes the StringBuilder to its rightful size.
//It's quite stupid that according to the P/Invoke help, 
//StringBuilder parameters don't support SizeConst.
public static void WrapTest(float[] avrSwap, out int aviFAIL, string accInfile, string avcOutname, out string avcMsg)
{
    StringBuilder sbAvcMsg = new StringBuilder(1024);
    Test(avrSwap, out aviFail, accInfile, avcOutname, sbAvcMsg);
    avcMsg = sbAvcMsg.ToString();
}
于 2013-10-10T15:55:36.640 回答