473,657 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PlaySound question

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

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

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

-Harry

Nov 16 '05 #1
3 4638
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.net com.com> wrote in message
news:v1******** **********@news read1.news.pas. earthlink.net.. .
I added some sounds to my application, but the example in the msdn Library did not work. It had:

[DllImport("core dll")]
public static extern bool PlaySound( string szSound, IntPtr hMod, PlaySoundFlags flags );
The file coredll was not found. I changed it to [DllImport("WINM M")] 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.net com.com> wrote in message
news:v1******** **********@news read1.news.pas. earthlink.net.. .
I added some sounds to my application, but the example in the msdn Library did not work. It had:

[DllImport("core dll")]
public static extern bool PlaySound( string szSound, IntPtr hMod, PlaySoundFlags flags );
The file coredll was not found. I changed it to [DllImport("WINM M")] 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("winm m.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.PlaySou nd( strFileName, IntPtr.Zero, Helpers.PlaySou ndFlags.SND_FIL ENAME |
Helpers.PlaySou ndFlags.SND_ASY NC );
}
catch
{
// DllImport("winm m.dll") file not found or no PlaySound entry point in the file
// so generate no sound
}
}
}

-Harry

"Mike Kitchen" <pu*******@hotm ail.com> wrote in message news:%2******** ********@TK2MSF TNGP12.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.net com.com> wrote in message
news:v1******** **********@news read1.news.pas. earthlink.net.. .
I added some sounds to my application, but the example in the msdn Library

did not work.
It had:

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

PlaySoundFlags flags );

The file coredll was not found. I changed it to [DllImport("WINM M")] 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
5477
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 under each case is included in another header file that I created. I have the <mmsystem.h> included in the main cpp file. The functions under the PlaySound function works correctly, but it is not playing the wav file.
19
15425
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 the parameters and i have all the right headerfiles in there, but it won't work. it says that i must declare SND_FILENAME ,
5
2343
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 is unsuccessful. I get an error saying "file mmsystem not found". I think I've violated some API call protocol.
4
4508
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 had to add the following lines in order to use the multimedia extensions. In stdafx.h #include <MMSystem.h>
2
1683
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 my project as a resource (steps please) How do I call PlaySound once that I have the wav file as part of the resource.
10
2474
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 plays a sound file. One of the options I found in a nice description of PlaySound says that there are a couple of other choices. 1) The sound can be in the registry and actually controlled/selected by the end user.
9
11837
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) until the user clicks a button to acknowledge the situation. To keep things simple, lets assume there is only one monitor. If I use the old sndPlaySound function, with the code:
3
10632
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 Windows, and they play fine outside of my app. This code works, but has the random "scratching" problem: private static void PlayResource(string audioRes) { // Get the resource into a stream
0
1897
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 help. /* This uses the high level WAVE API PlaySound() to play a WAVE file in memory. I simply open the WAVE file called "nagelas.wav" (ie, in order for this example to work, you should make sure that you have such a WAVE file on your...
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8740
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.