flat assembler
Message board for the users of flat assembler.
Index
> Windows > WAV file resource not found |
Author |
|
alszla 24 Sep 2016, 19:11
Hi. I am having trouble makin API PlaySound play a wav file defined in a resource file.
On one hand, I have this "external" RC script (to be compiled with MASM32's rc): Code:
1000 WAVE sound.wav
and somewhere in my source code (to be compiled with FASM): Code: invoke PlaySound,1000,[wHInstance], SND_ASYNC + SND_RESOURCE I also include the resource file like this: Code: section '.rsrc' data readable resource from 'woof.res' And the resulting executable works as expected. It plays the wave file as soon as the window is displayed. On the other hand, when I try to rewrite the resource section with FASM syntax: Code: section '.rsrc' data readable resource directory RT_RCDATA,sounds resource sounds,\ 1000,LANG_NEUTRAL,somename resdata somename file 'sound.wav' endres The resulting executable doesn't seem to find the resource. Debugging it in OllyDbg shows "ERROR_RESOURCE_TYPE_NOT_FOUND" error in OllyDbg. I found similar posts here at the forums describing this behaviour, but all of them give alternate solutions either by defining the file using 'file' directive in data section OR by using sndPlaySound API along with Lock/Free/Load/FindResource APIs. I also tested all of those alternate solutions and while all of them worked, I couldn't find any code that uses just PlaySound API to play a sound from a resource defined in FASM syntax. Microsoft reference states that PlaySound takes care of all the process of finding and loading the resource. https://msdn.microsoft.com/en-us/library/dd743679%28v=vs.85%29.aspx So there wouldn't be any need to use LoadResource, FindResource APIs. I also find that using Playsound allows simpler and cleaner code. Just a personal preference. Is there anything wrong with the resource definition in my source code? OR Is this some kind of limitation in the way how FASM manages resources?? Thanks for all the help you've all provided so far. These forums have been an extremely useful source of guidance and solutions for many of my programs. If you find any mistake in the resource definition, please let me know. |
|||
24 Sep 2016, 19:11 |
|
Walter 27 Sep 2016, 10:59
alszla,
Quote: Microsoft reference states that PlaySound takes care of all the process of finding and loading the resource. Hadn't thought about that. While most coders here could debug the PlaySound API in an hour, it would take me three days. So instead, I looked to see what ReactOS does. https://doxygen.reactos.org/db/ddf/playsound_8c_source.html In proc_PlaySound you will see FindResource, LoadResource, LockResource, ... It now makes sense to me why the examples on this board use these functions with RT_RCDATA and sndPlaySound. Fasm does not support the named resource type (not what you wanted to hear). Here is an example that sort of gets what you want. "FASM syntax" and it does use a resource. However, it would be uncomfortable to work with resources in this fashion. Code: ;***************** ;* PlaySound.asm * ;***************** format pe gui 4.0 entry start include 'win32a.inc' IDW_WAVE = 100 SND_SYNC = 0x0 SND_RESOURCE = 0x40004 section '.code' code readable executable start: invoke GetModuleHandle,0 invoke PlaySound,IDW_WAVE,eax,SND_SYNC+SND_RESOURCE invoke ExitProcess,0 section '.idata' import data readable library kernel32,'kernel32.dll',\ winmm,'winmm.dll' import kernel32,\ ExitProcess,'ExitProcess',\ GetModuleHandle,'GetModuleHandleA' import winmm,\ PlaySound,'PlaySoundA' section '.rsrc' resource data readable ; IMAGE_RESOURCE_DIRECTORY dd 0x0 ; Characteristics. dd 0x57e9bcb3 ; TimeDateStamp (9/26/2016, 8:26:27 PM) dw 0x0 ; MajorVersion. dw 0x0 ; MinorVersion. dw 0x1 ; NumberOfNamedEntries. dw 0x0 ; NumberOfIdEntries. ; IMAGE_RESOURCE_DIRECTORY_ENTRY dd 0x80000048 ; Name. High bit set, NameIsString true. Lower 31 bits, is NameOffset. dd 0x80000018 ; OffsetToData. High bit set, DataIsDirectory true. Lower 31 bits, is OffsetToDirectory. ; IMAGE_RESOURCE_DIRECTORY dd 0x0 ; Characteristics. dd 0x57e9bcb3 ; TimeDateStamp. dw 0x0 ; MajorVersion. dw 0x0 ; MinorVersion. dw 0x0 ; NumberOfNamedEntries. dw 0x1 ; NumberOfIdEntries. ; IMAGE_RESOURCE_DIRECTORY_ENTRY dd IDW_WAVE ; ID. WaveFile Id. dd 0x80000030 ; OffsetToData. High bit set, DataIsDirectory true. Lower 31 bits, is OffsetToDirectory. ; IMAGE_RESOURCE_DIRECTORY dd 0x0 ; Characteristics. dd 0x57e9bcb3 ; TimeDateStamp. dw 0x0 ; MajorVersion. dw 0x0 ; MinorVersion. dw 0x0 ; NumberOfNamedEntries. dw 0x1 ; NumberOfIdEntries. ; IMAGE_RESOURCE_DIRECTORY_ENTRY (Resource language) dd 0x00000409 ; Resource language 0x409 = 1033 dd 0x00000054 ; IMAGE_RESOURCE_DIR_STRING_U dw 4 ; Length. Length of resource type name. du 'W','A','V','E',0x0 ; NameString. ; IMAGE_RESOURCE_DATA_ENTRY dd RVA WaveFileStart ; OffsetToData. RVA of the actual data. dd WaveFileEnd - WaveFileStart ; Size. Size in bytes of WaveFile. dd 0x0 ; CodePage. dd 0x0 ; Reserved. WaveFileStart: file 'Bdbnlck.wav' WaveFileEnd: Rename Bdbnlck.zip to Bdbnlck.wav if you decide to use this.
|
|||||||||||
27 Sep 2016, 10:59 |
|
alszla 27 Sep 2016, 23:48
Walter,
I appreciate your taking the time to debug the issue and actually come up with a solution and a conclusive answer. As you mentioned, it might be uncomfortable using this notation, but in the end, it really shows PlaySound API reading a resource defined in the same source code. I must also admit that I find the definition you proposed in the resource section very informative. As newbie as I am, it gives me an in-depth look at the nature of a resource. Correct me if I'm wrong: This notation is about using PE file format directly, right? Once again, thanks for your effort ( and for the lesson ). |
|||
27 Sep 2016, 23:48 |
|
alszla 29 Sep 2016, 05:40
As to using macros, I think that reading the resource.inc file (included in the fasm package) and the PE format specification are kind of mandatory in order for me to get a better understanding of how resources are constructed so I can try following a similar approach to the one used here: https://board.flatassembler.net/topic.php?t=2370 where a macro has been written in order to implement a stringtable in the resource section.
|
|||
29 Sep 2016, 05:40 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.