cpp code ( nativedll.cpp )
#include <stdio.h>
extern "C" void __attribute__((visibility("default"))) HelloWorld()
{
printf("Hello world, invoked by F#!\n");
}
compile cpp code
$ gcc -dynamiclib -o nativedll.dylib nativedll.cpp
fsharp code
open System.Runtime.InteropServices
module InteropWithNative =
[<DllImportAttribute(@"./nativedll.dylib", CallingConvention = CallingConvention.Cdecl)>]
extern void HelloWorld()
InteropWithNative.HelloWorld()
result
Hello world, invoked by F#!
[<DllImport("user32")>]
extern int GetWindowThreadProcessId( int hwnd, int& lpdwprocessid )
let GetPidFromHwnd(hwnd:int) :int =
let mutable pid = 0
GetWindowThreadProcessId(hwnd, &pid) |> ignore
pid