469,626 Members | 1,070 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

PlaySound question

I added some sounds to my application, but the example in the msdn Library did not work.
It had:

[DllImport("coredll")]
public static extern bool PlaySound( string szSound, IntPtr hMod, PlaySoundFlags flags );

The file coredll was not found. I changed it to [DllImport("WINMM")] and it now works.
What is the best way to handle this?

-Harry

Nov 16 '05 #1
3 4461
Hi Harry,

code.dll ( Please note that you forgot the . in your post ) is a dll from
the PocketPC platform. so the code you took maybe intended to run on a
PocketPC, if not you have to change it to the correct dll from the desktop.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Harry J. Smith" <hj*****@ix.netcom.com> wrote in message
news:v1******************@newsread1.news.pas.earth link.net...
I added some sounds to my application, but the example in the msdn Library did not work. It had:

[DllImport("coredll")]
public static extern bool PlaySound( string szSound, IntPtr hMod, PlaySoundFlags flags );
The file coredll was not found. I changed it to [DllImport("WINMM")] and it now works. What is the best way to handle this?

-Harry

Nov 16 '05 #2
This has been addressed several times here.

I have compiled the common answers in my snippets page found at

http://www.publicjoe.f9.co.uk/csharp/snip/snip001.html

Plus I now have about sound at
http://www.publicjoe.f9.co.uk/csharp/csharp17.html
and
http://www.publicjoe.f9.co.uk/csharp/csharp18.html

Hope this helps

Publicjoe
C# Tutorial at http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Snippets at http://www.publicjoe.f9.co.uk/csharp/snip/snippets.html
C# Ebook at http://www.publicjoe.f9.co.uk/csharp/samples/ebook.html
VB Ebook at http://www.publicjoe.f9.co.uk/vbnet/samples/ebook.html

"Harry J. Smith" <hj*****@ix.netcom.com> wrote in message
news:v1******************@newsread1.news.pas.earth link.net...
I added some sounds to my application, but the example in the msdn Library did not work. It had:

[DllImport("coredll")]
public static extern bool PlaySound( string szSound, IntPtr hMod, PlaySoundFlags flags );
The file coredll was not found. I changed it to [DllImport("WINMM")] and it now works. What is the best way to handle this?

-Harry

Nov 16 '05 #3
Thanks Mike, your C# Tutorial is great.

The short answer to me question is use

[DllImport("winmm.dll")]
public static extern bool PlaySound( string szSound, IntPtr hMod, PlaySoundFlags flags );

I also put in an exception handler to keep the application from crashing:

public class Sound
{
public static void Play( string strFileName )
{
try
{
Helpers.PlaySound( strFileName, IntPtr.Zero, Helpers.PlaySoundFlags.SND_FILENAME |
Helpers.PlaySoundFlags.SND_ASYNC );
}
catch
{
// DllImport("winmm.dll") file not found or no PlaySound entry point in the file
// so generate no sound
}
}
}

-Harry

"Mike Kitchen" <pu*******@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...
This has been addressed several times here.

I have compiled the common answers in my snippets page found at

http://www.publicjoe.f9.co.uk/csharp/snip/snip001.html

Plus I now have about sound at
http://www.publicjoe.f9.co.uk/csharp/csharp17.html
and
http://www.publicjoe.f9.co.uk/csharp/csharp18.html

Hope this helps

Publicjoe
C# Tutorial at http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Snippets at http://www.publicjoe.f9.co.uk/csharp/snip/snippets.html
C# Ebook at http://www.publicjoe.f9.co.uk/csharp/samples/ebook.html
VB Ebook at http://www.publicjoe.f9.co.uk/vbnet/samples/ebook.html

"Harry J. Smith" <hj*****@ix.netcom.com> wrote in message
news:v1******************@newsread1.news.pas.earth link.net...
I added some sounds to my application, but the example in the msdn Library

did not work.
It had:

[DllImport("coredll")]
public static extern bool PlaySound( string szSound, IntPtr hMod,

PlaySoundFlags flags );

The file coredll was not found. I changed it to [DllImport("WINMM")] and

it now works.
What is the best way to handle this?

-Harry

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ben Bateman | last post: by
19 posts views Thread by bballmitch | last post: by
4 posts views Thread by rcattral | last post: by
2 posts views Thread by Joe Thompson | last post: by
10 posts views Thread by Ot | last post: by
9 posts views Thread by Andy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.