sndPlaySoundA

New to FreeBASIC? Post your questions here.
Post Reply
lucidapogee
Posts: 19
Joined: Mar 06, 2023 2:07
Location: Arizona
Contact:

sndPlaySoundA

Post by lucidapogee »

I found some examples of using sndPlaySoundA, but am having trouble declaring it for -lang qb usage.

I have tried the following and more, but am only getting errors and no sound.

Code: Select all

'wrong
declare function PlaySound alias "sndPlaySoundA" (byval as string, byval as integer) as integer

Code: Select all

'wrong?
declare function PlaySound alias "sndPlaySoundA" (byval as string, byval as __uinteger) as integer

Code: Select all

'wrong??
declare function PlaySound alias "sndPlaySoundA" (byref as string, byval as __uinteger) as integer
How is this done correctly?
lucidapogee
Posts: 19
Joined: Mar 06, 2023 2:07
Location: Arizona
Contact:

Re: sndPlaySoundA

Post by lucidapogee »

I'm not making any progress.

For example....

Code: Select all

#LANG "qb"

DECLARE FUNCTION PLAYWAV ALIAS "sndPlaySoundA"(BYREF AS STRING, BYVAL AS __UINTEGER) AS INTEGER

LET wavname$ = "test.wav"
LET soundflags = 9

PLAYWAV wavname$, soundflags

SLEEP
gives me

Code: Select all

C:\PROGRA~1\FREEBA~1.0\bin\win32\ld.exe: qbwav.o:fake:(.text+0x96): undefined re
ference to `sndPlaySoundA@16'
I have also tried loading in the function through a DLL and get a similar error.
Imortis
Moderator
Posts: 1924
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: sndPlaySoundA

Post by Imortis »

Most people do not use lang "qb" with new code for this exact reason. Anything outside of making old qb code compile with minimal changes is a bit outside the scope of what the qb dialect was designed for. I have not had time to investigate this myself so I can't answer your question just now. I will see what I can do if the qb dialect is absolutely required, but I am not sure it is possible.
lucidapogee
Posts: 19
Joined: Mar 06, 2023 2:07
Location: Arizona
Contact:

Re: sndPlaySoundA

Post by lucidapogee »

Imortis wrote: Apr 03, 2023 1:15 Most people do not use lang "qb" with new code for this exact reason. Anything outside of making old qb code compile with minimal changesbis a bit outside the scope of what the qb dialect was designed for. I have not had time to investigate this myself so I can't answer your question just now. I will see what I can do if the qb dialect is absolutely required, but I am not sure it is possible.
Any efforts towards bringing new FB code to lang qb is valuable to me and others as well.

I compiled this.

Code: Select all

#cmdline "-pp"
#define winincludeall
#include "windows.bi" 
#include "win/mmsystem.bi"
looked though the results and found these definitions

Code: Select all

declare function sndPlaySoundA(byval pszSound as LPCSTR, byval fuSound as UINT) as WINBOOL
declare function sndPlaySoundW(byval pszSound as LPCWSTR, byval fuSound as UINT) as WINBOOL

 declare function sndPlaySound alias "sndPlaySoundA"(byval pszSound as LPCSTR, byval fuSound as UINT) as WINBOOL

const SND_SYNC = &h00000
const SND_ASYNC = &h0001
const SND_NODEFAULT = &h0002
const SND_MEMORY = &h0004
const SND_LOOP = &h0008
const SND_NOSTOP = &h0010
const SND_NOWAIT = &h00002000
const SND_ALIAS = &h00010000
const SND_ALIAS_ID = &h00110000
const SND_FILENAME = &h00020000
const SND_RESOURCE = &h00040004
const SND_PURGE = &h0040
const SND_APPLICATION = &h0080
const SND_ALIAS_START = 0
declare function PlaySoundA(byval pszSound as LPCSTR, byval hmod as HMODULE, byval fdwSound as DWORD) as WINBOOL
declare function PlaySoundW(byval pszSound as LPCWSTR, byval hmod as HMODULE, byval fdwSound as DWORD) as WINBOOL

 declare function PlaySound alias "PlaySoundA"(byval pszSound as LPCSTR, byval hmod as HMODULE, byval fdwSound as DWORD) as WINBOOL
I tried defining with something like this, but no luck no matter how I try writing it.

Code: Select all

DECLARE FUNCTION PLAYWAV ALIAS "sndPlaySound"(BYVAL pszSound AS LPCSTR, BYVAL fuSound AS __UINT) AS WINBOOL

I was able to get the beep command working for now. This is a good start. I will be pulling my hair out trying to figure out how to play wav files with windows API now.

Code: Select all

DECLARE FUNCTION SOUND ALIAS "BEEP"(BYVAL f AS INTEGER,BYVAL d AS INTEGER) AS INTEGER
lucidapogee
Posts: 19
Joined: Mar 06, 2023 2:07
Location: Arizona
Contact:

Re: sndPlaySoundA

Post by lucidapogee »

EDIT: Why isn't the code tag working?

Feels like I am getting warmer. The issue seems to be WINBOOL.

Code: Select all

#LANG "qb"

#DEFINE LPCSTR __ZSTRING __PTR
#DEFINE QBWINB WINBOOL LONG

DECLARE FUNCTION PlaySound ALIAS "sndPlaySoundA" (BYVAL AS LPCSTR, BYVAL AS __UINTEGER=0) AS QBWINB

LET n$ = "test.wav"
LET f = 9

PLAYSOUND n$, INT(f)

SLEEP

Trying to match the parameters with pp.bas

Code: Select all

declare function sndPlaySoundA(byval pszSound as LPCSTR, byval fuSound as UINT) as WINBOOL
declare function sndPlaySoundW(byval pszSound as LPCWSTR, byval fuSound as UINT) as WINBOOL

 declare function sndPlaySound alias "sndPlaySoundA"(byval pszSound as LPCSTR, byval fuSound as UINT) as WINBOOL

const SND_SYNC = &h00000
const SND_ASYNC = &h0001
const SND_NODEFAULT = &h0002
const SND_MEMORY = &h0004
const SND_LOOP = &h0008
const SND_NOSTOP = &h0010
const SND_NOWAIT = &h00002000
const SND_ALIAS = &h00010000
const SND_ALIAS_ID = &h00110000
const SND_FILENAME = &h00020000
const SND_RESOURCE = &h00040004
const SND_PURGE = &h0040
const SND_APPLICATION = &h0080
const SND_ALIAS_START = 0
declare function PlaySoundA(byval pszSound as LPCSTR, byval hmod as HMODULE, byval fdwSound as DWORD) as WINBOOL
declare function PlaySoundW(byval pszSound as LPCWSTR, byval hmod as HMODULE, byval fdwSound as DWORD) as WINBOOL

 declare function PlaySound alias "PlaySoundA"(byval pszSound as LPCSTR, byval hmod as HMODULE, byval fdwSound as DWORD) as WINBOOL
Last edited by fxm on Apr 07, 2023 18:01, edited 1 time in total.
Reason: In the 'options' tab of 'Edit post', you must not check the box 'disable BBcode'. (in your 'User Control Panel / Board preferences / Edit posting defaultd', check the box 'Enable BBcode by default').
Post Reply