我正在使用第三方API,并尝试将以下C#代码转换为F#:
[DllImport("libfsdk.so", EntryPoint = "FSDK_FeedFrame", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
private static extern int FSDK_FeedFrame_Old(int Tracker, long CameraIdx, int Image, ref long FaceCount, [Out, MarshalAs(UnmanagedType.LPArray)] long[] IDs, long MaxSizeInBytes);
public static int FeedFrame(int Tracker, long CameraIdx, int Image, ref long FaceCount, out long[] IDs, long MaxSizeInBytes)
{
IDs = new long[MaxSizeInBytes/8];
return FSDK_FeedFrame_Old(Tracker, CameraIdx, Image, ref FaceCount, IDs, MaxSizeInBytes);
}
到目前为止,我的尝试是:
[<DllImport("libfsdk.so", EntryPoint = "FSDK_FeedFrame", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)>]
extern int private FSDK_FeedFrame(int Tracker, int64 CameraIdx, int Image, int64& FaceCount, [<Out; MarshalAs(UnmanagedType.LPArray)>] int64[] IDs, int64 MaxSizeInBytes);
let FeedFrame(Tracker: int, CameraIdx: int64, Image: int, faceCount: int64 byref, [<Out>] IDs: int64[] byref, MaxSizeInBytes: int64) =
let ids = Array.create (int MaxSizeInBytes) 0L
let mutable fc = 0L
let res = FSDK_FeedFrame(Tracker, CameraIdx, Image, &fc, ids, MaxSizeInBytes)
res
我在参数列表中尝试了byref
的变体,但是结果代码始终表示无效的参数。我是否需要任何特殊的变体以便可以使用此P / Invoke方法?