Sound advice

  • Thread starter Thread starter Peteroid
  • Start date Start date
P

Peteroid

Can anybody point me to or give a simple source example of a managed C++
application that can play a wav sound file? I know a little about
playSound(), but it doesn't seem to like to compile (even though it's
'recognized' via type-ahead in the editor). Required header files might be
my problem, not sure...

Thanx in advance! :)
 
Peteroid said:
Can anybody point me to or give a simple source
example of a managed C++
application that can play a wav sound file?

Yup, try this:

#include <windows.h>

#using <mscorlib.dll>
using namespace System;

int main()
{
Console::WriteLine(S"Play sound test ...");

PlaySound("file.wav", 0, SND_FILENAME);

return 0;
}

Change "file.wav" to be the full path to a multimedia file.
I know a little about playSound(), but it doesn't
seem to like to compile (even though it's 'recognized'
via type-ahead in the editor). Required header files
might be my problem, not sure...

Compilers can be so picky ... :-)

Seriously, it is often wise to post a _few lines_ of code and the _exact_
text of the error message you get from the compiler. More often than not
someone here will be able to decipher it for you. And on those rare
occasions when no one can spot the error, it can be escalated to someone who
does.

Regards,
Will
 
Thanx for responding!

I tried the code snipet below, and I get a lot of errors. After a little
experimentation, I've narrowed it down to not liking the inclusion of
"windows.h". It needs it to recognize PlaySound() and SND_FILENAME, but a
subset of the errors it gives with windows.h are as follows:

C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\ObjIdl.h(7385): error C2371: 'IDataObject' :
redefinition; different basic types

C:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\ObjIdl.h(7894): error C2371: 'IMessageFilter' :
redefinition; different basic types

c:\Program Files\Microsoft Visual Studio
..NET\Vc7\PlatformSDK\Include\ServProv.h(92): error C2872: 'IServiceProvider'
: ambiguous symbol
:
:
etc.

and other errors that look like just these same errors being repeated many
times. I'm doing a MANAGED windows program, is that the problem?

[==Peter==]
 
Peteroid said:
Thanx for responding!

You are welcome.
I tried the code snipet below, and I get a lot of errors.

Hmm, you tried what I posted? That would be strange as it compiles, links
and runs fine here (VS.Net 2003). Just by the way, I turned off the
pre-compiled header option and ditched <stdafx.h> in that little hack.

Make sure you include <windows.h> _outside_ of the namespace.

Regards,
Will
 
Hi Will,

Sorry for the long delay in response, Memorial Day stuff...

Yes, that was definitely part of my problem! I had placed the include
<windows.h> inside the namespace.

It compiles better, but has one error:

myProject error LNK2001: unresolved external symbol "int __stdcall
PlaySoundA(char const *,struct HINSTANCE__ *,unsigned long)"
(?PlaySoundA@@$$J212YGHPBDPAUHINSTANCE__@@K@Z)

I think this means it recognized the PlaySound() call, but it looks like
it can't find where the actual call is. Do I have to make some dll or
something a dependency? Just guessing here, it's so close!

[==Peter==]
 
Peteroid said:
myProject error LNK2001: unresolved external symbol "int __stdcall
PlaySoundA(char const *,struct HINSTANCE__ *,unsigned long)"
(?PlaySoundA@@$$J212YGHPBDPAUHINSTANCE__@@K@Z)

I think this means it recognized the PlaySound() call, but it looks like
it can't find where the actual call is. Do I have to make some dll or
something a dependency? Just guessing here, it's so close!

Looks like you need to link against the winmm.lib import library.

Thobias Jones
 
Looks like you need to link against the winmm.lib import library.

That sounds like exactly what I need to do. So, how does one 'link against
winmm.lib" in VC++ NET? What do I do in my project to make this happen?

[==Peter==]
 
Peteroid said:
That sounds like exactly what I need to do. So, how does one 'link against
winmm.lib" in VC++ NET? What do I do in my project to make this happen?

From the menu choose

Project->Properties->Linker->Input

In the "Additional Dependencies" edit box type the name of the library.

Regards.
Will
 
Back
Top