473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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 4627
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ben Bateman | last post by:
I am tyring to write a small menu program that will display the lyrics of a song, and then play the song. I was told that you have to convert the mp3 to wav, did that. The 2 function calls...
19
by: bballmitch | last post by:
Why won't the following code work? char soundfile2 = "C:/Windows/Media/pinky and the brain.wav"; PlaySound(soundfile2,NULL,SND_FILENAME|SND_SYNC|SND_ASYNC); getchar(); i put libwinmm.a in...
5
by: MLH | last post by:
I have a line of code that works when called from a procedure in Access 2.0 form... PlaySound("C:\cr\help\Help0018.wav", 0) I imported what I thought was needed into A97. However, running it...
4
by: rcattral | last post by:
Has anybody been using the PlaySound() function to play WAV files from within a DLL? Here is what I normally do. Since upgrading to 7.1 NET after using VC 6.0 for quite some time, I found that I...
2
by: Joe Thompson | last post by:
Hi, I am trying to use PlaySound in a VC++.net Windows app (VS 2003). I can use it to play a file but now I want to play it from a resource. I have two questions: How do I add a wav file to...
10
by: Ot | last post by:
I found information on PlaySound. I implemented it in my program and it works just dandy. The only little problem is that I have to package the ..wav files and send them along since PlaySound...
9
by: Andy | last post by:
Hi, I have an application that has several forms. Each form acts as a monitor of a gateway system. If the gateway appears to be dead, the application should play a .wav file (not resource)...
3
by: Jared | last post by:
I'm using the first code sample below to play WAV files stored as embedded resources. For some reason I *occasionally* get scratching and crackling. I'm using a couple WAVs that ship with...
0
by: poppy | last post by:
I tried to play a wav file with function Playsound() but it played only the first seconds of the song.I would like to play whole the song.What might de be wrong?Here is my code in case someone can...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.