473,382 Members | 1,736 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,382 software developers and data experts.

Sound

Thanks for the last one, first of all.
I have another problem, using an API function
[DllImport("winmm.dll", SetLastError=true)]
static extern bool PlaySound(string pszSound,
System.UIntPtr hmod, uint fdwSound);

to use the uint fdwSound I initialized the following enum:
[Flags]
public enum SoundFlags : uint
{
SND_SYNC = 0x0000, // play synchronously (default)
SND_ASYNC = 0x0001, // play asynchronously
SND_NODEFAULT = 0x0002, // silence (!default) if sound not found
SND_MEMORY = 0x0004, // pszSound points to a memory file
SND_LOOP = 0x0008, // loop the sound until next sndPlaySound
SND_NOSTOP = 0x0010, // don't stop any currently playing sound
SND_NOWAIT = 0x00002000, // don't wait if the driver is busy
SND_ALIAS = 0x00010000, // name is a registry alias
SND_ALIAS_ID = 0x00110000, // alias is a predefined id
SND_FILENAME = 0x00020000, // name is file name
SND_RESOURCE = 0x00040004 // name is resource name or atom
}
But when I try to use this function by writing:
PlaySound("music.wav",UIntPtr.Zero,SoundFlags.SND_ FILENAME |
SoundFlags.SND_ASYNC );
It generates a compile time error:
Argument 3: Cannot convert Form1.SoundFlags to uint
What is the problem and how can I solve it?
I copied all the info from pininvoke.net and didn't invent anything:(
Thanks for your help

Nov 16 '05 #1
8 1925
Michael,

The problem comes from the fact that they are separate types. While
enumerations might be represented in a value set that is shared by Int32,
Int16, etc, etc, they are separate types.

In order to get around this, you will have to cast the value to the uint
type, or change your declaration. I suggest changing your declaration to:

[DllImport("winmm.dll", SetLastError=true)]
static extern bool PlaySound(string pszSound, System.UIntPtr hmod,
SoundFlags fdwSound);

Also, I don't think you should use the UIntPtr. IntPtr is the preferred
type, and used everywhere to represent pointers/handles in the framework.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.com...
Thanks for the last one, first of all.
I have another problem, using an API function
[DllImport("winmm.dll", SetLastError=true)]
static extern bool PlaySound(string pszSound,
System.UIntPtr hmod, uint fdwSound);

to use the uint fdwSound I initialized the following enum:
[Flags]
public enum SoundFlags : uint
{
SND_SYNC = 0x0000, // play synchronously (default)
SND_ASYNC = 0x0001, // play asynchronously
SND_NODEFAULT = 0x0002, // silence (!default) if sound not found
SND_MEMORY = 0x0004, // pszSound points to a memory file
SND_LOOP = 0x0008, // loop the sound until next sndPlaySound
SND_NOSTOP = 0x0010, // don't stop any currently playing sound
SND_NOWAIT = 0x00002000, // don't wait if the driver is busy
SND_ALIAS = 0x00010000, // name is a registry alias
SND_ALIAS_ID = 0x00110000, // alias is a predefined id
SND_FILENAME = 0x00020000, // name is file name
SND_RESOURCE = 0x00040004 // name is resource name or atom
}
But when I try to use this function by writing:
PlaySound("music.wav",UIntPtr.Zero,SoundFlags.SND_ FILENAME |
SoundFlags.SND_ASYNC );
It generates a compile time error:
Argument 3: Cannot convert Form1.SoundFlags to uint
What is the problem and how can I solve it?
I copied all the info from pininvoke.net and didn't invent anything:(
Thanks for your help

Nov 16 '05 #2
Thanks a lot!
It helped and it works.
About the UIntPtr I just have no idea what they mean, in every API function
I have seen such an argument which is a IntPtr or UIntPtr type and I always
put IntPtr.Zero as an input to the function. Can you please explain me what
those arguments mean?
Thanks..
Nov 16 '05 #3
Michael,

An IntPtr is a representation of a native pointer on the system that it
is running on. For 32 bit systems, it is a 32 bit value, and on 64 bit
systems, it is a 64 bit value. They are used to represent pointers, as well
as handles (they are really just pointers in memory), and interoping with
unmanaged code.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
Thanks a lot!
It helped and it works.
About the UIntPtr I just have no idea what they mean, in every API
function
I have seen such an argument which is a IntPtr or UIntPtr type and I
always
put IntPtr.Zero as an input to the function. Can you please explain me
what
those arguments mean?
Thanks..

Nov 16 '05 #4
It's a platform-dependent pointer.

On 32-bit systems, the IntPtr is 32 bits.
On 64-bit systems, the IntPtr becomes 64 bits.

It's something like the DWORD_PTR that used in WinAPI.

HTH,
Stefan

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
Thanks a lot!
It helped and it works.
About the UIntPtr I just have no idea what they mean, in every API
function
I have seen such an argument which is a IntPtr or UIntPtr type and I
always
put IntPtr.Zero as an input to the function. Can you please explain me
what
those arguments mean?
Thanks..

Nov 16 '05 #5
Thanks a lot!
Nov 16 '05 #6
Michael,

Take a look at http://www.pinvoke.net/ - I havent used them for this
particular routine, but have used other samples and they save a shedload of
time!

Chris.

"Michael" wrote:
Thanks for the last one, first of all.
I have another problem, using an API function
[DllImport("winmm.dll", SetLastError=true)]
static extern bool PlaySound(string pszSound,
System.UIntPtr hmod, uint fdwSound);

to use the uint fdwSound I initialized the following enum:
[Flags]
public enum SoundFlags : uint
{
SND_SYNC = 0x0000, // play synchronously (default)
SND_ASYNC = 0x0001, // play asynchronously
SND_NODEFAULT = 0x0002, // silence (!default) if sound not found
SND_MEMORY = 0x0004, // pszSound points to a memory file
SND_LOOP = 0x0008, // loop the sound until next sndPlaySound
SND_NOSTOP = 0x0010, // don't stop any currently playing sound
SND_NOWAIT = 0x00002000, // don't wait if the driver is busy
SND_ALIAS = 0x00010000, // name is a registry alias
SND_ALIAS_ID = 0x00110000, // alias is a predefined id
SND_FILENAME = 0x00020000, // name is file name
SND_RESOURCE = 0x00040004 // name is resource name or atom
}
But when I try to use this function by writing:
PlaySound("music.wav",UIntPtr.Zero,SoundFlags.SND_ FILENAME |
SoundFlags.SND_ASYNC );
It generates a compile time error:
Argument 3: Cannot convert Form1.SoundFlags to uint
What is the problem and how can I solve it?
I copied all the info from pininvoke.net and didn't invent anything:(
Thanks for your help

Nov 16 '05 #7
Thanks but that's where I took the information in the first place:)
Nov 16 '05 #8
Michael,

I've cleaned up the declarations at pinvoke.net. It should be better
now, and it should work.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:01**********************************@microsof t.com...
Thanks but that's where I took the information in the first place:)

Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Larry L | last post by:
I want to play a repetitive sound, and have a user click on a button each time it plays (say 5-10 times) and measure how far off he is from the sound each time. The only way I know to play a...
1
by: Marco Krechting | last post by:
Hi All, I have a database with the timer function set to warn the user that arecord is due to expire. Is there a Win API that I can use so a loud warning will go off. Not this simpel beep in...
4
by: Robert Gravereaux | last post by:
I'm putting together a C# .Net forms project on win2k. The application requires some sort of horn sound. I've never implemented any audio in .Net, so I'm not sure how best to accomplish this. ...
1
by: Lam | last post by:
how can I play sound file in a .aspx page written in C#? I try to use the code like the following. But whenI call the play function play("sound.wav", this.SND_ASYNC) my computer give out "be"...
4
by: Larry Serflaten | last post by:
I'm adding a bit of sound to a simple game I've got going, and I want to have several sounds on at the same time, so I go looking to use the MCISendString commands and find they CRASH MY COMPUTER...
16
by: Dobedani | last post by:
Dear All, I found the code added below at: http://simplythebest.net/sounds/sound_guide.html Unfortunately, the code doesn't seem to work in Firefox. These are the error messages I can see in...
6
by: laredotornado | last post by:
Hi, Is there a cross-browser way to play short (< 25K) sound files without spawning new windows or embedding any visual controls on the page? I would like to click a button and hear my short...
6
by: =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?= | last post by:
I have an application that is designed for using with a bar code scanner. I want the user to know that the scan was complete and the data was entered, so I am playing a system sound after data...
4
by: kid joe | last post by:
Hello I've got interested in learning some basic sound programming bits in C... mainly I want to know how to go about accessing the sound devices - reading from them mainly - in windows and...
8
by: chromis | last post by:
Hi, I've been struggling to get sounds to work with attachSound when the sounds are stored in a swf loaded into another swf. I came across a post on a forum which supposedly explains how to to do...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.