external library @ symbol

BlitzMax Forums/BlitzMax Programming/external library @ symbol

Pantheon(Posted 2006) [#1]
Hi all,

Im trying to import functions from the BASSmod sound system using the static library, bassmod.lib. As just a test I have defined :-

<CODE>
Import "bassmod.lib"

Extern
Function BASSMOD_GetVersion:Short( ) = "BASSMOD_GetVersion@0"
End Extern

DebugLog BASSMOD_GetVersion( )
</CODE>

Now... This returns 2 and im quite content to belive that this is correct. So my question is what does the @ symbol is needed for? I had a look at the FMod topic and thats where I got it from.

Im sure that I could have found this out in the documents but I was also quite keen to make my first post here.

Also are there any guides on how to format posts in the forums? I dont have a clue how to get thoes code boxes.

Thanks


skidracer(Posted 2006) [#2]
For code boxed use the square brackets [ ] for your markup tags (checkout the FAQ located in the Home section of this site).

As for the name mangling, this is due to the library being compiled in C++ rather than plain C. I think it has something to do with that language supporting multiple functions that have the same name but different parameter lists.


Gabriel(Posted 2006) [#3]
Nm.. Skidracer already told you.


Pantheon(Posted 2006) [#4]
Rite ok,
So it stems from overidden functions. So for the most part I should just set it to @0 ?

I also have one more dilema, a function BASSMOD_SetVolume:bool( volume:short ) needs to be implemented, however bMax doest support a boolean. Can I just let it be cast safely into a byte or will the data overrun?

Cool, thanks.


DStastny(Posted 2006) [#5]
A bool is equvalent to an Int.

The @0 decoration is inication of amount of stack space required for paramaters and usually indication of a stdcall calling conventions when exported by DLL or LIB.

The "C" calling convention does not decorate.

So...
Extern
Function BASSMOD_GetVersion:Short( ) = "BASSMOD_GetVersion@0"
End Extern

Should probably be
Extern
Function BASSMOD_GetVersion:Short( ) "win32" = "BASSMOD_GetVersion@0"
End Extern


Doug Stastny


Pantheon(Posted 2006) [#6]
Thanks for the quick replies, its much appreciated.

@Budman:
So, if I use ( Extern "C" ) then I should not need to include the "win32"?

Im now getting the compilation error :-
undefined reference to `BASSMOD_Init@16'

with my extern code :-

Extern "C"
Function BASSMOD_Init:Byte( device:Int, freq:Short, flags:Short ) = "BASSMOD_Init@16"
End Extern

and runcode :-
DebugLog BASSMOD_Init( -1, 44100, 16 )

So, im sure that it cant locate that function within the library when it is called.

If anyone could advise farther that would be great.


Pantheon(Posted 2006) [#7]
Ok, its getting late and im writing buggy code. I just made 2 buggs in succession with strange consequences.

The problem is in (= "BASSMOD_Init@16"). The @16 seems like it should be 8 because int+2*short = 8 bytes. This infact doesnt compile, giving the same error as before.

In my error I wrote @12 and it magicaly compiled and ran successfully.

When they get pushed onto the stack are they padded to integer positions for that SIMM memory thing? Thats all I could think it could be.


skidracer(Posted 2006) [#8]
Have you seen the post by sucoX at the bottom of
this thread?

Also dword=32bitint, what shorts are you referring to?


DStastny(Posted 2006) [#9]
@Pantheon

You are confusing what Extern "C" vs Extern "Win32".

The "C" or "Win32" is the calling convention of the function. You cant mix them its one or other. Based upon your symbol problems its clear this is a Stdcall => "Win32" calling convention. Just wrap all your functions your are attempting to access in
Extern "Win32"
..
End Extern


Although you might just want to use what skid linked to.

Doug Stastny


Pantheon(Posted 2006) [#10]
Yes,
these two points raised (skidracer & Budman) were the problems I was encountering. When I got home, I realised both of them and changed to using "win32" thus correcting a problem with pointer handling. Also I stupidly got confused and let dword = short. When I changed this I solved my compilation errors.
The Bass port by sucoX looks realy well writen. I myself was just trying this to learn how to program with external C files in BMX. It now fully works, so thanks guys.