P/Invoke函数重载

pbl*_*cci 3 pinvoke f#

我正试图从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'
Run Code Online (Sandbox Code Playgroud)

有什么特殊的方法可以解决这个问题吗?我无法改变C库.

Pon*_*gge 6

EntryPoint如果MSDN可以信任(未在F#中测试),该属性应该起作用(例如,使用序数).为您导入的函数命名,例如setValueInt()setValueString().