PlaySound Win API

This is a discussion on PlaySound Win API within the Windows Programming forums, part of the Platform Specific Boards category; hey im having a problem with the PlaySound APi call; i am used to using sndPlaySound from user32.dll (when i ...

  1. #1
    INNEEDOFHELP
    Guest

    PlaySound Win API

    hey im having a problem with the PlaySound APi call;
    i am used to using sndPlaySound from user32.dll (when i program in vb) but for some reason in c++ (M$ VC++6.0ent) even though i include all the necessary headers i cant get either call to work; ive tried including the complete windows.h header without the 'lean_and_mean' comment but although it recognises the calls it still finds problems with the externals,
    maybee its just my code? this is what im using:

    Code:
    //example code
    #include "windows.h"
    int DoSound()
    {
    PlaySound("c:\\a.wav",NULL,SND_FILENAME);
    //have also tried the PlaySoundA rerefrence and the 
    //sndPlaySound call but it still dont work!!!!
    return 1;
    }
    am i calling enough headers? any help would be great or else i'l have to use the anoying mci calls.
    thanx

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    add this to the top

    Code:
     #pragma comment(lib,"winmm.lib")

  3. #3
    INNEEDOFHELP
    Guest
    Thanx that worked great

  4. #4
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    i've never done sound in windows API. does the sound go on while further code is being executed (say if its a long sound)?

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Leeman_s
    i've never done sound in windows API. does the sound go on while further code is being executed (say if its a long sound)?
    By default it is a blocking call ( synchronous function ). However, I believe there is an asynchronously flag you can set that will let other code execute while the sound is playing. The flag is SND_ASYNC if I remember correctly.

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by hore
    I have a question...

    Is there any way I can make a sound in my Windows app? Something beep? without having to play any particular sound file like that which was demonstrated above? ty.
    Code:
    #include <windows.h>
    
    int main(int argc, char* argv[])
    {
    	for(int i = 0;i < 50;++i){
    		MessageBeep(MB_OK);
    		Sleep(150);
    	}
    	return 0;
    }

  7. #7
    hore
    Guest
    I have a question...

    Is there any way I can make a sound in my Windows app? Something beep? without having to play any particular sound file like that which was demonstrated above? ty.

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Wow, that Fordy sure is quick to answer!

  9. #9
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by swoopy
    Wow, that Fordy sure is quick to answer!
    I just knew he was going to say that

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by hore
    I have a question...

    Is there any way I can make a sound in my Windows app? Something beep? without having to play any particular sound file like that which was demonstrated above? ty.
    There sure is. Here is the function prototype:

    Code:
    BOOL MessageBeep( UINT uType );
    For additional information please search MSDN.

    http://msdn.microsoft.com/library/de...essagebeep.asp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with this
    By tyrantil in forum C Programming
    Replies: 18
    Last Post: 01-30-2005, 03:53 PM
  2. win api literature
    By DMaxJ in forum Windows Programming
    Replies: 5
    Last Post: 04-30-2004, 03:25 PM
  3. Help with editor windows with win api
    By NightStalker in forum Windows Programming
    Replies: 1
    Last Post: 03-13-2003, 02:53 AM
  4. Win API
    By Marky_Mark in forum Windows Programming
    Replies: 4
    Last Post: 10-23-2001, 12:57 PM
  5. Rich edit control example Win API
    By Echidna in forum Windows Programming
    Replies: 1
    Last Post: 09-17-2001, 02:12 AM

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