Win API and Sounds

Started by
8 comments, last by Fixxer 17 years, 12 months ago
I am trying to use sounds, but nothing is being recognized. My book doesn't tell me to include anything extra. ------ Build started: Project: Example 3, Configuration: Debug Win32 ------ Compiling... main.cpp .\main.cpp(34) : error C2065: 'SND_ASYNC' : undeclared identifier .\main.cpp(34) : error C2065: 'SND_LOOP' : undeclared identifier .\main.cpp(34) : error C2065: 'SND_RESOURCE' : undeclared identifier .\main.cpp(34) : error C3861: 'PlaySound': identifier not found .\main.cpp(55) : error C2065: 'SND_PURGE' : undeclared identifier .\main.cpp(55) : error C3861: 'PlaySound': identifier not found Build log was saved at "file://c:\Documents and Settings\Owner\Desktop\Programming\Windows Game Programming Book\Chapter 3\Example 3\Example 3\Debug\BuildLog.htm" Example 3 - 6 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Advertisement
ok I found mmsystem.h

Now I get this

------ Build started: Project: Example 3, Configuration: Debug Win32 ------Compiling...main.cpp.\main.cpp(35) : error C2664: 'PlaySoundA' : cannot convert parameter 2 from 'HANDLE' to 'HMODULE'        Conversion from 'void*' to pointer to non-'void' requires an explicit cast.\main.cpp(56) : error C2664: 'PlaySoundA' : cannot convert parameter 2 from 'HANDLE' to 'HMODULE'        Conversion from 'void*' to pointer to non-'void' requires an explicit castBuild log was saved at "file://c:\Documents and Settings\Owner\Desktop\Programming\Windows Game Programming Book\Chapter 3\Example 3\Example 3\Debug\BuildLog.htm"Example 3 - 2 error(s), 0 warning(s)========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


here is how im playing and stopping the sound

// playPlaySound(MAKEINTRESOURCE(SOUND_MUSIC), hinstance_app, SND_ASYNC | SND_LOOP | SND_RESOURCE);//stopPlaySound(NULL,hinstance_app,SND_PURGE);
have you linked the winmm.lib to the compiler?

Beginner in Game Development?  Read here. And read here.

 

I think I have.
Winmm.lib is in a directory that I have linked to it.

Do I need to some how link my project to it?
post the code [smile] and what IDE are you using? VS6 or VS 2005 Express Edition?

Beginner in Game Development?  Read here. And read here.

 

2005 Express.

Here is my main.cpp

// EXAMPLE 3 OF CHAPTER THREE#define WIN32_LEAN_AND_MEAN#include <windows.h>#include <windowsx.h>#include <stdio.h>#include <math.h>#include <mmsystem.h>#include "resource.h"// DEFINES //////////////////////////#define WINDOW_CLASS_NAME "WINCLASS1"// GLOBALS //////////////////////////HANDLE hinstance_app;// FUNCTIONS ////////////////////////void GameMain();LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){	// this is the main message handler for the system	PAINTSTRUCT ps; // used in WM_PAINT	HDC			hdc; // handle to device context	// what is the message	switch(msg)	{	case WM_CREATE:		{			// do initialization stuff here			// play the music			PlaySound(MAKEINTRESOURCE(SOUND_MUSIC), hinstance_app, SND_ASYNC | SND_LOOP | SND_RESOURCE);			//return success			return(0);		} break;	case WM_PAINT:		{			// validate the window			hdc = BeginPaint(hwnd,&ps);			// do all painting here			EndPaint(hwnd,&ps);			//return success			return(0);		} break;	case WM_DESTROY:		{			// kill application, sends a WM_QUIT message			PostQuitMessage(0);			// stop the music!			PlaySound(NULL,hinstance_app,SND_PURGE);			//return success			return(0);		} break;	default:break;	} // end switch	// process any message that were not taken care of	return(DefWindowProc(hwnd,msg,wparam,lparam));} // end WinProc// WINMAIN /////////////////////////////////int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPSTR lpcmdline, int ncmdshow){	WNDCLASSEX winclass; // this is the windows class	HWND hwnd; // generic windows handle	MSG msg; // generic message	winclass.cbSize = sizeof(WNDCLASSEX);	winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;	winclass.cbClsExtra = 0;	winclass.lpfnWndProc = WindowProc;	winclass.cbClsExtra = 0;	winclass.cbWndExtra = 0;	winclass.hInstance = hinstance;	winclass.hIcon = LoadIcon(hinstance , MAKEINTRESOURCE(ID_ICON1));	winclass.hCursor = LoadCursor(hinstance, MAKEINTRESOURCE(ID_CURSOR_CROSS));	winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);	winclass.lpszMenuName = NULL;	winclass.lpszClassName = WINDOW_CLASS_NAME;	winclass.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(ID_ICON1));	// save instance in global	hinstance_app = hinstance;	// register window class	if (!RegisterClassEx(&winclass))		return(0);	//creat window	if (!(hwnd = CreateWindowEx(NULL, // exntended style		WINDOW_CLASS_NAME, // class		"Resources!", // title		WS_OVERLAPPEDWINDOW | WS_VISIBLE,		0,0, // initial x , y		400,400, // initial width , height		NULL, //handle to parent		NULL, // handle to menu		hinstance, // instance of the application		NULL))) // extra creation params		return(0);	// enter main event loop	while(TRUE)	{		// test for message		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))		{			// test for quit			if (msg.message == WM_QUIT)				break;			// translate any accelerator keys			TranslateMessage(&msg);			// send the message to the window proc			DispatchMessage(&msg);		} // end if		GameMain();	}// end while	// return to Windows	return(msg.wParam);}// end WinMainvoid GameMain(){}
make hinstance_app a HINSTANCE instead of a HANDLE.
(...more to come...)

Beginner in Game Development?  Read here. And read here.

 

Ok made that change.
Now this error comes up.

------ Build started: Project: Example 3, Configuration: Debug Win32 ------Compiling...main.cppLinking...main.obj : error LNK2019: unresolved external symbol __imp__PlaySoundA@12 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)C:\Documents and Settings\Owner\Desktop\Programming\Windows Game Programming Book\Chapter 3\Example 3\Debug\Example 3.exe : fatal error LNK1120: 1 unresolved externalsBuild log was saved at "file://c:\Documents and Settings\Owner\Desktop\Programming\Windows Game Programming Book\Chapter 3\Example 3\Example 3\Debug\BuildLog.htm"Example 3 - 2 error(s), 0 warning(s)========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_vcmcpp/html/971463b4-7178-42cc-87b4-566295b7ae50.htm

go to that URL on the VC Help Page and make sure you have everything it says is necessary.

if you do or after you do, click on the Project Menu and select "x" properties ("x" will be whatever you're project is called).

add these if you don't have them already in the Additional Dependencies section:
"kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib winmm.lib"

it should compile then. the only errors i'm getting right now are missing variables because i don't have your resources.h file. so it should work properly.

Beginner in Game Development?  Read here. And read here.

 

thanks =)

This topic is closed to new replies.

Advertisement