Oxygen Basic
Programming => Problems & Solutions => Topic started by: Emil_halim on April 22, 2013, 11:37:45 AM
-
Hi all
can any one show me a working example of callback function system in oxygen.
and how can i declare import function that accept a function pointer (the callback).
-
Do you want to see that in single or multi-threaded?
Sorry Charles, I couldn't resist. :D
-
Oh , it seems i am willing leave this forum.
BTW this is the first forum seeing it's members are so funny and not serious.
-
That was a big Thank You to Charles for his multi-threading and shared callback work with DLLC and not a response to your question. Sorry Emil.
-
no problem John,
but it hurts my alot.
-
Emil ..do you mean callback like this:
'gui-skeleton app
Include "awinh.inc"
#lookahead
INT win,win2
INT x,y,w,h,x2,y2,w2,h2
x=0:y=10:w=400:h=400
x2=410:y2=10:w2=400:h2=300
INT winstyle,wstyle2
winstyle = WS_MINMAXSIZE or WS_CLIPCHILDREN
wstyle2 = WS_MINMAXSIZE or WS_CLIPCHILDREN
INT b0ID = 100
'############################################
print "WIN:" +str(win)
'############################################
'create window **************************************************
win = SetWindow("Skeleton App",x,y,w,h,0,winstyle)
print "WIN:" +str(win)
'create button on win
button0 = SetButton(win,80,4,80,26,"Close Win2",0x50000000,0x200,b0ID)
'create second window
win2 = SetWindow("New Window",x2,y2,w2,h2,0,winstyle)
print "WIN2:" +str(win2)
'****************************************************************
'/////////
Wait()
'\\\\\\\\\
Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback
SELECT hwnd
'----------------------------------------
CASE win
'----------------------------------------
Select wmsg
CASE WM_CLOSE
DestroyWindow win
MsgBox "Quit...","End program!"
PostQuitMessage 0
CASE WM_COMMAND
controlID = LoWord(wParam) 'get control ID
notifyCode = HiWord(wParam) 'get notification message
Select controlID
CASE b0ID
If notifycode=0
MsgBox "Close New Window!","To Win2"
CloseWindow(win2)
End If
End Select
End select
'----------------------------------------
CASE win2
'-----------------------------------------
Select wmsg
CASE WM_CLOSE
DestroyWindow win2
MsgBox "Win2 Closed!","WIN2"
End select
END SELECT
RETURN Default
END FUNCTION
or something else ?
-
Yes, wndproc is one example of a callback.
A more generalised form might look like this:
function cbk(sys v) as sys , callback
...
return -1
end function
the address of the callback function is then @cbk
SetCallBackFunction("type spec",@cbk)
Callbacks are automatically extern, but if they are expected to be cdecl then that must be made explicit.
-
thanks you Aurel & Charles,
actually the callback function will be in the exe file , then i have to pass it's address to an import function
in dll , so how to declare the import function.
-
On the other (usually the DLL) side:
extern
! SendCallBackA(sys v)
! SendCallBackB(sys v)
...others
extern export
function SetCallBackFunction(char*spec,sys f)
...
@sendcallbackA=f
...
end function
end extern
if @SendCallBackA then SendCallBackA 42
Charles