The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Magnum on September 11, 2010, 04:37:01 PM

Title: Write out a file that is in my program
Post by: Magnum on September 11, 2010, 04:37:01 PM
If I want to store a wave file in my program, how would I write it out to a file?

Title: Re: Write out a file that is in my program
Post by: bomz on September 11, 2010, 05:22:50 PM
in resources like icons.
may be anyone get an example code?
Title: Re: Write out a file that is in my program
Post by: Tedd on September 11, 2010, 07:52:22 PM
If you already have the wav file, it's easiest (and best in terms of memory usage) to add it as a resource - from where it can be played directly too.


Example Attached.
Title: Re: Write out a file that is in my program
Post by: Coma on September 11, 2010, 07:53:42 PM
Hi,
FindResource, SizeofResource, LoadResource, LockResource, CreateFile, WriteFile, CloseHandle, could work.
Wave Resource must defined as RCDATA:
mySound         RCDATA      test.wav
Title: Re: Write out a file that is in my program
Post by: Magnum on September 11, 2010, 09:47:45 PM
Thanks to everyone.
Title: Re: Write out a file that is in my program
Post by: Magnum on September 11, 2010, 09:57:10 PM
Quote from: Tedd on September 11, 2010, 07:52:22 PM
If you already have the wav file, it's easiest (and best in terms of memory usage) to add it as a resource - from where it can be played directly too.

Example Attached.


Thanks Tedd.
I found that no delay is necessary if SND_ASYNC is not used.

Why MS included this is one of those mysteries. :-)

SND_ASYNC

The sound is played asynchronously and PlaySound returns immediately after beginning the sound.

Title: Re: Write out a file that is in my program
Post by: bomz on September 11, 2010, 10:19:51 PM
Quote from: Coma on September 11, 2010, 07:53:42 PM
Hi,
FindResource, SizeofResource, LoadResource, LockResource, CreateFile, WriteFile, CloseHandle, could work.
Wave Resource must defined as RCDATA:
mySound         RCDATA      test.wav

any more?

what about MIDI files?
Title: Re: Write out a file that is in my program
Post by: Coma on September 12, 2010, 09:46:18 AM
Hi,
myMidi         RCDATA      test.mid
myPng         RCDATA      test.png
myPdf          RCDATA      test.pdf
Title: Re: Write out a file that is in my program
Post by: bomz on September 12, 2010, 11:04:56 AM
(http://i068.radikal.ru/0811/0b/7c7c611ce687.gif)
Title: Re: Write out a file that is in my program
Post by: Tedd on September 12, 2010, 12:20:44 PM
Quote from: Magnum on September 11, 2010, 09:57:10 PM
I found that no delay is necessary if SND_ASYNC is not used.

Why MS included this is one of those mysteries. :-)

If you don't use SND_ASYNC then your program will block waiting for the sound to finish; for short sounds this isn't very noticeable, for longer ones it is - especially if you have other things to do following the sound, e.g. repaint the window.
So yes, it's not 'necessary' but it's generally better, which is why I demonstrated it that way (hence the delay, which you wouldn't otherwise use since there wouldn't normally be an exit immediately afterwards.)
If you just want a sound to play in your program (to signal some event) use async (no delay required.)
Title: Re: Write out a file that is in my program
Post by: Magnum on September 12, 2010, 01:23:47 PM
Thanks for the explanation.