Using this code (mostly just added the irvine32.inc to the github code here: https://gist.github.com/michaellindahl/7782978

TITLE MASM PlaySound                        (PlaySoundExample.asm)

includelib winmm.lib
INCLUDE Irvine32.inc
INCLUDE macros.inc
PlaySound PROTO,
        pszSound:PTR BYTE, 
        hmod:DWORD, 
        fdwSound:DWORD

.data
deviceConnect BYTE "DeviceConnect",0
SND_ALIAS    DWORD 00010000h
SND_RESOURCE DWORD 00040005h
SND_FILENAME DWORD 00020000h
file BYTE "t.wav",0

.code
main PROC
     INVOKE PlaySound, OFFSET deviceConnect, NULL, SND_ALIAS
     INVOKE PlaySound, OFFSET file, NULL, SND_FILENAME

    exit
main ENDP
END main
1

There are 1 best solutions below

5
On

You need to add SND_ASYNC flag additionally.

The sound is played asynchronously and PlaySound returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, call PlaySound with pszSound set to NULL.

In MASM32, you need to OR their binary bits, so your function arg has both bits set like SND_ASYNC | SND_FILENAME in C.

#define SND_ASYNC           0x0001 
#define SND_FILENAME    0x00020000L

Code Sample:

.model flat, stdcall
option casemap: none

include windows.inc
include kernel32.inc
include user32.inc

includelib kernel32.lib
includelib user32.lib
includelib Winmm.lib

PlaySoundA PROTO,
        pszSound:PTR BYTE, 
        hmod:DWORD, 
        fdwSound:DWORD

.data
file BYTE "t.wav",0

szCaption   db  "Hello", 0
szText      db  "Hello World!", 0

.code
main PROC
     INVOKE PlaySoundA, OFFSET file, NULL, 20001H      ; SND_ASYNC | SND_FILENAME
     INVOKE MessageBox, NULL, addr szText, addr szCaption, MB_OK
     INVOKE ExitProcess, 0
main ENDP

END main