P/Invoke函数重载

3

我正在尝试从F#调用一个C库,并遇到了一个奇怪的问题。我有一个包含所有extern函数的模块。底层的C库有两个同名但参数不同的函数。在F#模块中,这是不允许的。

module C =

  open System.Runtime.InteropServices

  [<DllImport("libc", CallingConvention = CallingConvention.Cdecl)>]
  extern int setValue(nativeint source, int value)

  [<DllImport("libc", CallingConvention = CallingConvention.Cdecl)>]
  extern int setValue(nativeint source, string value)

  // the previous function declaration cause the following compile-time error:
  // Duplicate definition of value 'setValue'

有没有什么特别的方法来解决这个问题?我不能修改C库。
1个回答

6

EntryPoint属性应该可以使用(例如,使用序数),如果可以信任MSDN的话(尚未在F#中进行测试)。将导入的函数命名为setValueInt()setValueString()


谢谢。我对这个 P/Invoke 场景还很陌生。 - pblasucci

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接