Quantcast
Channel: SCN : All Content - PowerBuilder Developer Center
Viewing all articles
Browse latest Browse all 2935

Can't Play system sounds

$
0
0

I can't play system sounds using windows API.

Here is my PB 11.5 Classic function:

 

Function boolean PlaySoundW (string SoundName, long hModule, uint Flags) Library "WINMM.DLL"
Function uint waveOutGetNumDevs () Library "WINMM.DLL"

 

 

uint lui_NumDevs
long ll_mode
long ll_module

CONSTANT Long SND_APPLICATION = 128 // look for application specific association
CONSTANT Long SND_ALIAS = 65536 // name is a WIN.INI [sounds] entry
CONSTANT Long SND_ALIAS_ID = 1114112 // name is a WIN.INI [sounds] entry identifier
CONSTANT Long SND_ASYNC = 1 // play asynchronously
CONSTANT Long SND_FILENAME = 131072 // name is a file name
CONSTANT Long SND_LOOP = 8 // loop the sound until next sndPlaySound
CONSTANT Long SND_MEMORY = 4 // lpszSoundName points to a memory file
CONSTANT Long SND_NODEFAULT = 2 // silence not default, if sound not found
CONSTANT Long SND_NOSTOP = 16 // don't stop any currently playing sound
// NOT IMPLEMENTED: CONSTANT Long SND_NOWAIT = 8192 // don't wait if the driver is busy
CONSTANT Long SND_PURGE = 64 // purge non-static events for task
CONSTANT Long SND_RESOURCE = 262148 // name is a resource name or atom
CONSTANT Long SND_SYNC = 0 // play synchronously (default)

CONSTANT LONG SND_ALIAS_START = 0
CONSTANT LONG SND_ALIAS_SYSTEMHAND = 18515
CONSTANT LONG SND_ALIAS_SYSTEMEXCLAMATION = 8531
CONSTANT LONG SND_ALIAS_SYSTEMASTERISK = 10835
CONSTANT LONG SND_ALIAS_SYSTEMQUESTION = 16211
CONSTANT LONG SND_ALIAS_SYSTEMDEFAULT = 17491
CONSTANT LONG SND_ALIAS_SYSTEMEXIT = 17747
CONSTANT LONG SND_ALIAS_SYSTEMSTART = 21331
CONSTANT LONG SND_ALIAS_SYSTEMWELCOME = 22355


// Not used
setnull(ll_module)

// Detect mode
if ab_system then
    ll_mode = SND_ALIAS_ID
else    ll_mode = SND_FILENAME
end if
ll_mode += SND_NODEFAULT
if not ab_blocking then    // Async    ll_mode += SND_ASYNC
end if

// No crash/error handling needed
TRY
    lui_NumDevs = WaveOutGetNumDevs()    IF lui_NumDevs > 0 THEN        if not PlaySoundW(as_sound, ll_module, ll_mode) then            // Playsound Error            // Throw ???            messagebox("Playsound error", "")        end if    ELSE        // No audio        // Throw ???    END IF 
CATCH (runtimeerror lre)    // No errors
END TRY

 

And here is how I call it:

nc_smart.of_playsound("d:\test.wav", false, true)
nc_smart.of_playsound("18515", true, true)
nc_smart.of_playsound("SND_ALIAS_SYSTEMHAND", true, true)

 

First call works ok and plays the file.

Second and third calls pop the messagebox error

 

I've tried it in c++ and it works well:

#include "Windows.h"
#include "Mmsystem.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{    //stdout << SND_ASYNC;    //return 100;    printf("Playing SND_ALIAS_SYSTEMHAND %d\n", SND_ALIAS_SYSTEMHAND);    PlaySoundA((LPCTSTR)SND_ALIAS_SYSTEMHAND, NULL, SND_ALIAS_ID | SND_NODEFAULT);    printf("Playing SND_ALIAS_SYSTEMEXCLAMATION %d\n", SND_ALIAS_SYSTEMEXCLAMATION);    PlaySoundA((LPCTSTR)SND_ALIAS_SYSTEMEXCLAMATION, NULL, SND_ALIAS_ID | SND_NODEFAULT);    return 0;
}

 

 

What's wrong with my PB code?

 

PS: I've tried with the ansi version but same error occurs


Viewing all articles
Browse latest Browse all 2935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>