LoadResource, FindResource play Wave file

I'm trying to play WAVE file via sndPlaySound using this solution http://msdn.microsoft.com/en-us/library/ms712876(VS.85).aspx
I know I just could use PlaySound, but I'm making a metronome so I need to play wave's fast and even:
PlaySound(TEXT("RealDrumkits\\RD_Snare_2.wav"), NULL, SND_FILENAME | SND_ASYNC);
is too slow. I wonder if by locking wave and playing it from memory I can make it faster. I use Visual Studio C++ and I added a Wave resource so my resource.h file look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by app.rc
//
#define IDR_WAVE1                       102

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        105
#define _APS_NEXT_COMMAND_VALUE         40002
#define _APS_NEXT_CONTROL_VALUE         1000
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif 

When I copy exmple to my program i get errors:
1
2
3
4
5
6
c:\users\michal\documents\visual studio 2008\projects\mik\mik\Form1.h(18) : error C2065: 'hInst' : undeclared identifier
c:\users\michal\documents\visual studio 2008\projects\mik\mik\Form1.h(24) : error C2065: 'hInst' : undeclared identifier
c:\users\michal\documents\visual studio 2008\projects\mik\mik\Form1.h(30) : error C2440: '=' : cannot convert from 'LPVOID' to 'LPSTR'
        Conversion from 'void*' to pointer to non-'void' requires an explicit cast
c:\users\michal\documents\visual studio 2008\projects\mik\mik\Form1.h(33) : error C2664: 'sndPlaySoundW' : cannot convert parameter 1 from 'LPSTR' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


What should I do?
(Sorry, but I'm complete beginner and I'm from non-engilsh country.)
closed account (S6k9GNh0)
hInst is a handle to your window. In order to play the music you need to pass a handle or pointer to your window. That's what the hInst undeclared identifier means. Unrelated to actually playing the music.

You apparently tried to pass an LPVOID (void *) to a LPSTR parameter (char *) which doesn't work. This has nothing to do with using PlaySound.

Also sndPlaySoundW is suppose to be sndPlaySound. Either way, you shouldn't use sndPlaySound, you should use PlaySound as the documentation explains. sndPlaySound is old and simply a subset of PlaySound.
Last edited on
Topic archived. No new replies allowed.