Skip to content

Instantly share code, notes, and snippets.

@callmekohei
Last active January 18, 2019 08:57
Show Gist options
  • Save callmekohei/b7cfd65c3bbbb01b762df6c2e54e225d to your computer and use it in GitHub Desktop.
Save callmekohei/b7cfd65c3bbbb01b762df6c2e54e225d to your computer and use it in GitHub Desktop.
interlopのメモ

Sample

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#!

byref —> int&

[<DllImport("user32")>]
extern int GetWindowThreadProcessId( int hwnd, int& lpdwprocessid )

let GetPidFromHwnd(hwnd:int) :int =
    let mutable pid = 0
    GetWindowThreadProcessId(hwnd, &pid) |> ignore
    pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment