f# - 如何将 out/ref extern 参数转换为 F#

标签 f# pinvoke extern ref-parameters

我有一个 C# extern 声明,如下所示:

    [DllImport("something.dll")]
    public static extern ReturnCode GetParent(IntPtr inRef, out IntPtr outParentRef);

如何将其转换为 F#?

最佳答案

您可以尝试类似下面的代码。不知道是什么ReturnCode是,所以下面的代码期望它是一个整数。对于任何更复杂的类型,您需要使用 [<Struct>] A-Dubb 引用的答案中的属性。

type ReturnCode = int

[<System.Runtime.InteropServices.DllImport("something.dll")>]
extern ReturnCode GetParent(System.IntPtr inRef, System.IntPtr& outParentRef);

要调用该函数,您需要编写如下代码:
let mutable v = nativeint 10
let n = GetParent(nativeint 0, &v)

顺便说一句:您能否也发布一个示例 C 代码来实现 something.dll 中的功能? ?如果是,我们可以在发送答案之前尝试运行解决方案......

关于f# - 如何将 out/ref extern 参数转换为 F#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6558789/

相关文章:

optimization - F# 和 ILNumerics

f# - 记录类型递归成员函数和 "rec"关键字

c++ - 定义结构时是否可以强制字符串为特定大小?

c - GCC/链接器错误 : using extern keyword gives duplicate definition

F# MSIL 混淆

compilation - 原子和f#的编译问题

c# - 如何将 C# 字符串传递给 delphi .dll PChar 类型?

c# - UI 自动化的 Google Chrome 可访问树缓存问题

c++ - extern 关键字不同于 c 到 c++?

cocoa - 如何存储引用,然后使用 extern NSString const ?