API declaring and Extern statement questions

BlitzMax Forums/BlitzMax Beginners Area/API declaring and Extern statement questions

semar(Posted 2005) [#1]
All, I have some question that puzzles me quite a lot.

1)
What does Extern clause means ? What do I include with this sentence:
Extern "Win32"
.
End Extern
Do I refer to the Win32.DLL API here ? Or what else ?


---------------------------------------
2) Why this code:
Extern "Win32"

	Function WinExec (lpCmdLine:Byte Ptr,nCmdShow=10)

End Extern

WinExec ("calc.exe")
works, even if WinExec is not contained in Win32.DLL, rather in the Kernel32.DLL ? WinExec is also not declared in Kernel.bmx .


---------------------------------------
3) In the Win32.bmx the SendMessage function is declared, but if I call it from within a bmx program, it does not work. If I declare, instead, a SendMessageA function, and call it, then works. So why SendMessage has been declared, and not SendMessageA instead ?

So, how should I declare an API function to be used in my .bmx sources ? I'm quite confused here, any help would be appreciated.

Sergio.


Chris C(Posted 2005) [#2]
as I understand it the "Win32" bit is the calling convention
you should use extern "C" for code included from your C routines, could be wrong, its not documented (at all) like other advanced topics - still I suppose that will come with time


Sarge(Posted 2005) [#3]
Well there are two ways of doing this,

First: you can add the right winapi commands in the win32.mod folder and compile then have fun.

Second: this one is much better,

Extern "Win32" is good for releasing a open-source or other program so that people can just use it straight away and is faster for the developer to work with rather than having to put all the api commands in win32.mod folder and compiling each time.

Extern "Win32" ' which calls the right win32 lib file which can be located in "BlitzMax\Lib" not "win32.dll", if you have trouble with the win32 lib file being called then you can do,
Import "-ladvapi32" ' this will call advapi32.a from the lib folder then you can do

Extern "Win32"
      Function RegCloseKey( hKey:Int ) = "RegCloseKey@4"
End Extern

Local key:int

RegCloseKey( key )

If you have SendMessage in user32.mod you can also use SendMessageA which is the same thing as SendMessage, most win32 commands need
ex: Function SendMessage( hWnd,MSG,wParam,lParam ) = "SendMessage@4"

that is not a working example but you will get the idea, the debugger will tell you the correct "SendMessage@".

well i hope that cleared it all up for you.


semar(Posted 2005) [#4]
That cleared a bit, thank you, but I must admit, I'm still confused..

If I have, for example, a function inside MyDll.DLL, how can I access to it ?

I would then write:
Extern "MyDll.DLL"
function myfunction(etc. etc.)
End Extern

I guess this is not the way.. but if so, where is the WinExec declared, for example ? It's not in the Win32.BMX file, and neither in the included files..

??

Sergio.


Chris C(Posted 2005) [#5]
abstract from mikmod player for bmax

Global mikmod=LoadLibraryA( "mikmak" )
Global MikMod_RegisterAllDrivers()"win32"=getprocaddress(mikmod,"MikMod_RegisterAllDrivers")
Global Voice_RealVolume:Short(voice:Byte)=getprocaddress(mikmod,"Voice_RealVolume")

you'll need the pub.win32 module for getprocaddress and loadlibraryA

the dll being used here is mikmak.dll


Sarge(Posted 2005) [#6]
I guess this is not the way.. but if so, where is the WinExec declared, for example ? It's not in the Win32.BMX file, and neither in the included files..

Well the win32.mod is not completed yet, it is missing alot of functions. I guess they will finish it when the gui mod is released.

So for now all we can do is Extern the missing commands until its finished.


Dreamora(Posted 2005) [#7]
check out the samples, birdie, mods, twin32


Sarge(Posted 2005) [#8]
Yup i know but half dont even work, i had to put most the refrences ect.