winmm.dll PlaySound

  • Thread starter Thread starter Joshua Moore
  • Start date Start date
J

Joshua Moore

Several locations on the web point to using the dll winmm and use PlaySound
using the code below. Can't I include the wav files in my project, and
change them to embedded resources, then point to the file name as
namespace.filename.extension?

Thanks,
Joshua Moore

static extern bool PlaySound( string pszSound, IntPtr hMod, SoundFlags sf );

then in a static void function

PlaySound( file, IntPtr.Zero, SoundFlags.SND_FILENAME |
SoundFlags.SND_ASYNC );
 
Joshua,

No, you can not. The reason for this is that the API expects a resource
id for a win32 resource, or a filename. The resources in .NET are not the
same, and therefore can't be used. If you include them as resources in your
project, then you will need to save the resource to disk and then pass the
file name to that.

Also, if you want, you can use the command line compiler to compile the
project to a module. You can then create a resource file with the WAV files
in it, and then use the assembly linker tool with the /win32res option to
place the .res file in the .NET dll. You should then be able to call the
GetModuleHandle API function through the P/Invoke layer to get the module
handle to pass to PlaySound.

Hope this helps.
 
Back
Top