PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Probleme mit PlaySound (Split aus: VS C++ 05 EE, PFSDK, DXSDK)


BavariaBlade
2006-02-20, 19:29:06
Hi,

ich hab hier ähnliche Probleme, da ich allerdings ein absoluter C++ Noob bin komm ich hier garmicht weiter.
Also ich hab das DXSDK (Feb06), und das PSDK, als IDE hab ich ebenfalls die VS C++ express edition von Microsoft.

PlaySound(...); will aber nicht funzen und ich weiß nicht warum?

Hier mal mein code:

// SoundTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <Mmsystem.h>

int _tmain(int argc, _TCHAR* argv[])
{
bool eins;

//PlaySound("test.wav",NULL, SND_ASYNC | SND_NODEFAULT );
eins PlaySound(NULL,NULL, 0);

return 0;
}


und Hier die Fehlermeldung die ich bekomme:


------ Build started: Project: SoundTest, Configuration: Debug Win32 ------
Compiling...
SoundTest.cpp
c:\programme\microsoft platform sdk\include\mmsystem.h(103) : error C2146: syntax error : missing ';' before identifier 'MMVERSION'
c:\programme\microsoft platform sdk\include\mmsystem.h(103) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(103) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(111) : error C2143: syntax error : missing ';' before '*'
c:\programme\microsoft platform sdk\include\mmsystem.h(111) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(121) : error C2146: syntax error : missing ';' before identifier 'ms'
c:\programme\microsoft platform sdk\include\mmsystem.h(121) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(121) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(122) : error C2146: syntax error : missing ';' before identifier 'sample'
c:\programme\microsoft platform sdk\include\mmsystem.h(122) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(122) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(123) : error C2146: syntax error : missing ';' before identifier 'cb'
c:\programme\microsoft platform sdk\include\mmsystem.h(123) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(123) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(124) : error C2146: syntax error : missing ';' before identifier 'ticks'
c:\programme\microsoft platform sdk\include\mmsystem.h(124) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(124) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(129) : error C2146: syntax error : missing ';' before identifier 'hour'
c:\programme\microsoft platform sdk\include\mmsystem.h(129) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(129) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(130) : error C2146: syntax error : missing ';' before identifier 'min'
c:\programme\microsoft platform sdk\include\mmsystem.h(130) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(130) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(131) : error C2146: syntax error : missing ';' before identifier 'sec'
c:\programme\microsoft platform sdk\include\mmsystem.h(131) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(131) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(132) : error C2146: syntax error : missing ';' before identifier 'frame'
c:\programme\microsoft platform sdk\include\mmsystem.h(132) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(132) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(133) : error C2146: syntax error : missing ';' before identifier 'fps'
c:\programme\microsoft platform sdk\include\mmsystem.h(133) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(133) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(134) : error C2146: syntax error : missing ';' before identifier 'dummy'
c:\programme\microsoft platform sdk\include\mmsystem.h(134) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(134) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(136) : error C2146: syntax error : missing ';' before identifier 'pad'
c:\programme\microsoft platform sdk\include\mmsystem.h(136) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(136) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(143) : error C2146: syntax error : missing ';' before identifier 'songptrpos'
c:\programme\microsoft platform sdk\include\mmsystem.h(143) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(143) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(146) : error C2143: syntax error : missing ';' before '*'
c:\programme\microsoft platform sdk\include\mmsystem.h(146) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(146) : error C2143: syntax error : missing ';' before '*'
c:\programme\microsoft platform sdk\include\mmsystem.h(146) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(146) : error C2377: 'FAR' : redefinition; typedef cannot be overloaded with any other symbol
c:\programme\microsoft platform sdk\include\mmsystem.h(111) : see declaration of 'FAR'
c:\programme\microsoft platform sdk\include\mmsystem.h(146) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(285) : error C2065: 'HDRVR' : undeclared identifier
c:\programme\microsoft platform sdk\include\mmsystem.h(285) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(298) : error C2146: syntax error : missing ';' before identifier 'dwDCISize'
c:\programme\microsoft platform sdk\include\mmsystem.h(298) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(298) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(299) : error C2146: syntax error : missing ';' before identifier 'lpszDCISectionName'
c:\programme\microsoft platform sdk\include\mmsystem.h(299) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(299) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(300) : error C2146: syntax error : missing ';' before identifier 'lpszDCIAliasName'
c:\programme\microsoft platform sdk\include\mmsystem.h(300) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(300) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(301) : error C2146: syntax error : missing ';' before identifier 'dnDevNode'
c:\programme\microsoft platform sdk\include\mmsystem.h(301) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(301) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(302) : error C2143: syntax error : missing ';' before '*'
c:\programme\microsoft platform sdk\include\mmsystem.h(302) : error C2371: 'NEAR' : redefinition; different basic types
c:\programme\microsoft platform sdk\include\mmsystem.h(146) : see declaration of 'NEAR'
c:\programme\microsoft platform sdk\include\mmsystem.h(302) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(302) : error C2143: syntax error : missing ';' before '*'
c:\programme\microsoft platform sdk\include\mmsystem.h(302) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(302) : error C2086: 'int FAR' : redefinition
c:\programme\microsoft platform sdk\include\mmsystem.h(146) : see declaration of 'FAR'
c:\programme\microsoft platform sdk\include\mmsystem.h(302) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(336) : error C2146: syntax error : missing ';' before identifier 'dwDCISize'
c:\programme\microsoft platform sdk\include\mmsystem.h(336) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(336) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(337) : error C2146: syntax error : missing ';' before identifier 'lpszDCISectionName'
c:\programme\microsoft platform sdk\include\mmsystem.h(337) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(337) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(338) : error C2146: syntax error : missing ';' before identifier 'lpszDCIAliasName'
c:\programme\microsoft platform sdk\include\mmsystem.h(338) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(338) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(339) : error C2143: syntax error : missing ';' before '*'
c:\programme\microsoft platform sdk\include\mmsystem.h(339) : error C2371: 'NEAR' : redefinition; different basic types
c:\programme\microsoft platform sdk\include\mmsystem.h(146) : see declaration of 'NEAR'
c:\programme\microsoft platform sdk\include\mmsystem.h(339) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(339) : error C2143: syntax error : missing ';' before '*'
c:\programme\microsoft platform sdk\include\mmsystem.h(339) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(339) : error C2086: 'int FAR' : redefinition
c:\programme\microsoft platform sdk\include\mmsystem.h(146) : see declaration of 'FAR'
c:\programme\microsoft platform sdk\include\mmsystem.h(339) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(356) : error C2065: 'CALLBACK' : undeclared identifier
c:\programme\microsoft platform sdk\include\mmsystem.h(356) : error C2065: 'DRIVERPROC' : undeclared identifier
c:\programme\microsoft platform sdk\include\mmsystem.h(356) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\programme\microsoft platform sdk\include\mmsystem.h(356) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Build log was saved at "file://c:\Dokumente und Einstellungen\Blade\Eigene Dateien\Visual Studio 2005\Projects\SoundTest\SoundTest\Debug\BuildLog.htm"
SoundTest - 88 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Wenn mir einer von euch helfen can, das wär zu geil. :)

Sephiroth
2006-02-20, 20:34:28
#include <windows.h>
außerdem mußt du das mit winmm.lib linken

dazu
#pragma comment(lib, "winmm.lib")
nach den includes einfügen

p.s.
das
eins PlaySound(NULL,NULL, 0);
wird nix ;)

so wird's was

#include <windows.h>
#include <TCHAR.h>
#include <Mmsystem.h>
#pragma comment(lib, "winmm.lib")

int _tmain(int argc, _TCHAR* argv[])
{
PlaySound("test.wav",NULL, SND_FILENAME | SND_SYNC);

return 0;
}

das tut's auch

#include <windows.h>
#include <Mmsystem.h>
#pragma comment(lib, "winmm.lib")

int main()
{
PlaySound("test.wav",NULL, SND_FILENAME | SND_SYNC);

return 0;
}

BavariaBlade
2006-02-20, 21:06:55
Danke danke :)

der Sound spielt zwar nch nicht ab, aber es compiliert jetzt richtig.
Gibts ne Möglichkeit diese winmm.lib auch anders zu verlinken, eventuell in den Projekt Settings oder so, da hab ich nämlich den ganzen Tag schon gesucht/rumprobiert.

thx servus BB

Sephiroth
2006-02-20, 21:36:06
Danke danke :)

der Sound spielt zwar nch nicht ab, aber es compiliert jetzt richtig.
Gibts ne Möglichkeit diese winmm.lib auch anders zu verlinken, eventuell in den Projekt Settings oder so, da hab ich nämlich den ganzen Tag schon gesucht/rumprobiert.

thx servus BB
Projekt-Eigenschaften > Linker > Input > Additional Dependencies und unter Linker > General noch den Lib-Ordner des PSDKs bei Additional Library Directories angeben.

/edit
Wieso wird die Datei nicht abgespielt?

BavariaBlade
2006-02-21, 00:22:08
Hm,

anscheinend hat ers doch noch nicht richtig kompiliert.
Also ich mache jetzt immer einen rechtsklick auf das Projekt->Build
und folgende Fehlermeldung kommt:
CODE:

#include <windows.h>
#include <TCHAR.h>
#include <Mmsystem.h>
#pragma comment(lib, "winmm.lib")

int _tmain(int argc, _TCHAR* argv[])
{

PlaySound("test.wav",NULL,SND_FILENAME | SND_SYNC);

return 0;
}



Fehlermeldung dazu:
------ Build started: Project: SoundTest, Configuration: Debug Win32 ------
Compiling...
SoundTest.cpp
.\SoundTest.cpp(19) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Build log was saved at "file://c:\Dokumente und Einstellungen\Blade\Eigene Dateien\Visual Studio 2005\Projects\SoundTest\SoundTest\Debug\BuildLog.htm"
SoundTest - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


wenn ich nun die stdafx.h noch einbinde, also so:
#include "stdafx.h"
#include <windows.h>
#include <TCHAR.h>
#include <Mmsystem.h>
#pragma comment(lib, "winmm.lib")

int _tmain(int argc, _TCHAR* argv[])
{

PlaySound("test.wav",NULL,SND_FILENAME | SND_SYNC);

return 0;
}

dann kommt follgende Fehlermeldung:

------ Build started: Project: SoundTest, Configuration: Debug Win32 ------
Compiling...
SoundTest.cpp
.\SoundTest.cpp(14) : error C2664: 'PlaySoundW' : cannot convert parameter 1 from 'const char [9]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build log was saved at "file://c:\Dokumente und Einstellungen\Blade\Eigene Dateien\Visual Studio 2005\Projects\SoundTest\SoundTest\Debug\BuildLog.htm"
SoundTest - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

hm, parameter 1 ist doch der String "test.wav" hm, der hat mit dem guten alten Nullbyte doch aber nur 9 Elemente als char array. Also von 0-8. Ich versteh jetzt nicht warum der über das Element an Pos 9 mekert, das gibts doch garnicht..grübel.

Sephiroth
2006-02-21, 01:15:44
stdafx.h
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <Mmsystem.h>

"test.wav" ist vom Typ LPCSTR

entweder verwendest du da explizit PlaySoundA oder aber _T("test.wav"), denn es wird PlaySoundW genutzt, welches ein Unicode string haben will - genauer LPCWTRS. LPCWSTR ist das selbe wie const wchar_t* - also ein constant zero-terminated Unicode string.
Solche deklarierst du mit einem L vor dem String oder du nutzt das Macro _T(x).

SoundTest.cpp
#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
// const wchar_t* sndFilename = L"test.wav");
LPCWSTR sndFilename = _T("test.wav"); // äquivalent zum vorigen
PlaySound(sndFilename, NULL, SND_FILENAME | SND_SYNC);
return 0;
}

Zur Info wann PlaySound PlaySoundW und wann PlaySoundA ist:
#ifdef _WIN32
....

WINMMAPI BOOL WINAPI PlaySoundA( IN LPCSTR pszSound, IN HMODULE hmod, IN DWORD fdwSound);
WINMMAPI BOOL WINAPI PlaySoundW( IN LPCWSTR pszSound, IN HMODULE hmod, IN DWORD fdwSound);
#ifdef UNICODE
#define PlaySound PlaySoundW
#else
#define PlaySound PlaySoundA
#endif // !UNICODE

#else
BOOL WINAPI PlaySound(LPCSTR pszSound, HMODULE hmod, DWORD fdwSound);
#endif
aha, also wenn UNICODE definiert ist und das wird es bei MSVC++ 2005 standardmäßig und kann durch setzen von Character Set auf "not set" unter Project-Properties > Configuration Properties > General deaktiviert werden.
Daher hat es übrigens bei mir vorhin über die command line mit "test.wav" geklappt. ;)
_T("foobar") ist bei UNICODE das gleiche wie wenn man L"foobar" schreibt und wenn UNICODE nicht def. ist, dann ist es ganz normal "foobar".

hier mal noch ein passendes konstrukt für LPCWSTR und LPCSTR ;D

#include "stdafx.h";
#ifdef UNICODE
typedef const wchar_t* FOOBAR;
#else
typedef const char* FOOBAR;
#endif


int _tmain(int argc, _TCHAR* argv[])
{
FOOBAR sndFilename = __T("test.wav");
PlaySound(sndFilename, NULL, SND_FILENAME | SND_SYNC);
return 0; // sollte der Compiler eh einfügen, kann man daher auch weggelassen
}

BavariaBlade
2006-02-21, 09:03:37
DAAAAAAAAAAAAAAAAAANNNNNNNNNKKKKEEEEE!

Ich glaube das hätte mich Monate gekostet.
Es macht jetzt endlich Sound!!

OK hier mal mein Code für alle Mitleser:


/ SoundTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <Mmsystem.h>


int _tmain(int argc, _TCHAR* argv[])
{
PlaySound("test.wav",NULL,SND_FILENAME | SND_SYNC);
return 0;
}


Dabei muss man noch 3 Einstellungen in den Projekt Properties ändern:
1.) Linker > General >Additional Library Directories: "C:\Programme\Microsoft Platform SDK\Lib"
2.) Linker > Input > Additional Dependencies: "kernel32.lib winmm.lib
3.) General>Character Set> NOT SET

damit sollte der obige Code ausführbar sein.

thx nochmal Sephiroth
sevus BB