Author Topic: callback function  (Read 2532 times)

0 Members and 1 Guest are viewing this topic.

Emil_halim

  • Guest
callback function
« 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).

JRS

  • Guest
Re: callback function
« Reply #1 on: April 22, 2013, 11:50:45 AM »
Do you want to see that in single or multi-threaded?

Sorry Charles, I couldn't resist.  :D

Emil_halim

  • Guest
Re: callback function
« Reply #2 on: April 22, 2013, 12:07:05 PM »

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.

JRS

  • Guest
Re: callback function
« Reply #3 on: April 22, 2013, 12:21:43 PM »
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.
« Last Edit: April 22, 2013, 06:29:50 PM by JRS »

Emil_halim

  • Guest
Re: callback function
« Reply #4 on: April 22, 2013, 12:26:55 PM »

no problem John,

but it hurts my alot.

Aurel

  • Guest
Re: callback function
« Reply #5 on: April 22, 2013, 12:48:20 PM »
Emil ..do you mean callback like this:
Code: [Select]
'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 ?

Charles Pegge

  • Guest
Re: callback function
« Reply #6 on: April 22, 2013, 02:01:08 PM »
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.

Emil_halim

  • Guest
Re: callback function
« Reply #7 on: April 22, 2013, 10:00:37 PM »
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.

Charles Pegge

  • Guest
Re: callback function
« Reply #8 on: April 23, 2013, 12:52:20 AM »
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
« Last Edit: April 23, 2013, 12:58:55 AM by Charles Pegge »