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 に答える