我不确定这个的语法。我正在尝试将此 C# 代码转换为 F#。
struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
public class IdleTimer
{
[DllImport("User32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
}
这是我到目前为止。
type LASTINPUTINFO = {
cbSize : UInt32;
dwTime : UInt32;
}
type IdleTimer =
[<DllImport("User32.dll")>]
[<return: MarshalAs(UnmanagedType.Bool)>]
extern GetLastInputInfo(plii : LASTINPUTINFO ref)
最佳答案
除了 Brian 的评论之外,可能值得指出的是 F# extern 签名相当忠实地反射(reflect)了 C 签名,因此而不是使用 [<In>][<Out>]
引用上的属性,您可能只需将参数声明为 LASTINPUTINFO* plii
,然后在调用函数时使用 && 运算符传递对本地实例的引用。
关于winapi - 使用 MarshalAs 的 P/Invoke 签名的 F# 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1689460/