Using the FMOD API with MASM – Part 2/3

I can’t understand why people are frightened of new ideas. I’m frightened of the old ones. — John Cage

Prototyping the functions

For this little project the way used above might be good enough. When dealing with larger projects it would be nice to be able to use MASMs inherent function wrapper which makes for a lot cleaner code. To be able to do that we need to first prototype the function:


As we know (from the FMOD help file), the function FSOUND_Init needs three parameters passed. The code line above creates a function prototype with 3 parameters. Now we need to define the function. Basically we do the same we did in our first example, only that we call LoadLibraryA once at the beginning of the code (to get the handle to the “fmod.dll”) and then make the FMOD functions call GetProcAddress from within our new function, to get the address of the function we need to call:

; === FSOUND_Init(mixrate,maxsoftwarechannels,FLAGS) ===
FSOUND_Init proc param1:DWORD, param2:DWORD, param3:DWORD
     ; get the  procedure adress of FSOUND_Init
     invoke GetProcAddress, DllHandle, addr FSInit
     test eax, eax              ; check if returned handle exists
     je Error
     push param3                ; push FLAGS (none)
     push param2                ; push maxsoftwarechannels
     push param1                ; push mixrate
     call eax                   ; call FSOUND_Init
FSOUND_Init endp

Now we can invoke the function in our main loop:

invoke FSOUND_Init, 44100, 32, 0

That is all there is to it. Feel free to download the archive:


VN:F [1.9.18_1163]
Rating: 0.0/5 (0 votes cast)
Thursday, January 29th, 2009 at 14:41
85 visits
  • Feb 8th, 2009 at 19:14 | #1

    People tell me that the executable aint working – they get the error-message “The file could not be found!” Note: this is on purpose! As I do mention in the readme.txt there is no “*.mod” file included in the archive (for copyright reasons). So you will need to download or create your own .mod file, rename it “modname.mod” if you dont want to recompile the source and copy it into the folder where the executable is located.

    VN:F [1.9.18_1163]
    Rating: 0.0/5 (0 votes cast)

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>