The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: m0nk3yi3unz on July 07, 2009, 12:21:53 AM

Title: Callback functions
Post by: m0nk3yi3unz on July 07, 2009, 12:21:53 AM
Hey all. I'm looking into the function WaveInOpen, and say it required a callback function.

I know what they are from my C# knowledge, however I have -no- idea how to implement them in MASM. I've googled everywhere but, not surprisingly, I found nothing. :/

Any help?

MSDN page: http://msdn.microsoft.com/en-us/library/ms913593.aspx


Cheers!

-Monkey
Title: Re: Callback functions
Post by: dedndave on July 07, 2009, 12:40:32 AM
if you look in the masm32 examples folder, there are many programs that use them
Title: Re: Callback functions
Post by: hutch-- on July 07, 2009, 04:31:47 AM
Monkey,

Ther basics of a callback are the arguments required and the return value if any along with a returned address in intercept style callbacks like controls. Usually Microsoft will publish the argument list with its corresponding dayta sizes so you lay out the bare callback in the form they publish.

If for example a callback has 3 DWORD sized arguments and requires a return value of 0 to terminate it you would lay it out something like this.


MyCallBack proc arg1:DWORD,arg2:DWORD,arg3:DWORD

    ; write the processing code here

    .if (terminating_condition) != 0
      xor eax, eax
      ret
    .endif

    ret

MyCallBack endp


Title: Re: Callback functions
Post by: m0nk3yi3unz on July 07, 2009, 04:46:06 AM
@dedndave - OH wow! xDD I didn't even know there was an examples folder. xD I'll definitely be looking at that (I've never noticed since I use RadASM).

Thanks for the tip :)

@hutch - ah, I see now. Thanks for that! It makes sense :)

-Monkey
Title: Re: Callback functions
Post by: BlackVortex on July 07, 2009, 05:21:47 AM
Also remember about register preservation.
Title: Re: Callback functions
Post by: ToutEnMasm on July 07, 2009, 07:02:33 AM

Usefull is the MMSystem.sdk. I think you can add it to the windows.inc , include the translate.inc first.

The callback function isn't define in the msdn help (your link.There is a choose to made with constants values.
The MMSystem defines only two callback functions.
The sdk defines allways callback prototypes with callback in there names.
Result is:
Quote
DRVCALLBACK PROTO :DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD
TIMECALLBACK PROTO :DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD
Perhaps a sample in c++ will help you to made choices ?.




Title: Re: Callback functions
Post by: m0nk3yi3unz on July 07, 2009, 04:57:17 PM
@BlackVortex - Thanks, will do :)

@ToutEnMasm - Thanks, I'll definitely look it up. The whole MM process contains a lot of steps :X this SDK should be rewarding.

Thanks for all of the support guys!