Sound

G

Guest

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
G

Guest

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..
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
S

Stefan Simek

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
 
N

Nicholas Paldino [.NET/C# MVP]

Michael,

I've cleaned up the declarations at pinvoke.net. It should be better
now, and it should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Question about PInvokeStackImbalance? Thanks 2
Problem plaing Wav on CE5 7
play sound file 1
how To Play sound 4
Play message 3
Calling A Module 5
Calling a Module 1
PlaySound 1

Top