使用MarshalAs进行P/调用签名的F#语法 [英] F# syntax for P/Invoke signature using MarshalAs
本文介绍了使用MarshalAs进行P/调用签名的F#语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不确定此语法.我正在尝试将此C#代码转换为F#.
I'm unsure of the syntax for this. I'm trying to translate this C# code into 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);
}
这是我到目前为止所拥有的.
This is what I have so far.
type LASTINPUTINFO = {
cbSize : UInt32;
dwTime : UInt32;
}
type IdleTimer =
[<DllImport("User32.dll")>]
[<return: MarshalAs(UnmanagedType.Bool)>]
extern GetLastInputInfo(plii : LASTINPUTINFO ref)
推荐答案
除了Brian的评论外,值得指出的是,F#extern签名相当忠实地反映了C签名,因此不要在其上使用[<In>][<Out>]
属性引用,您可能只需将参数声明为LASTINPUTINFO* plii
,然后使用&&将引用传递给本地实例调用该函数时的操作符.
In addition to Brian's comment, it may be worth pointing out that F# extern signatures reflect C signatures fairly faithfully, so that rather than using the [<In>][<Out>]
attributes on the reference you can probably just declare the parameter as LASTINPUTINFO* plii
, and then pass a reference to a local instance using the && operator when calling the function.
这篇关于使用MarshalAs进行P/调用签名的F#语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文