Restored from previous forum. Originally posted by Danilo.
> However, it also looks like PB doesn't follow the standard name decoration
> convention for STDCALL - ie: prefixing a '_' and appending '@bytes' -
> eg: _WinMain@16.
>
> Is this correct?
Thats Microsoft specific: MS Visual C/C++.
All Windows DLLs i´ve seen use stdcall without "_" and "@bytes".
Look at GDI32.DLL or SHELL32.DLL (with QuickViewPlus for example)
and test some functions in this DLLs.
Look at WinIO, look at the 6DX 3D Engine...
all are "__stdcall" but dont use the underscore and the "AT".
> It would be nice for PB to do this,
IMO not a good idea, because the DLLs are
for everything - not only for use in Blitz.
> as it would allow Blitz to auto-detect the calling
> convention through repeated calls to 'FindProcAddress'.
You try "@4", "@8", "@12", "@16", ... ?? LOL
Sorry, Mark - thats not a good and not a fast way
of doing it.
Maybe you could implement a "Declare" statement in
Blitz/BBmax like
Code: Select all
Declare "my.DLL" "myfunction" as "cool" (String, Long)
Declare "my.DLL" "blahblah" as "megacool" ()
Declare "purebasic.dll" "_OpenWin" as "OpenWindow" (long, long, long, long, long, long, string)
And after this statement the user can use the commands
"cool(string, long)" and "megacool()" directly in the source.
Its very easy to implement this in a compiler.
You simply add
Code: Select all
_ModuleHandle_myDLL = LoadLibrary("my.dll")
_adr_myDLL_cool = GetProcAddress(_ModuleHandle_myDLL, "myfunction")
_adr_myDLL_megacool = GetProcAddress(_ModuleHandle_myDLL, "blahblah")
_ModuleHandle_purebasicDLL = LoadLibrary("purebasic.dll")
_adr_purebasicDLL_OpenWindow = GetProcAddress(_ModuleHandle_purebasicDLL, "_OpenWin")
at the _beginning_ of your generated output.
The actual CALL (using the new function) would generate this code:
Code: Select all
; cool("Hello World", 12) generates:
PUSH dword 12
PUSH dword address_of_string_HelloWorld
CALL [_adr_myDLL_cool]
; megacool() generates:
CALL [_adr_myDLL_megacool]
; OpenWindow(1,10,20,640,480,#WS_POPUP,"Test") generates:
PUSH dword address_of_string_Test
PUSH dword 80000000h ; value of constant #WS_POPUP in Hex
PUSH dword 480
PUSH dword 640
PUSH dword 20
PUSH dword 10
PUSH dword 1
CALL [_adr_purebasicDLL_OpenWindow]
You can add this complete system in a few hours
to your compiler and everybody can use it without
any problems anymore.
If there is really __cdecl allowed for public DLLs,
you could allow "Declare:cdecl "my.DLL" ..." to
support this too.
I have done it this way in my "PureBasic DLL Importer" tool,
but Frederic said there are no __cdecl DLLs.
I think its possible with C/C++, but i dont use this languages -
so i cant say for sure.
If its possible to use CDECL, you use the same way
but add a "ADD dword ESP, ArgumentCount * 4" after
the "CALL [adr_...]".
To your generated ending-code you have to add
Code: Select all
FreeLibrary(_ModuleHandle_myDLL)
FreeLibrary(_ModuleHandle_purebasicDLL)
Thats nearly all you have to do.
You should add 1 thing to the start-code:
Check the ReturnValue of LoadLibrary() and GetProcAddress()
for 0 (ZERO). When it returns 0, it cant find the DLL
or the Function and you give a MessageBox "ERROR: Cant find my.DLL"
or "ERROR: Cant find function blahblah in my.DLL" like
Visual C/C++ does it when something goes wrong.
After this MessageBox the program ends and the user
of the game/program can check where the missing DLL is.
(Calling a 0-pointer isnt a good idea )
Its not that much work and you have a working
DLL calling System with this.
I think it would make many users much happier...
> The other option is to add a 'calling convention' flag to Blitz's
> CallDLL command - not so pretty...
Thats only a workaround and annoying for the users.
Better implement a good and complete system for this -
few hours of work, but MUCH better.
Begin to implement it NOW and the users will get the
new update tomorrow.
> Either way, I think it woul dbe nice for Blitz/PB to be
> able to talk to each other!
Blitz2D/3D + purebasic.dll = BlitzMAX ??
cya,
...Danilo
(registered PureBasic user)
Edited by - Danilo on 06 July 2002 06:49:01