flat assembler
Message board for the users of flat assembler.

Index > Windows > Another Resource Question ?

Author
Thread Post new topic Reply to topic
Spidark



Joined: 11 May 2005
Posts: 39
Spidark
Hello 2 all.
Let me clear this first.
Yes i have looked around on this and other forum for a solution but i still can't get it to work.
http://board.flatassembler.net/topic.php?t=2949
and also http://board.flatassembler.net/topic.php?t=568
Also the google thing, yes ...
But i think help is here.

Ok.
I'm trying to play a wav file from a resource file, but without succes.
I keep getting INVALID RESOURCE NAME (debugger).
Ive read
So i throw my towell in the ring for a moment to breathe a little.
Can some one tell me what the ^$%$% i'm doing wrong here.
Rolling Eyes
here's a piece of the code.

Code:
proc    ON_CREATE,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
        
        ;invoke FindResource,[hInstance],01,RT_RCDATA
        ;jz     .ERROR_DETECTED
        ;invoke LoadResource,[hInstance],eax
        ;mov [hData01],eax

        ;DOES NOT WORK
        
        ;invoke  FindResource,[hInstance],resName,RT_RCDATA
        ;jz     .ERROR_DETECTED
        ;invoke          LoadResource, [hInstance],eax
        ;invoke  LockResource, eax 
        
        ;DOES NOT WORK
        invoke PlaySound,resName,[hInstance],40005h    ; SND_RESOURCE+SND_ASYNC
        jmp     .SOUND_RUNNING
        ; Show error and continue
.ERROR_DETECTED:
        invoke  MessageBoxEx,[hWnd],errText1,messCap,MB_OK,0
        
.SOUND_RUNNING:
                ;invoke FreeResource,eax
        invoke CreateWindowEx,\
                0,\
                butClsName,\
                butName,\
                WS_VISIBLE or WS_CHILD,\
                10,\ 
                20,\ 
                80,\ 
                35,\ 
                [hWnd],\ 
                EXIT_BUTTON,\ 
                [hInstance],\ 
                0
            
        mov     [hWndButton],eax
        invoke  SetTimer,[hWnd],1,8000,0
        
        pop     ebx esi edi
        ;jmp    .EXIT_CR        
                
.EXIT_CR:       
        return
endp
    

I have been compiling the RC files with GORC| RC and FASM itself, all give the same problems.
So i think i'm the one doing it wrong.
This is how my externel RC file looks like.
Code:
IDW_MYSOUND RT_DCDATA "Data_1.wav"    


Here's how it looks in FASM file itself.
Code:
;section '.rsrc' resource from 'w.res' data readable

;section '.rsrc' data readable resource from 'w.res'

section '.rsrc' resource data readable
directory RT_RCDATA, files

resource files,01, LANG_NEUTRAL, MyText

fileres MyText, 'Data_1.wav'
    

Mayday Mayday.
Post 15 May 2005, 17:17
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1608
Location: Ukraine
shoorick
ones i've been inserting wav in rc:

Code:
1444 WAVE DISCARDABLE "shotgn2.wav"
    


and play it with this:
Code:
invoke PlaySound,1444,[hInstance],SND_RESOURCE; or SND_ASYNC    

nothing more. i just did not yet resource section with fasm macros - it was usual rc, compiled with masm' rc.exe
Post 16 May 2005, 14:28
View user's profile Send private message Visit poster's website Reply with quote
Spidark



Joined: 11 May 2005
Posts: 39
Spidark
shoorick wrote:
ones i've been inserting wav in rc:

Code:
1444 WAVE DISCARDABLE "shotgn2.wav"
    


and play it with this:
Code:
invoke PlaySound,1444,[hInstance],SND_RESOURCE; or SND_ASYNC    

nothing more. i just did not yet resource section with fasm macros - it was usual rc, compiled with masm' rc.exe

Yes your right this works well.
I hope someone could post another (WORKING) example on how to do this with FASM
Code:
section '.rsrc' resource data readable
directory RT_RCDATA, files
resource files,3000, LANG_NEUTRAL,MyWav
fileres MyWav, 'Data_1.wav'
    

FindResource Keeps giving me RESOURCE NOT FOUND ERROR.
No matter what i do.
If there's anybody who got this working with wav files Post it please.
Thanks Shoorick.
Post 16 May 2005, 15:21
View user's profile Send private message Reply with quote
Torrey



Joined: 12 Oct 2003
Posts: 78
Torrey
If possible can you post your source code? It makes debugging and bug checking easier on everyone that wants to help out.
Post 17 May 2005, 04:15
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1608
Location: Ukraine
shoorick
maybe it has to be placed not just like a file, but as some "WAVE" entry (as well as icon or bitmap) - just not ready such macro yet in resource.inc... i'm just not enough familiar with resource section structure to do this...
Post 17 May 2005, 05:53
View user's profile Send private message Visit poster's website Reply with quote
Spidark



Joined: 11 May 2005
Posts: 39
Spidark
Torrey wrote:
If possible can you post your source code? It makes debugging and bug checking easier on everyone that wants to help out.

Ok Torrey Here's the Code It's real Messy because there 2 version in one code.
So i hope you can make something out of it.
I would like to know where to find this information on how to implement ressource scrpits using plain FASM ( can't find this info anywhere).
Putting only one wav file is understandeble, but how do you do this if you have a wavefile a bitmap and xml.
I know how to do this for only one but how do you do this for all tree.
Greettzzz..

Code:
format PE GUI 4.0
entry start
SND_RESOURCE            equ     40004h
SND_ASYNC               equ     00001h
SND_NODEFAULT           equ     00002h 
EXIT_BUTTON             equ     1001h
MESS_BUTTON             equ     1002h
SND_LOOP                equ     0008h
AW_HIDE                 equ   00010000h
AW_BLEND                equ    00080000h
;IDB_BITMAP             equ     4000
START_MUSIC_TIMER       equ     1

include "c:\fasm\bin\include\Win32a.inc"

section '.data' data readable writeable
        hWnd            dd      ?
        hInstance       dd      ?
        hBitmap         dd      ?
        hWndButton      dd      ?

        wTitle          db      'WAV XML AND a BITMAP in A RESOURCE FILE',0 ;name of our window
        wcName          db      'WAVXMLBITMAP_Class',0      ;name of our window class
        msg                             MSG
        wc                              WNDCLASS
        errText         db      "Sorry but an ERROR was Detected Press OK to Shutdown.",0
        errText1        db      "Warning :Api resource Function returned an error.",0
        cYah            db      "cYah Later ",0
        messCap         db      "Message",0
        butClsName      db      "BUTTON",0
        butName         db      "E&xit",0
        exitText2       db      "YOU PRESSED THE BIG EXIT ---> Really Exit the Program ? ",0
        Win_Width       dd      800
        Win_Height      dd      600
        myText          db      "CONTINUE or EXIT ?",0
        lpText          db      "RESOURCE ERROR",0
        resourceName    db      "resName",0
section '.code' code readable executable


start:
                ;  registering the window class
        call    [InitCommonControls]     
        invoke  GetModuleHandle,NULL
        mov     [hInstance],eax
        mov     [wc.hInstance],eax
        mov     [wc.style],CS_HREDRAW or CS_VREDRAW
        mov     [wc.lpfnWndProc],WndProc
        mov     [wc.lpszClassName],wcName
        mov     [wc.hbrBackground],COLOR_WINDOW+1
        invoke  LoadIcon,NULL,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke   LoadCursor,NULL,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc




        ; creating the main window 
        invoke    CreateWindowEx,0,\
                         wcName,\
                         wTitle,\
                         WS_OVERLAPPEDWINDOW and (not ( WS_SIZEBOX or WS_MAXIMIZEBOX)),\
                         0,\
                         0,\
                         [Win_Width],\
                         [Win_Height],\
                         NULL,\
                         NULL,\
                         [hInstance],\
                         NULL
                         
                    mov  [hWnd],eax
                        
        invoke  MessageBoxEx,[hWnd],myText,messCap,MB_YESNO or MB_OK,0
        cmp     eax,IDNO
        jne     .ID_YES
        invoke  ExitProcess,0
.ID_YES:
       
        invoke  AnimateWindow, [hWnd],900,AW_BLEND
        invoke  ShowWindow,[hWnd],SW_SHOW
          ; | entering the message loop |
MSG_LOOP:
        invoke    GetMessage,msg,NULL,0,0
        or   eax,eax
        jz   END_LOOP
        invoke    TranslateMessage,msg
        invoke    DispatchMessage,msg
        jmp  MSG_LOOP
END_LOOP:
        invoke  MessageBoxEx,[hWnd],errText,messCap,MB_OK or MB_ICONSTOP 
        invoke  ExitProcess,0



WndProc:
        mov     eax,dword [esp+8]
        ;cmp    eax,WM_PAINT
        ;je     ON_PAINT
        cmp     eax,WM_DESTROY
        je      ON_DESTROY
        cmp     eax,WM_CREATE
        je      ON_CREATE
        cmp     eax,WM_TIMER
        je      ON_TIMER
        cmp     eax,WM_COMMAND
        je      ON_COMMAND
        jmp     DEFWIN
        
;proc   ON_PAINT,hWnd,uMsg,wParam,lParam
        ;ps     PAINTSTRUCT
        ;enter
        ;push   edi esi ebx                     ; save Regs
        ;lea    ebx,[ps]                        ; get adress addres of ps
        ;invoke BeginPaint,[hWnd],ebx           ; call API
        ;mov    edi,eax                         ; edi = HDC
        ;invoke CreateCompatibleDC,edi          ; Create Mem HDC
        ;mov    esi,eax                         ; save HDCMEM in edi 
        ;invoke SelectObject,esi,[hBitmap]      ; Select object in HDCMEM

        ;invoke BitBlt,edi,0,0,280,292,\        ; Copy it into HDC
        ;              esi,0,0,SRCCOPY

        ;invoke DeleteDC,esi                    ;Delete HDCMEM
        ;invoke EndPaint,[hWnd],ebx             ;Stop painting
        ;pop    ebx esi edi
        ;return
;endp

proc    ON_TIMER,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
; Wait a few seconds and then play the sound in loop mode
; WORKING VERSION-------------------------------------------------------------
        ;invoke  PlaySound,3000,[hInstance],SND_RESOURCE or SND_ASYNC or SND_LOOP
        ;cmp    eax,FALSE
; NOT WORKING VERSION --------------------------------------------------------
        ;push   resourceName
        ;call   PlayResource
        ;jz     .ERROR_DETECTED

        invoke  FindResource,[hInstance],01,RT_RCDATA 
        jz      .ERROR_DETECTED
      
        ;// Load the WAVE resource. 
 
        invoke  LoadResource,[hInstance],eax                    ; eax HOLDS RESOURCE INFO
        jz      .ERROR_DETECTED  
         
 
        ;// Lock the WAVE resource and play it. 
 
        invoke LockResource,eax                         ; eax Holds
        jz      .ERROR_DETECTED
       
        invoke PlaySound,eax,SND_RESOURCE or SND_ASYNC or SND_LOOP 
        
.ERROR_DETECTED:
        invoke  MessageBoxEx,[hWnd],errText1,messCap,MB_OK,0
.SAJONARA: 
        invoke  KillTimer,[hWnd],START_MUSIC_TIMER
        pop     ebx esi edi
        return
endp
        
proc    DEFWIN,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
        invoke    DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
        pop     ebx esi edi
        return
endp

proc    ON_DESTROY,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
        invoke   KillTimer,[hWnd],START_MUSIC_TIMER ; Don't know if this is Needed here ??????
        invoke   PostQuitMessage,0
        pop     ebx esi edi
        return
endp


proc    ON_COMMAND,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
        cmp     dword [wParam],EXIT_BUTTON
        jne     .SAJONARA
.BUTTON_ID:
        cmp  byte [wParam+2],0  ;BN_CLICKED = 0
        jne     .SAJONARA
.BUT_CLICKED:
         invoke  SendMessage,[hWnd],WM_CLOSE,0,0
.SAJONARA:        
        pop     ebx esi edi     
        return
endp

proc    ON_CREATE,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
;------------- LOAD THE BITMAP FROM RESOURCE WORKING VERSION
        ;invoke LoadBitmap,[hInstance],4000
        ;mov    [hBitmap],eax

;------------- CREATE A BUTTON
        invoke CreateWindowEx,\
                0,\
                butClsName,\
                butName,\
                WS_VISIBLE or WS_CHILD,\
                10,\ 
                20,\ 
                80,\ 
                35,\ 
                [hWnd],\ 
                EXIT_BUTTON,\ 
                [hInstance],\ 
                0
            
        mov     [hWndButton],eax                                ; save the BUTT HANDLE
        
        invoke  SetTimer,[hWnd],1,3000,0

        pop     ebx esi edi
        
        return
endp


proc PlayResource,resName
  ; .llpText    db      "hello",0
  ; .lmessCap   db      " Proc Message ",0
  ; CHECK HOW THS WORKS
        push    ebx esi edi
    ;// Find the WAVE resource. 
 
        enter
        lea     edi,[resName]
        invoke  FindResource,[hInstance],edi,RT_RCDATA 
        jz      .ERROR_DETECTED
      
        ;// Load the WAVE resource. 
 
        invoke  LoadResource,[hInstance],eax                    ; eax HOLDS RESOURCE INFO
        jz      .ERROR_DETECTED  
         
 
        ;// Lock the WAVE resource and play it. 
 
        invoke LockResource,eax                         ; eax Holds
        jz      .ERROR_DETECTED
       
        invoke PlaySound,eax,SND_RESOURCE or SND_ASYNC or SND_LOOP 
     ;   invoke sndPlaySound,eax,SND_RESOURCE or SND_ASYNC or SND_LOOP 

        
        
.ERROR_DETECTED:
        ; THIS SHIT IS NOT WORKING STIL TO DO
        ;invoke MessageBoxEx,NULL,.llpText,.messCap,MB_OK,0 
        mov     eax,0                                           ; Return NULL for ERROR
        pop     edi esi ebx
        return
.CLEAN_EXIT:
        mov     eax,-1                                          ; Indicating SUCCES
        pop     edi esi ebx
        return
endp


section '.idata' import data readable writeable
        library KERNEL32, 'KERNEL32.DLL',\
                USER32,   'USER32.DLL',\
                comctl32, 'CoMcTl32.DlL',\
                winmm,    'winmm.dll',\
                gdi32,    'gdi32.dll'   

        import  KERNEL32,\
               GetModuleHandle,         'GetModuleHandleA',\
               ExitProcess,             'ExitProcess',\
               FindResource,            'FindResourceA',\
               LoadResource,            'LoadResource',\
               LockResource,            'LockResource',\
               FreeResource,            'FreeResource'
               

        import USER32,\
               RegisterClass,           'RegisterClassA',\
               CreateWindowEx,          'CreateWindowExA',\
               DefWindowProc,           'DefWindowProcA',\
               ShowWindow,              'ShowWindow',\
               LoadCursor,              'LoadCursorA',\
               LoadIcon,                'LoadIconA',\
               GetMessage,              'GetMessageA',\
               TranslateMessage,        'TranslateMessage',\
               DispatchMessage,         'DispatchMessageA',\
               PostQuitMessage,         'PostQuitMessage',\
               MessageBoxEx,            'MessageBoxExA',\
               MessageBeep,             'MessageBeep',\
               SetTimer,                'SetTimer',\
               KillTimer,               'KillTimer',\
               SendMessage,             'SendMessageA',\
               AnimateWindow,           'AnimateWindow',\
               GetWindowRect,           'GetWindowRect',\
               GetDesktopWindow,        'GetDesktopWindow',\
               MoveWindow,              'MoveWindow',\
               GetSystemMetrics,        'GetSystemMetrics',\
               EndPaint,                'EndPaint',\
               BeginPaint,              'BeginPaint',\
               LoadBitmap,              'LoadBitmapA'
        import  comctl32,\
               InitCommonControls,      'InitCommonControls'
        import  winmm,\
               PlaySound,               'PlaySound'
        import  gdi32,\
                CreateCompatibleDC,     'CreateCompatibleDC',\
                BitBlt,                 'BitBlt',\
                DeleteDC,               'DeleteDC',\
                SelectObject,           'SelectObject'
               
;section '.rsrc' resource from 'w.res' data readable



section '.rsrc' resource data readable

directory RT_RCDATA,resName
         
resource resName,01, LANG_NEUTRAL,soundfile 


fileres soundfile , 'Data_1.wav'
    
Post 17 May 2005, 21:04
View user's profile Send private message Reply with quote
Torrey



Joined: 12 Oct 2003
Posts: 78
Torrey
Sorry I didn't clean up the code for you. But the main thing is that it works now. There was 1 thing I found wrong, the PlaySound api, I changed it to sndPlaySoundA.
Code:
format PE GUI 4.0
entry start
SND_RESOURCE            equ     40004h
SND_ASYNC               equ     00001h
SND_NODEFAULT           equ     00002h
EXIT_BUTTON             equ     1001h
MESS_BUTTON             equ     1002h
SND_LOOP                equ     0008h
SND_MEMORY              equ     4
AW_HIDE                 equ   00010000h
AW_BLEND                equ    00080000h
;IDB_BITMAP             equ     4000
START_MUSIC_TIMER       equ     1

include "%fasminc%\Win32a.inc"

section '.data' data readable writeable
        hWnd            dd      ?
        hInstance       dd      ?
        hBitmap         dd      ?
        hWndButton      dd      ?

        wTitle          db      'WAV XML AND a BITMAP in A RESOURCE FILE',0 ;name of our window
        wcName          db      'WAVXMLBITMAP_Class',0      ;name of our window class
        msg                             MSG
        wc                              WNDCLASS
        errText         db      "Sorry but an ERROR was Detected Press OK to Shutdown.",0
        errText1        db      "Warning :Api resource Function returned an error.",0
        cYah            db      "cYah Later ",0
        messCap         db      "Message",0
        butClsName      db      "BUTTON",0
        butName         db      "E&xit",0
        exitText2       db      "YOU PRESSED THE BIG EXIT ---> Really Exit the Program ? ",0
        Win_Width       dd      800
        Win_Height      dd      600
        myText          db      "CONTINUE or EXIT ?",0
        lpText          db      "RESOURCE ERROR",0
        resourceName    db      "resName",0
section '.code' code readable executable


start:
        ;  registering the window class
        call    [InitCommonControls]
        invoke  GetModuleHandle,NULL
        mov     [hInstance],eax
        mov     [wc.hInstance],eax
        mov     [wc.style],0 ;CS_HREDRAW or CS_VREDRAW
        mov     [wc.lpfnWndProc],WndProc
        mov     [wc.lpszClassName],wcName
        mov     [wc.hbrBackground],COLOR_BTNFACE+1
        mov     [wc.cbClsExtra],0
        mov     [wc.cbWndExtra],0
        mov     [wc.lpszMenuName],0
        invoke  LoadIcon,NULL,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke   LoadCursor,NULL,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc

        ; creating the main window
        invoke    CreateWindowEx,0,wcName,wTitle,WS_OVERLAPPEDWINDOW and (not ( WS_SIZEBOX or WS_MAXIMIZEBOX)),0,0,\
                         [Win_Width],[Win_Height],NULL,NULL,[hInstance],NULL
        mov  [hWnd],eax

        invoke  MessageBoxEx,[hWnd],myText,messCap,MB_YESNO or MB_OK,0
        cmp     eax,IDNO
        jne     .ID_YES
        invoke  ExitProcess,0

.ID_YES:

        invoke  AnimateWindow, [hWnd],900,AW_BLEND
        invoke  ShowWindow,[hWnd],SW_SHOW
        ; | entering the message loop |
MSG_LOOP:
        invoke    GetMessage,msg,NULL,0,0
        or   eax,eax
        jz   END_LOOP
        invoke    TranslateMessage,msg
        invoke    DispatchMessage,msg
        jmp  MSG_LOOP
END_LOOP:
        invoke  MessageBoxEx,[hWnd],errText,messCap,MB_OK or MB_ICONSTOP
        invoke  ExitProcess,0

WndProc:
        mov     eax,dword [esp+8]
        cmp     eax,WM_DESTROY
        je      ON_DESTROY
        cmp     eax,WM_CREATE
        je      ON_CREATE
        cmp     eax,WM_TIMER
        je      ON_TIMER
        cmp     eax,WM_COMMAND
        je      ON_COMMAND
        jmp     DEFWIN

proc    ON_TIMER,hWnd,uMsg,wParam,lParam
        push    edi esi ebx

        invoke  FindResource,[hInstance],01,RT_RCDATA

        ;// Load the WAVE resource.

        invoke  LoadResource,[hInstance],eax                    ; eax HOLDS RESOURCE INFO

        ;// Lock the WAVE resource and play it.

        invoke LockResource,eax                         ; eax Holds

        invoke PlaySound,eax,SND_RESOURCE or SND_ASYNC or SND_LOOP
        jmp .SAJONARA

.ERROR_DETECTED:
        invoke  MessageBoxEx,[hWnd],errText1,messCap,MB_OK,0
.SAJONARA:
        invoke  KillTimer,[hWnd],START_MUSIC_TIMER
        pop     ebx esi edi
        return
endp

proc    DEFWIN,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
        invoke    DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
        pop     ebx esi edi
        return
endp

proc    ON_DESTROY,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
        invoke   KillTimer,[hWnd],START_MUSIC_TIMER ; Don't know if this is Needed here ??????
        invoke   PostQuitMessage,0
        pop     ebx esi edi
        return
endp


proc    ON_COMMAND,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
        cmp     dword [wParam],EXIT_BUTTON
        jne     .SAJONARA
.BUTTON_ID:
        cmp  byte [wParam+2],0  ;BN_CLICKED = 0
        jne     .SAJONARA
.BUT_CLICKED:
         invoke  SendMessage,[hWnd],WM_CLOSE,0,0
.SAJONARA:
        pop     ebx esi edi
        return
endp

proc    ON_CREATE,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
;------------- LOAD THE BITMAP FROM RESOURCE WORKING VERSION
        ;invoke LoadBitmap,[hInstance],4000
        ;mov    [hBitmap],eax

;------------- CREATE A BUTTON
        invoke CreateWindowEx,\
                0,\
                butClsName,\
                butName,\
                WS_VISIBLE or WS_CHILD,\
                10,\
                20,\
                80,\
                35,\
                [hWnd],\
                EXIT_BUTTON,\
                [hInstance],\
                0

        mov     [hWndButton],eax                                ; save the BUTT HANDLE

        invoke  SetTimer,[hWnd],1,3000,0

        pop     ebx esi edi

        return
endp


proc PlayResource,resName
  ; .llpText    db      "hello",0
  ; .lmessCap   db      " Proc Message ",0
  ; CHECK HOW THS WORKS
        push    ebx esi edi
    ;// Find the WAVE resource.

        enter
        lea     edi,[resName]
        invoke  FindResource,[hInstance],edi,RT_RCDATA
        jz      .ERROR_DETECTED

        ;// Load the WAVE resource.

        invoke  LoadResource,[hInstance],eax                    ; eax HOLDS RESOURCE INFO
        jz      .ERROR_DETECTED


        ;// Lock the WAVE resource and play it.

        invoke LockResource,eax                         ; eax Holds
        jz      .ERROR_DETECTED

        invoke PlaySound,eax,SND_RESOURCE or SND_ASYNC or SND_LOOP
     ;   invoke sndPlaySound,eax,SND_RESOURCE or SND_ASYNC or SND_LOOP



.ERROR_DETECTED:
        ; THIS SHIT IS NOT WORKING STIL TO DO
        ;invoke MessageBoxEx,NULL,.llpText,.messCap,MB_OK,0
        mov     eax,0                                           ; Return NULL for ERROR
        pop     edi esi ebx
        return
.CLEAN_EXIT:
        mov     eax,-1                                          ; Indicating SUCCES
        pop     edi esi ebx
        return
endp


section '.idata' import data readable writeable
        library KERNEL32, 'KERNEL32.DLL',\
                USER32,   'USER32.DLL',\
                comctl32, 'CoMcTl32.DlL',\
                winmm,    'winmm.dll',\
                gdi32,    'gdi32.dll'

        import  KERNEL32,\
               GetModuleHandle,         'GetModuleHandleA',\
               ExitProcess,             'ExitProcess',\
               FindResource,            'FindResourceA',\
               LoadResource,            'LoadResource',\
               LockResource,            'LockResource',\
               FreeResource,            'FreeResource'


        import USER32,\
               RegisterClass,           'RegisterClassA',\
               CreateWindowEx,          'CreateWindowExA',\
               DefWindowProc,           'DefWindowProcA',\
               ShowWindow,              'ShowWindow',\
               LoadCursor,              'LoadCursorA',\
               LoadIcon,                'LoadIconA',\
               GetMessage,              'GetMessageA',\
               TranslateMessage,        'TranslateMessage',\
               DispatchMessage,         'DispatchMessageA',\
               PostQuitMessage,         'PostQuitMessage',\
               MessageBoxEx,            'MessageBoxExA',\
               MessageBeep,             'MessageBeep',\
               SetTimer,                'SetTimer',\
               KillTimer,               'KillTimer',\
               SendMessage,             'SendMessageA',\
               AnimateWindow,           'AnimateWindow',\
               GetWindowRect,           'GetWindowRect',\
               GetDesktopWindow,        'GetDesktopWindow',\
               MoveWindow,              'MoveWindow',\
               GetSystemMetrics,        'GetSystemMetrics',\
               EndPaint,                'EndPaint',\
               BeginPaint,              'BeginPaint',\
               LoadBitmap,              'LoadBitmapA'
        import  comctl32,\
               InitCommonControls,      'InitCommonControls'
        import  winmm,\
               PlaySound,               'sndPlaySoundA'
        import  gdi32,\
                CreateCompatibleDC,     'CreateCompatibleDC',\
                BitBlt,                 'BitBlt',\
                DeleteDC,               'DeleteDC',\
                SelectObject,           'SelectObject'

;section '.rsrc' resource from 'w.res' data readable



section '.rsrc' resource data readable

directory RT_RCDATA,resName

resource resName,01, LANG_NEUTRAL,soundfile


fileres soundfile , 'Data_1.wav'    
Post 18 May 2005, 05:03
View user's profile Send private message Visit poster's website Reply with quote
Spidark



Joined: 11 May 2005
Posts: 39
Spidark
Torrey wrote:
Sorry I didn't clean up the code for you. But the main thing is that it works now. There was 1 thing I found wrong, the PlaySound api, I changed it to sndPlaySoundA.

Well Torrey, sorry 2 bother yah again but i'm past the FIND LOAD and LOCK RESOURCE FUNCTION.
I found out that i was not checking eax for a NULL, but just doing a JZ .ERROR_DETECTED after api call.( wich i think is not good)
But i'm still getting bunch of errors, check it out if you have the time, and tell me what i'm doing wrong here.
I commented out the calls made and right below the call you can see the error that the debugger reports on the call.( IN THE ERROR SECTION )
Thank you verry much upfront.

Code:
format PE GUI 4.0
entry start


SND_RESOURCE            equ     040004h
SND_ASYNC               equ     000001h
SND_NODEFAULT           equ     000002h 
SND_LOOP                equ     000008h


include "c:\fasm\bin\include\Win32a.inc"

section '.data' data readable writeable
        hWnd            dd   ?
        hInstance       dd   ?

        wTitle          db      "WAV FILE IN RESOURCE 3",0 ;name of our window
        wcName          db      "Wav_In_Res_Class",0      ;name of our window class
        msg             MSG
        wc              WNDCLASS
        errText         db      "Error Detected Program can not run on this machine!",0
        resErr          db      "A resource Functions returned a error",0
        myText          db      "Hello we Like assembly language don't we",0
        messCap         db      "Message",0
        resText         db      "resName",0
     
section '.code' code readable executable
        start:
                ;  registering the window class
                 
        invoke  GetModuleHandle,NULL
        mov     [hInstance],eax
        mov     [wc.hInstance],eax
        mov     [wc.style],CS_HREDRAW or CS_VREDRAW
        mov     [wc.lpfnWndProc],WndProc
        mov     [wc.lpszClassName],wcName
        mov     [wc.hbrBackground],COLOR_WINDOW+1
        invoke  LoadIcon,NULL,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke   LoadCursor,NULL,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc

        ; creating the main window 
        invoke    CreateWindowEx,\
                               0,\
                         wcName,\
                         wTitle,\
                         WS_OVERLAPPEDWINDOW ,\
                         CW_USEDEFAULT,\
                         CW_USEDEFAULT,\
                         CW_USEDEFAULT,\
                         CW_USEDEFAULT,\
                         NULL,\
                         NULL,\
                         [hInstance],\
                         NULL
                    mov  [hWnd],eax
        push    [hWnd]
        invoke    ShowWindow,[hWnd],SW_SHOW
          ; | entering the message loop |
MSG_LOOP:
        invoke    GetMessage,msg,NULL,0,0
        or   eax,eax
        jz   END_LOOP
        invoke    TranslateMessage,msg
        invoke    DispatchMessage,msg
        jmp  MSG_LOOP
END_LOOP:
        invoke  MessageBoxEx,[hWnd],errText,messCap,MB_OK or MB_ICONSTOP 
        invoke  ExitProcess,0


WndProc:
        cmp     dword [esp+8],WM_DESTROY
        je      ON_DESTROY
        cmp     dword [esp+8],WM_CREATE
        je      ON_CREATE
        jmp     DEFWIN
        

proc    ON_DESTROY,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
        invoke    PostQuitMessage,0
        pop     ebx esi edi
        return
endp



proc    ON_CREATE,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
                
        
        invoke  FindResource,[hInstance],01,RT_RCDATA 
        cmp     eax,0
        jz      .ERROR_DETECTED
      
        ;// Load the WAVE resource. 
 
        invoke  LoadResource,[hInstance],eax                    ; eax HOLDS RESOURCE INFO
        cmp     eax,0
        jz      .ERROR_DETECTED  
         
 
        ;// Lock the WAVE resource and play it. 
 
        invoke LockResource,eax                         ; eax Holds
        cmp     eax,0
        jz      .ERROR_DETECTED
 ;------------------------------------ERROR SECTION --------------------------------------      

;        invoke sndPlaySound,01,SND_RESOURCE or SND_ASYNC or SND_LOOP
         ;ERROR_RESOURCE_TYPE_NOT_FOUND (00000715)
        
        ;invoke sndPlaySound,resName,SND_RESOURCE or SND_ASYNC or SND_LOOP
         ;ERROR_RESOURCE_TYPE_NOT_FOUND (00000715)
 
        
        ;invoke sndPlaySound,resText,SND_RESOURCE or SND_ASYNC or SND_LOOP
         ;ERROR_RESOURCE_TYPE_NOT_FOUND (00000715)

        ;invoke PlaySound,resText, [hInstance]SND_RESOURCE or SND_ASYNC or SND_LOOP
        ; DOES NOT PLAY BUT GIVE AN ERROR SUCCES IN DEBUGGER BUT SET EAX TO 0
        
        ;invoke PlaySound,resName, [hInstance]SND_RESOURCE or SND_ASYNC or SND_LOOP
        ; SAME AS ABOVE EAX = NULL of FALSE BUT DOES NOT PLAY
        
        ;invoke PlaySound,01, [hInstance]SND_RESOURCE or SND_ASYNC or SND_LOOP
        ; SAME AS ABOVE
        
        ;invoke PlaySound,01, NULL,SND_RESOURCE or SND_ASYNC or SND_LOOP
        ;ERROR_RESOURCE_TYPE_NOT_FOUND (00000715)
        
;------------------------------------------- END ERROR SECTION -----------------------        
        cmp     eax,FALSE
        je      .ERROR_DETECTED
        jmp     .SAJONARA
.ERROR_DETECTED:
        invoke  MessageBoxEx,[hWnd],resErr,messCap,MB_OK,0
.SAJONARA:
        pop     ebx esi edi
        return
endp

proc    DEFWIN,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
        invoke    DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
        pop     ebx esi edi
        return
endp



section '.idata' import data readable writeable
        library KERNEL32, 'KERNEL32.DLL',\
                USER32,   'USER32.DLL',\
                winmm,    'WINMM.DLL'

        import  KERNEL32,\
               GetModuleHandle,         'GetModuleHandleA',\
               ExitProcess,             'ExitProcess',\
               FindResource,            'FindResourceA',\
               LoadResource,            'LoadResource',\
               LockResource,            'LockResource',\
               FreeResource,            'FreeResource'
        import USER32,\
               RegisterClass,           'RegisterClassA',\
               CreateWindowEx,          'CreateWindowExA',\
               DefWindowProc,           'DefWindowProcA',\
               ShowWindow,              'ShowWindow',\
               LoadCursor,              'LoadCursorA',\
               LoadIcon,                'LoadIconA',\
               GetMessage,              'GetMessageA',\
               TranslateMessage,        'TranslateMessage',\
               DispatchMessage,         'DispatchMessageA',\
               PostQuitMessage,         'PostQuitMessage',\
               MessageBoxEx,            'MessageBoxExA'
import  winmm,\
               PlaySound,               'PlaySoundA',\
               sndPlaySound,            'sndPlaySoundA'
; PlaySound,            'sndPlaySoundA',\
;section '.rsrc' resource from 'wavres.res' data readable
section '.rsrc' resource data readable

directory RT_RCDATA,resName
         
resource resName,01, LANG_NEUTRAL,soundfile 


fileres soundfile , 'data_1.wav'
    
Post 18 May 2005, 19:32
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Hello Spidark,
I decided to fiddle around with your program and came up with an alternate solution to your problem, Instead of using resources, use a memory pointer. This would be easier than trying to define a sound resource, or multiple sound resources for that matter. In the data section, where the "noise:" variable is you can change the wav file back to your's. also may have to change the include directories also. Cleaned up the source a little too.
Here's the source

Code:
format PE GUI 4.0
entry WinMain

include '%fasminc%\win32a.inc'
include '%fasminc%\macro\if.inc'

SND_RESOURCE            equ     040004h
SND_ASYNC               equ     000001h
SND_NODEFAULT           equ     000002h
SND_LOOP                equ     000008h
SND_ALIAS_ID            = $110000 ;alias is a predefined ID
SND_MEMORY = 4  ;pszSound points to a memory file

section '.data' data readable writeable
        msg             MSG
        wc              WNDCLASS

        hWnd            dd   ?
        hInstance       dd   ?

        wTitle          db      "WAV FILE IN RESOURCE 3",0 ;name of our window
        wcName          db      "Wav_In_Res_Class",0      ;name of our window class
        errText         db      "Error Detected Program can not run on this machine!",0
        resErr          db      "A resource Functions returned a error",0
        myText          db      "Hello we Like assembly language don't we",0
        messCap         db      "Message",0
        resText         db      "resName",0

noise:
     file 'av037.wav'

section '.code' code readable executable

proc WinMain, hInstance, hPrevInstance, szCmdLine, iCmdShow
     enter

     ;  registering the window class
     invoke  GetModuleHandle,NULL
     mov     [hInstance],eax
     mov     [wc.hInstance],eax
     mov     [wc.style],CS_HREDRAW or CS_VREDRAW
     mov     [wc.lpfnWndProc],WndProc
     mov     [wc.lpszClassName],wcName
     mov     [wc.hbrBackground],COLOR_WINDOW+1
     invoke  LoadIcon,NULL,IDI_APPLICATION
     mov     [wc.hIcon],eax
     invoke   LoadCursor,NULL,IDC_ARROW
     mov     [wc.hCursor],eax
     invoke  RegisterClass,wc

     ; creating the main window
     invoke    CreateWindowEx,\
                            0,\
                      wcName,\
                      wTitle,\
                      WS_OVERLAPPEDWINDOW ,\
                      CW_USEDEFAULT,\
                      CW_USEDEFAULT,\
                      CW_USEDEFAULT,\
                      CW_USEDEFAULT,\
                      NULL,\
                      NULL,\
                      [hInstance],\
                      NULL
     mov  [hWnd],eax
     invoke    ShowWindow,[hWnd],SW_SHOW

        ; | entering the message loop |
forever_loop:
     ;Window's main message loop
     invoke  GetMessage, msg, NULL, 0, 0

     .if     eax, e, NULL
             jmp     end_loop
     .else
             invoke TranslateMessage, msg
             invoke DispatchMessage, msg
             jmp forever_loop
     .endif

end_loop:
     invoke  ExitProcess,[msg.wParam]
     return
endp


proc WndProc, hwnd, message, wParam, lParam
     enter

     .if     [message], e, WM_DESTROY
             invoke    PostQuitMessage,0
             return

     .elseif [message], e, WM_CREATE
             invoke PlaySound, noise, [hInstance], SND_ASYNC +  SND_MEMORY
             .if     eax, e, FALSE
                     invoke  MessageBox, [hwnd], wcName, wTitle, MB_OK
                     return
             .endif
             ; DOES NOT PLAY BUT GIVE AN ERROR SUCCES IN DEBUGGER BUT SET EAX TO 0
     .endif

     invoke  DefWindowProc, [hwnd], [message], [wParam], [lParam]
     return
endp

section '.idata' import data readable writeable
        library KERNEL32, 'KERNEL32.DLL',\
                USER32,   'USER32.DLL',\
                winmm,    'WINMM.DLL'

        import  KERNEL32,\
               GetModuleHandle,         'GetModuleHandleA',\
               ExitProcess,             'ExitProcess',\
               FindResource,            'FindResourceA',\
               LoadResource,            'LoadResource',\
               LockResource,            'LockResource',\
               FreeResource,            'FreeResource'

        import USER32,\
               RegisterClass,           'RegisterClassA',\
               CreateWindowEx,          'CreateWindowExA',\
               DefWindowProc,           'DefWindowProcA',\
               ShowWindow,              'ShowWindow',\
               LoadCursor,              'LoadCursorA',\
               LoadIcon,                'LoadIconA',\
               GetMessage,              'GetMessageA',\
               TranslateMessage,        'TranslateMessage',\
               DispatchMessage,         'DispatchMessageA',\
               PostQuitMessage,         'PostQuitMessage',\
               MessageBox,              'MessageBoxA'

        import  winmm,\
               PlaySound,               'PlaySoundA',\
               sndPlaySound,            'sndPlaySoundA'
    
Post 19 May 2005, 07:40
View user's profile Send private message Reply with quote
Torrey



Joined: 12 Oct 2003
Posts: 78
Torrey
I agree with madmatt I tried both sndPlaySoundA, and PlaySoundA in more ways then you can imagine. All of them coming up with nothing good. Is it possible that MS has some buggy routines for resource wave playing? WAV files external to the program that madmatt mention always work with no problem.

An upside to using his idea would be that you wouldn't have memory full of resources. WAV files tend to get pretty large.
Post 19 May 2005, 08:12
View user's profile Send private message Visit poster's website Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
hello, i found this on the boards, perhaps it can help:

http://board.flatassembler.net/topic.php?t=2949
Post 19 May 2005, 12:01
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
TORREY: I'm not sure, could be bad documentation of this feature also. I Tried many different methods to get the resouce to play but no luck.

Also, touching on what Torrey pointed out above, for major code space savings you could/should play the sound from the harddrive, but for speed and small .wav files the above method works just fine.
Post 19 May 2005, 15:59
View user's profile Send private message Reply with quote
Spidark



Joined: 11 May 2005
Posts: 39
Spidark
madmatt wrote:
TORREY: I'm not sure, could be bad documentation of this feature also. I Tried many different methods to get the resouce to play but no luck.

Also, touching on what Torrey pointed out above, for major code space savings you could/should play the sound from the harddrive, but for speed and small .wav files the above method works just fine.

Wel after googling for a few hours, i've decided that the best thing to do is indeed the mem pointer way, or in the future as i learn to extract it to the hardisk, and play it from disk. or just play it from disk.
I 've learned how to include differrent resources in one application using pure fasm syntax style.
Just hope this could be more clearly documented in the future.
Coconut ,Madmatt and Torrey thanks for replying and trying to help.
I leave you with the last peace of code that i tried to get up and running, but without succes, so you could say that playing a wav file from a resource give's some troubles when using fasm.If anybody got this working out there (in fasm syntax of course ) be welcome to drop a note.( or maybe i'm just plain stupid Laughing)
Code:
format PE GUI 4.0
entry start

RT_MANIFEST             equ     24
SND_RESOURCE            equ     040004h
SND_ASYNC               equ     000001h
SND_NODEFAULT           equ     000002h 
SND_LOOP                equ     000008h
SND_ALIAS_ID                         equ 110000h


include '%fasminc%\win32a.inc' 

section '.data' data readable writeable
        hWnd            dd      ?
        hInstance       dd      ?
        playHandle      dd      ?

        wTitle          db      "WAV FILE IN RESOURCE 3",0 ;name of our window
        wcName          db      "Wav_In_Res_Class",0      ;name of our window class
        msg             MSG
        wc              WNDCLASS
        errText         db      "Error Detected Program can not run on this machine!",0
        resErr1         db      "FindResource Returned an error",0
        resErr2         db      "LoadResource Returned an error",0
        resErr3         db      "LockResource Returned an error",0
        resErr4         db      "PlaySound    Returned an error",0

        myText          db      "Hello we Like assembly language don't we",0
        messCap         db      "Message",0
        resText         db      "soundfile",0
     
section '.code' code readable executable
        start:
                ;  registering the window class
                 
        invoke  GetModuleHandle,NULL
        mov     [hInstance],eax
        mov     [wc.hInstance],eax
        mov     [wc.style],CS_HREDRAW or CS_VREDRAW
        mov     [wc.lpfnWndProc],WndProc
        mov     [wc.lpszClassName],wcName
        mov     [wc.hbrBackground],COLOR_WINDOW+1
        invoke  LoadIcon,NULL,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke   LoadCursor,NULL,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc

        ; creating the main window 
        invoke    CreateWindowEx,\
                               0,\
                         wcName,\
                         wTitle,\
                         WS_OVERLAPPEDWINDOW ,\
                         CW_USEDEFAULT,\
                         CW_USEDEFAULT,\
                         CW_USEDEFAULT,\
                         CW_USEDEFAULT,\
                         NULL,\
                         NULL,\
                         [hInstance],\
                         NULL
                    mov  [hWnd],eax
        push    [hWnd]
        invoke    ShowWindow,[hWnd],SW_SHOW
          ; | entering the message loop |
MSG_LOOP:
        invoke    GetMessage,msg,NULL,0,0
        or   eax,eax
        jz   END_LOOP
        invoke    TranslateMessage,msg
        invoke    DispatchMessage,msg
        jmp  MSG_LOOP
END_LOOP:
        invoke  MessageBoxEx,[hWnd],errText,messCap,MB_OK or MB_ICONSTOP 
        invoke  ExitProcess,0


WndProc:
        mov     eax,dword [esp+8]
        cmp     eax,WM_DESTROY
        je      ON_DESTROY
        cmp     eax,WM_CREATE
        je      ON_CREATE
        jmp     DEFWIN
        

proc    ON_DESTROY,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
        invoke    PostQuitMessage,0
        pop     ebx esi edi
        return
endp



proc    ON_CREATE,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
                
        
        invoke  FindResource,[hInstance],1001,RT_RCDATA 
        cmp     eax,0
        jz      .ERROR_DETECTED1
      
        ;// Load the WAVE resource. 
 
        invoke  LoadResource,[hInstance],eax                    ; eax HOLDS RESOURCE INFO
        cmp     eax,0
        jz      .ERROR_DETECTED2  
         
 
        ;// Lock the WAVE resource and play it. 
 
        invoke LockResource,eax                         ; eax Holds
        cmp     eax,0
        jz      .ERROR_DETECTED3
        mov     [playHandle],eax
        invoke PlaySound,1001,NULL ,SND_RESOURCE or SND_ASYNC or SND_LOOP or SND_ALIAS_ID
        ;ERROR_RESOURCE_DATA_NOT_FOUND (00000714)
        cmp     eax,FALSE
        je      .ERROR_DETECTED4
        jmp     .SAJONARA
.ERROR_DETECTED1:
        invoke  MessageBoxEx,[hWnd],resErr1,messCap,MB_OK,0
        jmp     .SAJONARA
.ERROR_DETECTED2:
        invoke  MessageBoxEx,[hWnd],resErr2,messCap,MB_OK,0
        jmp     .SAJONARA
.ERROR_DETECTED3:
        invoke  MessageBoxEx,[hWnd],resErr3,messCap,MB_OK,0
        jmp     .SAJONARA
.ERROR_DETECTED4:
        invoke  MessageBoxEx,[hWnd],resErr4,messCap,MB_OK,0
        jmp     .SAJONARA

.SAJONARA:
        pop     ebx esi edi
        return
endp

proc    DEFWIN,hWnd,uMsg,wParam,lParam
        push    edi esi ebx
        invoke    DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
        pop     ebx esi edi
        return
endp



section '.idata' import data readable writeable
        library KERNEL32, 'KERNEL32.DLL',\
                USER32,   'USER32.DLL',\
                winmm,    'WINMM.DLL'

        import  KERNEL32,\
               GetModuleHandle,         'GetModuleHandleA',\
               ExitProcess,             'ExitProcess',\
               FindResource,            'FindResourceA',\
               LoadResource,            'LoadResource',\
               LockResource,            'LockResource',\
               FreeResource,            'FreeResource'
        import USER32,\
               RegisterClass,           'RegisterClassA',\
               CreateWindowEx,          'CreateWindowExA',\
               DefWindowProc,           'DefWindowProcA',\
               ShowWindow,              'ShowWindow',\
               LoadCursor,              'LoadCursorA',\
               LoadIcon,                'LoadIconA',\
               GetMessage,              'GetMessageA',\
               TranslateMessage,        'TranslateMessage',\
               DispatchMessage,         'DispatchMessageA',\
               PostQuitMessage,         'PostQuitMessage',\
               MessageBoxEx,            'MessageBoxExA'
import  winmm,\
               PlaySound,               'PlaySoundA',\
               sndPlaySound,            'sndPlaySoundA'
; PlaySound,            'sndPlaySoundA',\
;section '.rsrc' resource from 'wavres.res' data readable
section '.rsrc' resource data readable


        
directory       RT_MANIFEST             ,manifest,\
                RT_RCDATA               ,resName, \
                RT_BITMAP               ,appBmp
;       
resource        manifest,1,LANG_NEUTRAL,man

fileres         man,        "wavinres.xml"
         
resource        resName,1001,LANG_NEUTRAL,soundfile 

fileres         soundfile , "Data_1.wav"


resource        appBmp,300,LANG_NEUTRAL,bmp1
       
bitmap          bmp1,      "foto.bmp"
    

Thanks again.
Post 19 May 2005, 21:36
View user's profile Send private message Reply with quote
Torrey



Joined: 12 Oct 2003
Posts: 78
Torrey
If you want to extract the resource to the hard drive use api's in this order:

FindResourceA
LoadResource
SizeofResource (returned size maybe larger because of alignment)
CreateFileA
CreateFileMappingA
MapViewOfFile
(copy data over from the handle returned by LoadResource)
UnmapViewOfFile (saves the data into the newly created file)

Also if you chose the delete on close option for the CreateFileA you could try to play the sound from memory using the memory address that MapViewOfFile returns back to you.

Quick Example:
Code:
format PE GUI 4.0
entry BeginCode

include '%fasminc%\win32a.inc'

section '.code' executable readable writeable

BeginCode:
        xor eax,eax
        invoke GetModuleHandle,eax
        mov [hModule],eax

        invoke FindResource,eax,1,RT_RCDATA
        mov [infoblock],eax

        invoke SizeofResource,[hModule],eax
        mov [szRes],eax

        invoke LoadResource,[hModule],[infoblock]
        mov [hData],eax

        invoke CreateFileA,wave,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ,\
               0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,FILE_FLAG_DELETE_ON_CLOSE,0
        cmp eax,-1
        je Error
        mov [hFile],eax

        invoke CreateFileMapping,eax,0,PAGE_READWRITE,0,[szRes],0
        mov [hMap],eax
        invoke MapViewOfFile,eax,FILE_MAP_ALL_ACCESS,0,0,0
        mov [baseAddr],eax

        mov edi,eax
        mov esi,[hData]
        mov ecx,[szRes]
        rep movsb

        invoke PlaySound,wave,[hModule],[SND_FILENAME]
        invoke UnmapViewOfFile,[baseAddr]
        invoke CloseHandle,[hMap]
        invoke CloseHandle,[hFile]

        invoke DeleteFileA,wave
        invoke ExitProcess,0
Error:
        invoke MessageBox,0,errMsg,exMsg,0
        invoke ExitProcess,0

section '.data' data readable writeable

SND_FILENAME   dd       0x20000
hMap           dd       ?
hModule        dd       ?
hFile          dd       ?
infoblock      dd       ?
szRes          dd       ?
baseAddr       dd       ?
hData          dd       ?
exMsg          db       'Example',0
errMsg         db       'An error has occured',0
wave           db       'wave.wav',0

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL',\
          winmm,'WINMM.DLL'

  import kernel,\
         ExitProcess,'ExitProcess',\
         GetModuleHandle,'GetModuleHandleA',\
         CreateFileA,'CreateFileA',\
         CreateFileMapping,'CreateFileMappingA',\
         MapViewOfFile,'MapViewOfFile',\
         UnmapViewOfFile,'UnmapViewOfFile',\
         CloseHandle,'CloseHandle',\
         DeleteFileA,'DeleteFileA',\
         FindResource,'FindResourceA',\
         LoadResource,'LoadResource',\
         SizeofResource,'SizeofResource'

  import user,\
         MessageBox,'MessageBoxA'

  import winmm,\
         PlaySound,'PlaySoundA'

section '.rsrc' resource data readable

directory       RT_RCDATA,sound

resource        sound,1,LANG_NEUTRAL,soundfile
fileres         soundfile,'C:\WINNT\Media\Knock01.wav'
    

This example creates a wave.wav in the current directory, plays the wave, and deletes the file afterwards.
Post 20 May 2005, 04:13
View user's profile Send private message Visit poster's website Reply with quote
Spidark



Joined: 11 May 2005
Posts: 39
Spidark
Torrey wrote:
If you want to extract the resource to the hard drive use api's in this order:

FindResourceA
LoadResource
SizeofResource (returned size maybe larger because of alignment)
CreateFileA
CreateFileMappingA
MapViewOfFile
(copy data over from the handle returned by LoadResource)
UnmapViewOfFile (saves the data into the newly created file)

Also if you chose the delete on close option for the CreateFileA you could try to play the sound from memory using the memory address that MapViewOfFile returns back to you.

Thanks again Torrey for the help i,m going to experiment with these functions.Thanks for the example.
Post 20 May 2005, 11:09
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.