assemblyx86fasm

FASM 64 bit exception on call winmm.dll


Calling any function from winmm.dll causes an exceptional error (0xc0000005).

format PE64 GUI 5.0

entry start

include 'win64a.inc'

section '.code' code readable executable 
start: 
 invoke mixerGetNumDevs 
 invoke ExitProcess

section '.idata' import data readable 
library kernel, 'kernel32.dll', wmm, 'winmm.dll'
import kernel, ExitProcess, 'ExitProcess'
import wmm, mixerGetNumDevs, 'mixerGetNumDevs' 

If compiled in 32-bit mode, then everything works. What's wrong?


Solution

  • I answer my own question: when starting the program, you need to align the stack: sub rsp, 08h, which was not done.

    start:
     sub rsp, 08h
     invoke mixerGetNumDevs 
     invoke ExitProcess