Re: still no success binding DLL's callback function

2019-01-08 Thread Araq
Don't use `ptr any`, use `pointer` instead.


Re: still no success binding DLL's callback function

2019-01-07 Thread oyster
Let me ignore the data type first ;) I hope there is a 
VisualBasic-Freebasic-C-Nim data type comparasion sheet


type
  Fl_Callback* = proc(widget: ptr Fl_Widget, pData: ptr any):cint {.cdecl.}

proc ButtonClick (button: ptr FL_WIDGET, arg: ptr any):cint {.cdecl.} =
  Fl_WidgetCopyLabel(button, "do it again")

Fl_WidgetSetCallback(Btn, ButtonClick)


Run

says 


a.nim(45, 27) template/generic instantiation of `ButtonClick` from here
a.nim(40, 42) Error: cannot instantiate: 'arg:type'


Run


Re: still no success binding DLL's callback function

2019-01-07 Thread cumulonimbus
FLTK's widgets are full on pointers, and coordinates in FLTK-1.3 are at least 
32-bit (they were 16-bit in FLTK-1.0 and FLTK-1.1); You might have problems 
from the int16<>ptr mismatch, as well as the int16<->int32 mismatch if you ever 
use coordianates > 32768.


Re: still no success binding DLL's callback function

2019-01-07 Thread moerm
Here is your problem:


Fl_Callback* = proc(widget: ptr Fl_Widget, pData: ptr any)

# ...
proc ButtonClick (button: ptr FL_WIDGET, arg: ptr any):**cint  {.cdecl.}** =

Run

In other words, `Fl_Callback` is not cdecl and its return type is void while 
`ButtonClick` is cdecl and its return type is cint.


still no success binding DLL's callback function

2019-01-07 Thread oyster
I have posted days ago 
[https://forum.nim-lang.org/t/4522](https://forum.nim-lang.org/t/4522) in which 
I try to bind xcgui which is a free 32bits dll for windows

Now I try to bind FLTK([http://www.fltk.org)](http://www.fltk.org\)). I can 
compile FLTK, test, examples and fluid with my MSYS2+MingW64 on Win7 64 bits I 
know there is already 
[https://github.com/Skrylar/nfltk](https://github.com/Skrylar/nfltk), but so 
bad, the test.nim can not be compiled, my msys2 halted for hours on lines 


Hint: nimwidget [Processing]
CC: fltk_test
CC: fltk_enumerations


Run

However I am not trying to translated the official FLTK C header by myself 
again. C's pointer are always beats me, and I found a nice FLTK binding( and 
tons of examples) for freebasic by D.J.Peters on 
[https://www.freebasic.net/forum/viewtopic.php?f=14=24547](https://www.freebasic.net/forum/viewtopic.php?f=14=24547)
 In the work of D.J.Peters, there are prebuilt 


fltk-c-1.3.3-32.dll
fltk-c-1.3.3-64.dll
libfltk-c-1.3.3-32-arm.so
libfltk-c-1.3.3-32-syslib.so
libfltk-c-1.3.3-32.so
libfltk-c-1.3.3-64-syslib.so
libfltk-c-1.3.3-64.so


Run

so I just mimicked and got the following code 


import winim # for the L""

type
long = int16
Fl_Widget = int16
Fl_Window = int16
Fl_Button = int16
#~ Fl_Callback = int16

const
fltk* = "fltk-c-1.3.3-64.dll"


type
  Ihandle = object
  PIhandle* = ptr Ihandle
  
  Icallback* = proc (arg: PIhandle): cint {.cdecl.}
  
  Fl_Callback* = proc(widget: ptr Fl_Widget, pData: ptr any)

proc Fl_WindowNew(byval: long, h: long, title:cstring):  ptr Fl_Window{.
cdecl, importc: "Fl_WindowNew", dynlib: fltk, discardable.}

proc Fl_ButtonNew(x: long, y: long, w: long, h: long, label: cstring) :  
ptr Fl_Button{.
cdecl, importc: "Fl_ButtonNew", dynlib: fltk, discardable.}

proc Fl_WidgetSetCallback(wgt:  ptr Fl_Widget, cb:Fl_Callback){.
cdecl, importc: "Fl_WidgetSetCallback", dynlib: fltk, discardable.}

proc Fl_WindowShow(win:  ptr Fl_Window){.
cdecl, importc: "Fl_WindowShow", dynlib: fltk, discardable.}

proc Fl_Run(): long{.
cdecl, importc: "Fl_Run", dynlib: fltk, discardable.}

proc Fl_WidgetCopyLabel(wgt:  ptr Fl_Widget; caption: ptr WCHAR){.
cdecl, importc: "Fl_WidgetCopyLabel", dynlib: fltk, discardable.}

proc ButtonClick (button: ptr FL_WIDGET, arg: ptr any):cint  {.cdecl.} =
  Fl_WidgetCopyLabel(button, "do it again")

var Win = Fl_WindowNew(320, 200, "What a shiny Window :-)")
var Btn = Fl_ButtonNew(10, 10, 120, 32, "click me")
#~ Fl_WidgetSetCallback(Btn, ButtonClick)
#~ Fl_WidgetSetCallback(cast[ptr Fl_Widget](Btn), (ButtonClick))
#~ Fl_WidgetSetCallback(cast[ptr Fl_Widget](Btn), 
cast[Fl_Callback](ButtonClick))
Fl_WindowShow(Win)
Fl_Run()


Run

this code can run without the Fl_WidgetSetCallback line.

If I use 


Fl_WidgetSetCallback(Btn, ButtonClick)


Run

I get 


a.nim(45, 21) Error: type mismatch: got 
but expected one of:
proc Fl_WidgetSetCallback(wgt: ptr Fl_Widget; cb: Fl_Callback)
  first type mismatch at position: 2
  required type: Fl_Callback
  but expression 'ButtonClick' is of type: proc (button: ptr Fl_Widget, 
arg: ptr GenericParam): cint{.cdecl.}

expression: Fl_WidgetSetCallback(Btn, ButtonClick)


Run

elif I use 


Fl_WidgetSetCallback(cast[ptr Fl_Widget](Btn), (ButtonClick))


Run

I get 


a.nim(46, 21) Error: type mismatch: got 
but expected one of:
proc Fl_WidgetSetCallback(wgt: ptr Fl_Widget; cb: Fl_Callback)
  first type mismatch at position: 2
  required type: Fl_Callback
  but expression 'ButtonClick' is of type: proc (button: ptr Fl_Widget, 
arg: ptr GenericParam): cint{.cdecl.}

expression: Fl_WidgetSetCallback(cast[ptr Fl_Widget](Btn), ButtonClick)


Run

elif I use 


Fl_WidgetSetCallback(cast[ptr Fl_Widget](Btn), 
cast[Fl_Callback](ButtonClick))


Run

I get 


a.nim(47, 53) Error: cannot cast to a non concrete type: 'Fl_Callback'


Run

Please, can anyone give clear help? Thanks