Bass: Specifying another file location?

BlitzMax Forums/Brucey's Modules/Bass: Specifying another file location?

MGE(Posted 2009) [#1]
Is there a way to specify where the bass.dll is? For screensavers, I don't want to place the bass.dll inside the same location as the screensaver (windows) because another version of bass (older or newer) may be there and cause problems. Thanks.


MGE(Posted 2009) [#2]
Or.....if we could somehow rename the .dll to a specific version name that would work too. Something like bass24.dll etc, etc. Then we could place it in the same folder as the screensaver. (windows)


MGE(Posted 2009) [#3]
hmm.. doing some looking at the source. Perhaps I need to edit the .lib file? I see alot of references to bass.dll there. Could we rename the dll to bass24.dll and then edit the .lib file? If so...what editor can I use to edit the .lib file? It comes up fairly garbled in notepad.


Brucey(Posted 2009) [#4]
You might be able to create a .def from the lib using reimp.exe (it's a mingw util)
reimp -d bass.lib

With the .def you can create a .a file using the following command :
dlltool -k -d bass.def -l libbass.a

At the top of the .def is the name of the .dll. Perhaps changing the name before generating the .a will make the linker expect a differently named .dll.


MGE(Posted 2009) [#5]
Thanks for the reply. But it's a little bit over my head on exactly what to do. Sorry. :(

Tell you what though....if you can research this a bit, find a solution and give me exact detailed instructions what to do in order to make this work so I can use another name of the .dll, (bass24.dll, bass26.dll, etc, etc) I'll send you $50.00 via PayPal for your time. ;) Thanks for considering it. :)


Brucey(Posted 2009) [#6]
Step by Step ;-)

Create a file called bass.def in lib/win32, and fill it with this :

Note the first line. That is the name of the dll you want to link to. (I got the function list from Dependency Walker)

Run this on that .def file :
dlltool -k -d bass.def -l libbass.a

It creates an archive file. If you search the file, you will see references to the dll you named in the .def. This file should be in lib/win32.

Now, since we have changed the way we intend to link to Bass, we need to change the module in a few places :

In common.bmx, you will see
?win32
Import "lib/win32/bass.lib"

You need to change it to
?win32
Import "-lbass"

Next, on line 131 or so, you will see
?win32
Extern "win32"

You need to remove "win32" (including the quotes), so that it becomes
?win32
Extern


And finally, in include/bass.h, you will see
#ifndef BASSDEF
#define BASSDEF(f) WINAPI f
#endif

You should change it to
#ifndef BASSDEF
#define BASSDEF(f) f
#endif


These last two changes are required because moving from .lib to .a the imported functions use a different naming convention.

Rebuild the module, build one of the examples (you will need a full build rather than quick), and it should now complain that it can't find your named .dll.

:-)


MGE(Posted 2009) [#7]
wow! Looking at this right now... will reply after I give it a try! :)


MGE(Posted 2009) [#8]
I was able to build the module no problem, but now I'm getting errors during the linking of my program(s). All of the errors seem related to the glue.cpp file?

C:/Program Files/BlitzMax/mod/bah.mod/bass.mod/bass.release.win32.x86.a(glue.cpp.release.win32.x86.o):glue.cpp:(.text+0xba): undefined reference to `BASS_ChannelGetLength@8'
C:/Program Files/BlitzMax/mod/bah.mod/bass.mod/bass.release.win32.x86.a(glue.cpp.release.win32.x86.o):glue.cpp:(.text+0xf2): undefined reference to `BASS_ChannelGetPosition@8'
C:/Program Files/BlitzMax/mod/bah.mod/bass.mod/bass.release.win32.x86.a(glue.cpp.release.win32.x86.o):glue.cpp:(.text+0x10e): undefined reference to `BASS_ChannelGetPosition@8'
C:/Program Files/BlitzMax/mod/bah.mod/bass.mod/bass.release.win32.x86.a(glue.cpp.release.win32.x86.o):glue.cpp:(.text+0x13b): undefined reference to `BASS_ChannelSeconds2Bytes@12'
C:/Program Files/BlitzMax/mod/bah.mod/bass.mod/bass.release.win32.x86.a(glue.cpp.release.win32.x86.o):glue.cpp:(.text+0x15a): undefined reference to `BASS_ChannelGetTags@8'
C:/Program Files/BlitzMax/mod/bah.mod/bass.mod/bass.release.win32.x86.a(glue.cpp.release.win32.x86.o):glue.cpp:(.text+0x20a): undefined reference to `BASS_StreamGetFilePosition@8'
C:/Program Files/BlitzMax/mod/bah.mod/bass.mod/bass.release.win32.x86.a(glue.cpp.release.win32.x86.o):glue.cpp:(.text+0x2a0): undefined reference to `BASS_StreamCreateFileUser@16'
C:/Program Files/BlitzMax/mod/bah.mod/bass.mod/bass.release.win32.x86.a(glue.cpp.release.win32.x86.o):glue.cpp:(.text+0x2b8): undefined reference to `BASS_SampleGetInfo@8'
C:/Program Files/BlitzMax/mod/bah.mod/bass.mod/bass.release.win32.x86.a(glue.cpp.release.win32.x86.o):glue.cpp:(.text+0x3e4): undefined reference to `BASS_GetDeviceInfo@8'
C:/Program Files/BlitzMax/mod/bah.mod/bass.mod/bass.release.win32.x86.a(glue.cpp.release.win32.x86.o):glue.cpp:(.text+0x411): undefined reference to `BASS_RecordGetInfo@4'
C:/Program Files/BlitzMax/mod/bah.mod/bass.mod/bass.release.win32.x86.a(glue.cpp.release.win32.x86.o):glue.cpp:(.text+0x4a4): undefined reference to `BASS_ChannelGetInfo@8'



Brucey(Posted 2009) [#9]
You didn't modify bass.h ?
You also then need to ensure the glue is recompiled.

... "And finally, in include/bass.h, you will see" ...


MGE(Posted 2009) [#10]
Yes, I did all as requested. hmm... when I re-built the module, I assumed it recomiled the glue as well? If not...how do I re-compile the glue? Thanks.


Brucey(Posted 2009) [#11]
just edit the file - you can add then remove a character - just to get the filestamp updated.

The error is due to the "WINAPI" definition in the functions that the C++ glue is calling. With the new .a file, they should not include WINAPI. - hence the change to the header (bass.h)


If you have changed all of this, and it still doesn't work, perhaps it is picking up a header from elsewhere? (but I doubt it would do that on Windows).


Brucey(Posted 2009) [#12]
BlitzMax will only recompile files it thinks need compiling. If you have a cpp file like we have here, modifying a .bmx in the same module will not cause the cpp to be re-compiled.
You can of course Build on the command-line using the -a option, which will force a (Re)build of the module - compiling everything, regardless.

I guess I should have made "Rebuild the module" in bold, in the post :-)


MGE(Posted 2009) [#13]
Ok..first off, thanks for helping. I think we're close. :) I was able to rebuild the mod, I get no errors during compiling an app now. But now when the app runs, I'm getting various "unhandled memory exception errors".

"example01.bmx" errors on:
"Local length:Long = channel.GetLength(BASS_POS_BYTE)"

"example02.bmx" works ok.

"example03.bmx" errors on "info = TBass.GetDeviceInfo(i)"

"example04.bmx" errors on "Local stream:TBassChannel = New TBassStream.CreateMem(IncbinPtr("resources/bass_track_baby.mp3"), IncbinLen("resources/bass_track_baby.mp3""

"example05.bmx" works ok.

Do these examples work on your end when changing the name of the dll using your step examples?

Thanks again.


MGE(Posted 2009) [#14]
Went ahead and did everthing from scratch, downloaded the latest via SVN, followed the instructions, etc. Still same problems.

For the heck of it, did you (Brucey) get a chance to rename the dll and run your examples? Thanks for your continued help.


Brucey(Posted 2009) [#15]
Okay.... version 2 ;-)

I've started again, and think I've found a better implementation - at last!
The .def file is different this time, with those win32 bits on the end of each function.

Create a file called bass.def in lib/win32, and fill it with this :

Note the first line. That is the name of the dll you want to link to. (I got the function list from Dependency Walker)

Run this on that .def file :
dlltool -k -d bass.def -l libbass.a

It creates an archive file. If you search the file, you will see references to the dll you named in the .def. This file should be in lib/win32.

Now, since we have changed the way we intend to link to Bass, we need to change the module in a few places :

In common.bmx, you will see
?win32
Import "lib/win32/bass.lib"

You need to change it to
?win32
Import "-lbass"



Different to last time, you can keep the "win32" reference in common.bmx, and you don't need to change bass.h (hence, you also keep the WINAPI bit in there).

See how you get on with that.


MGE(Posted 2009) [#16]
Doing some testing. So far the results are very promising. ;) Will reply later after several Vista machines tested.


MGE(Posted 2009) [#17]
Everthing "seems" to be working well. No problems found. However, several techies have told me not to rename the dll, to keep it "bass.dll" and at program startup, just point to the folder where the .dll is located at.

So, is there a way to reference the .dll from another location other than the root of the app? Going back to what the topic was mainly about. :) Thanks.


Brucey(Posted 2009) [#18]
They did, hey?

Well, the "other" way to do it is to use LoadLibrary, and reference all the functions as global function pointers - like how the openal module works.


MGE(Posted 2009) [#19]
hmmm... I prefer to stick with how it's working now with the renamed procedure. ;) I'm doing more tests today. Turns out the 2 Vista machines I have been testing on didn't have UAC turned on.


MGE(Posted 2009) [#20]
Hi Brucey, everything is working well on Vista. I have donated $50.00 as promised for your time. I'm sure we'll do business again. :) :) :)


Brucey(Posted 2009) [#21]
Thanks very much :-)

Glad you got it all sorted out in the end!!