Did Freebasic 1.0 change library locations?

General FreeBASIC programming questions.
lassar
Posts: 302
Joined: Jan 17, 2006 1:35
Contact:

Did Freebasic 1.0 change library locations?

Postby lassar » Feb 11, 2016 8:32

I was try to compile RadioTelephone Tutor using Freebasic 1.0.

It compiles, and works good on Freebasic 24.

Compiles, and doesn't work with Freebasic 1.0


What changed in Freebasic 1.0

Has some of the library locations changed?

Example of trouble:

Code: Select all

DECLARE SUB PlayWave(BYREF SoundFile$)
DECLARE FUNCTION sndPlaySound LIB "WINMM" ALIAS "sndPlaySoundA" (byval lpszSoundName$, BYVAL uFlags AS DWORD) AS LONG

PlayWave "Sound.wav"

SLEEP

END

SUB PlayWave(BYREF Sound$)
    SndPlaySound BYVAL "", SND_SYNC  'stop anything currently playing
    SndPlaySound Sound$, SND_ASYNC
END SUB
D.J.Peters
Posts: 8024
Joined: May 28, 2005 3:28
Contact:

Re: Did Freebasic 1.0 change library locations?

Postby D.J.Peters » Feb 11, 2016 9:24

Code: Select all

DECLARE FUNCTION sndPlaySound LIB "WINMM" ALIAS "sndPlaySoundA" (SoundName as zstring ptr, uFlags AS LONG) AS LONG

SUB PlayWave(Sound as string)
  const SND_SYNC = &h0000
  const SND_ASYNC = &h0001
  SndPlaySound "", SND_SYNC  'stop anything currently playing
  SndPlaySound Sound, SND_ASYNC
END SUB

PlayWave "Sound.wav"

SLEEP
fxm
Posts: 9637
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Did Freebasic 1.0 change library locations?

Postby fxm » Feb 11, 2016 12:24

Yes.

I think that since the beginning, your declaration of "SndPlaySound(byval as string, ...)" is not the good (rather should be "byval as zstring ptr"):
- But up to fbc version 1.00.0, "byval as string" behaved like "byref as zstring", so that a "zstring Ptr" was passed to the procedure which is compatible of it (a reference is always passed by its address).
- Now "byval as string" works normally and a copied string is passed (by means of its descriptor) to the procedure which is not compatible of that (the procedure uses the passed descriptor as a zstring!).
lassar
Posts: 302
Joined: Jan 17, 2006 1:35
Contact:

Re: Did Freebasic 1.0 change library locations?

Postby lassar » Feb 11, 2016 16:34

I am beginning to to think that FB 1.0 broke FBLITE mode.

You code works in fb (default mode) ,but does not work in FBLITE.

Anyone have any idea why?


Code: Select all

#LANG "FBLITE"

DECLARE FUNCTION sndPlaySound LIB "WINMM" ALIAS "sndPlaySoundA" (SoundName as zstring ptr, uFlags AS LONG) AS LONG
DECLARE SUB PlayWave(Sound as string)

SUB PlayWave(Sound as string)
  const SND_SYNC = &h0000
  const SND_ASYNC = &h0001
  SndPlaySound "", SND_SYNC  'stop anything currently playing
  SndPlaySound Sound, SND_ASYNC
END SUB

PlayWave "sound.wav"

SLEEP
END



I also tried this:


Code: Select all

#LANG "FBLITE"

DECLARE FUNCTION sndPlaySound LIB "WINMM" ALIAS "sndPlaySoundA" (SoundName as zstring ptr, uFlags AS LONG) AS LONG
DECLARE SUB PlayWave(Sound AS STRING)

SUB PlayWave(Sound AS STRING)
  DIM MySound AS zstring ptr
  MySound = STRPTR(Sound)
  const SND_SYNC = &h0000
  const SND_ASYNC = &h0001
  SndPlaySound "", SND_SYNC  'stop anything currently playing
  SndPlaySound MySound, SND_ASYNC
END SUB

PlayWave "code.wav"

SLEEP
END

dkl
Site Admin
Posts: 3211
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Did Freebasic 1.0 change library locations?

Postby dkl » Feb 11, 2016 17:59

It looks like the Byval keywords are missing. Remember that fblite uses Byref by default, so it probably needs to be:

Code: Select all

DECLARE FUNCTION sndPlaySound LIB "WINMM" ALIAS "sndPlaySoundA" (BYVAL SoundName as zstring ptr, BYVAL uFlags AS LONG) AS LONG
fxm
Posts: 9637
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Did Freebasic 1.0 change library locations?

Postby fxm » Feb 11, 2016 22:24

That is why I advise to users (as I do myself) to always define explicitly all parameter passing conventions (except for arrays).
In order to not forget one, by compiling with option '-w param' or '-w pedantic' warns each time that a procedure parameter is not specified with either ByVal or ByRef.
This has the advantage of forcing themselves to ask the question of passing convention for each parameter.

Return to “General”

Who is online

Users browsing this forum: Google [Bot] and 10 guests