PlaySound() with resources

This is a discussion on PlaySound() with resources within the Windows Programming forums, part of the Platform Specific Boards category; Well, I can play sound from .wav files..., but it doesn't work with resources. Code: //sound.cpp #include <iostream> #include <windows.h> ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102

    PlaySound() with resources

    Well, I can play sound from .wav files..., but it doesn't work with resources.
    Code:
    //sound.cpp
    #include <iostream> 
    #include <windows.h>
    #include "res.h"
    #include "data.rc"
    #pragma comment(lib,"winmm")
    int main() 
    { 
      PlaySound(MAKEINTRESOURCE(ID_SOUND),NULL, SND_ASYNC | SND_RESOURCE); 
    
    }
    
    //data.rc
    
    #include "res.h"
    ID_SOUND WAVE DISCARDABLE  "data.wav"
    
    //res.h
    
    #define ID_SOUND 333
    It gives me the following error:

    Error 1 error C2059: syntax error : 'constant' c:\documents and settings\olafs.ntworld-9ba1e5e\desktop\misc\programming\visual c++ projects\general\data.rc 2

    Whats wrong with my resource? Every tutorial says exactly the same to put in there
    Code:
    ID_SOUND WAVE DISCARDABLE  "data.wav"

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    DO NOT INCLUDE RESOURCE FILES.
    Just add resource files to your project, do not #include them.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102
    Ah, thanks, now it says:
    Error 1 fatal error RC1004: unexpected end of file found c:\Documents and Settings\Olafs.NTWORLD-9BA1E5E\Desktop\Misc\Programming\Visual C++ Projects\general\res.h 1

    EDIT: It's all working now! Just added a empty line at the end of the header file.
    Thanks maxorator.
    Last edited by Overlord; 09-09-2006 at 07:07 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  2. PlaySound doesn't play when called!
    By Queatrix in forum Windows Programming
    Replies: 7
    Last Post: 03-03-2006, 08:02 PM
  3. Getting resources from another program.
    By Queatrix in forum C++ Programming
    Replies: 3
    Last Post: 02-11-2006, 09:00 PM
  4. Storing resources into a single file
    By LuckY in forum Game Programming
    Replies: 20
    Last Post: 08-15-2004, 12:28 AM
  5. Adding resources
    By nima_ranjbar in forum Windows Programming
    Replies: 0
    Last Post: 04-15-2002, 12:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21