Last active
September 22, 2016 19:26
-
-
Save stisa/8c29b228dc9bb3240954711053976d6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## lib.nim ######### | |
proc test1(): string {.exportc, dynlib .}= | |
result = "test" | |
## user.nim ######## | |
import dynlib, osproc | |
# compile libs so I don't have to do it by hand | |
let l1 = execCmd("nim c --app:lib lib.nim") | |
# load the lib | |
let lib = loadLib("lib.dll") | |
# get a pointer to the proc in lib.nim | |
let testptr = lib.checkedsymAddr("test1") | |
#error: request for member 'ClEnv' in something not a structure or union | |
var testderef = cast[proc():string](testptr) | |
echo testderef() # | |
# SIGSEGV | |
var testderef2 = cast[ptr proc():string](testptr)[] | |
echo testderef2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changing
var testderef = cast[proc():string](testptr)
tovar testderef = cast[proc():string {.cdecl.}](testptr)
works.