Overloading the P / Invoke Function

I am trying to P / invoke the C library from F # and am facing a particular problem. I have a module containing all my functions extern. The C base library has two functions with the same name but different arguments. This, of course, is not allowed in the F # module.

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'

Is there any special way around this? I cannot change the C library.

+3
source share
1 answer

The attribute EntryPointshould work (for example, with a serial number), if MSDN can be trusted (not checked in F #), name your imported functions, for example. setValueInt()and setValueString().

+6
source

Source: https://habr.com/ru/post/1754821/


All Articles