Playsound Linker Error
#include int main() { PlaySound(TEXT("bomb.wav"), NULL, SND_FILENAME); return 0; } 1 way i tried (as instructed on these
Playsound C++ Example
forums) to link to winmm.lib and when i did that is undefined reference to playsound@12 came up with an error saying it cant find winmm.lib. Another way i tried was without
Winmm.lib Download
linking and it says: undefinded reference to 'PlaySoundA@12' I also tried changing the code in different ways... 1
2
3
4
5
6
7
#include #include int main() { PlaySound("bomb.wav", NULL, SND_FILENAME); winmm.lib location return 0; } and 1
2
3
4
5
6
7
8
#include #include #include int main() { PlaySound(TEXT("bomb.wav"), NULL, SND_FILENAME); return 0; } (comes up that there is no such file or directory called winmm.lib) I have tried all the different ways on 2 different editors.(Code::Blocks & Dev C++) can someone explain why it wont work and please undefined reference to playsound@12' code blocks dont just send me to a link somewhere else? Jun 12, 2011 at 10:21pm UTC Lamblion (642) You do NOT #include You LINK to winmm.lib in your additional dependencies configuration, whatever that is for Dec C++ or Code::Blocks, as I don't use either one. In VS it's under Properties | Linker | Input | Additional Dependencies Once there, you add winmm.lib as an additional dependency. Last edited on Jun 12, 2011 at 10:22pm UTC Jun 22, 2011 at 4:39am UTC bhattaroshan (4) that means winmm.lib file in your library is missing you can either re-install the program or just download winmm.lib and paste in correct directory. but there is another option for you. i.e. if you load the dll dynamically then you don't need library files. so try loading winmm.dll dynamically this might help you. also make note that PlaySound cannot play sound file of large size may be greater than 1mb (i guess) in this case you can use function mci
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow
Snd_async
the company Business Learn more about hiring developers or posting ads with us Stack playsoundw Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of
Mp3 To Wav
6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to PlaySound in C++ using Windows API? up vote 9 down vote favorite 3 I try http://www.cplusplus.com/forum/windows/44705/ to play a music file in my coding, but failed. I have my music file in the same folder which save .cpp file. Can someone help me? My code is: #include #include int main() { PlaySound("kenny g.WAV", NULL, SND_ASYNC); } c++ winapi playsound share|improve this question edited Sep 5 '13 at 5:17 WiSaGaN 23.3k52057 asked Oct 14 '09 at 10:23 user189748 What is the error code you are http://stackoverflow.com/questions/1565439/how-to-playsound-in-c-using-windows-api getting with GetErrorCode() function? –Naveen Oct 14 '09 at 10:27 i'm not sure about the GetErrorCode() but the error message is [Linker error]undefined reference to 'PlaySound@12' id returned 1 exit status –user189748 Oct 14 '09 at 10:33 You need winmm.lib to play music as Luis mentioned –ukanth Oct 14 '09 at 10:53 add a comment| 7 Answers 7 active oldest votes up vote 8 down vote You need to use the absolute path, make sure that you're sending a filename (use SND_FILENAME flag), and pause the program long enough to play the sound file (e.g., use getchar()). You need to link the winmm.lib library in your project settings, and #include windows.h and mmsystem.h in the header. #include #include int main() { PlaySoundA((LPCSTR) "C:\\kenny g.WAV", NULL, SND_FILENAME | SND_ASYNC); getchar(); } API: http://msdn.microsoft.com/en-us/library/ms712879(VS.85).aspx That should be it. Let me know, thanks! share|improve this answer edited Jun 24 at 5:17 aaronsnoswell 3,01112454 answered Oct 14 '09 at 10:40 Luis B 809614 1 How would you compile that example under gcc/windows? –lowerkey Jun 18 '10 at 15:42 add a comment| up vote 3 down vote try adding -lwinmm to your compiler settings thingy. It worked for me. Just type that in the compiler options area and it will work. share|imp
Studio Languages , Windows Desktop Development > Visual C++ Question 0 Sign in to vote https://social.msdn.microsoft.com/Forums/vstudio/en-US/dff0c5e3-007c-430f-a4d3-350dbfce969f/error-lnk2019-unresolved-external-symbol-impplaysoundw12?forum=vcgeneral I wanna create a SDI with a dialog , which can play countdown sound after press a button . how ever , the code end https://www.daniweb.com/programming/software-development/threads/375350/dev-c-playsound-function-in-windows-project-help up with 2 errors which can not resolved . I check and search the msdn forums and do get some knowledge but it do not undefined reference work . so the code will be posted ,and I wanna to get a helping hand : according to some artical , "#include " was put in the head file , and "Winmm.lib" was add on the item "project property pages-Linker-General-Additional Library Directories" . // CountDlg.cpp : implementation file// undefined reference to #include "stdafx.h"#include "TimeRecord_try4.h"#include "CountDlg.h"#include // CCountDlg dialog IMPLEMENT_DYNAMIC(CCountDlg, CDialog) CCountDlg::CCountDlg(CWnd* pParent /*=NULL*/) : CDialog(CCountDlg::IDD, pParent) , m_RadioStart(0) , m_Notice(_T("the process will automatically record the first data right away ...")) , m_Seconds(0) , m_bCount(false) , m_TimeLeft(0){ } CCountDlg::~CCountDlg(){} void CCountDlg:oDataExchange(CDataExchange* pDX){ CDialog:oDataExchange(pDX); DDX_Radio(pDX, IDC_RADIO1, m_RadioStart); DDX_Text(pDX, IDC_STATIC_NOTICE, m_Notice);} BEGIN_MESSAGE_MAP(CCountDlg, CDialog) ON_BN_CLICKED(IDC_RADIO1, &CCountDlg:nBnClickedRadio1) ON_BN_CLICKED(IDC_RADIO2, &CCountDlg:nBnClickedRadio2) ON_BN_CLICKED(IDC_RADIO3, &CCountDlg:nBnClickedRadio3) ON_BN_CLICKED(IDC_BUTTON2, &CCountDlg:nBnClickedButton2) ON_WM_CREATE() ON_WM_DESTROY() ON_BN_CLICKED(IDC_BUTTON1, &CCountDlg:nBnClickedButton1) ON_WM_TIMER()END_MESSAGE_MAP() // CCountDlg message handlers void CCountDlg:nBnClickedRadio1(){ // TODO: Add your control notification handler code here m_RadioStart = 0; m_Notice = _T("the process will automatically record the first data right away ..."); UpdateData(FALSE);} void CCountDlg:nBnClickedRadio2(){ // TODO: Add your control notification handler code here m_RadioStart = 1; m_Notice = _T("the process will automatically record the first in 10 seconds ."); UpdateData(FALSE);} void CCountDlg:nBnClickedRadio3(){ // TODO: Add your control notification handler code here m_RadioStart = 2; m_Notice = _T("the process will automatically record the first data in 30 seconds ."); UpdateData(FALSE);} void CCountDlg:nBnClickedButton2(){ // TODO: Add your control notification handler code here OnCancel();} int CCountDlg:nCreate(LPCREATESTRUCT lpCreateStruct){ if (CDialog:nCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here SetTimer(2,1000,NULL); return 0;} void CCountDlg:nDestroy(){ CDialog:nDestroy
I am trying to make a one octave piano. heres my code: #include #include #include /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); /* Make the class name into a global variable */ char szClassName[ ] = "WindowsApp"; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ "Piano", /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 544, /* The programs width */ 375, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Make the window visible on the screen */ ShowWindow (hwnd, nFunsterStil); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages