%include "dll_names.inc"

%ifdef DIGITALMARS
                    group FLAT _TEXT _DATA
    ; DM is otherwise same as Borland:
    %define BORLAND 1
%endif

                    global __imp__PlaySoundW@12
                    global PlaySoundW
                    global _PlaySoundW@12
                    global _Unicows_PlaySoundW
                  
                    extern _LoadUnicowsSymbol

%ifdef BORLAND
                    section  _TEXT class=CODE code  use32
%else
                    section .text
%endif

unicows_initial_stub_PlaySoundW:
                    ; Load the symbol...
                    pusha
                    push dword __imp__PlaySoundW@12     ; place to save the pointer
                    push dword [_Unicows_PlaySoundW]      ; default proc, if any
                    push dword WINMM                  ; dll id
                    push dword namestring_PlaySoundW      ; name of the function
                    call _LoadUnicowsSymbol
                    add  esp,byte 16
                    popa

                    ; ...and skip to it (see following jmp instruction):

PlaySoundW:
_PlaySoundW@12:
                    jmp [__imp__PlaySoundW@12]

%ifdef BORLAND
                    section  _DATA class=DATA data use32
%else
                    section .data
%endif

__imp__PlaySoundW@12:   dd unicows_initial_stub_PlaySoundW
_Unicows_PlaySoundW:      dd 0
namestring_PlaySoundW:    db 'PlaySoundW',0
