PureBasic .dll's and Blitz.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Paul.
Halo, Take a look at this on your Blitz forum...
http://www.blitzbasic.co.nz/cgi-bin/sho ... topic=9892
Read the last couple of posts from BlitzSupport.
Halo, Take a look at this on your Blitz forum...
http://www.blitzbasic.co.nz/cgi-bin/sho ... topic=9892
Read the last couple of posts from BlitzSupport.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
I just read the thread and it sounds strange. Windows DLL are always STDCALL. I don't think than Mark used a CDECL declaration.
The difference between CDECL and STDCALL (I read something wron on the Blitz forums):
- STDCALL: all parameters are passed on the stack, first argument pushed last. It's the function which free up the stack (RET NbParameters*4 in asm).
- CDECL: all parameters are passed on the stack, first argument pushed last. It's the program which free up the stack after the function has returned (ADD ESP, NbParameters*4 in asm).
I hope it clears thing up. If Blitz use CDECL mode, then it can't use standard windows DLL properly. To test it:
For k=0 To 1000000
CALL(YourFavoriteFunction)
Next
If CDECL is used, then the stack will explode.
Fred - AlphaSND
I just read the thread and it sounds strange. Windows DLL are always STDCALL. I don't think than Mark used a CDECL declaration.
The difference between CDECL and STDCALL (I read something wron on the Blitz forums):
- STDCALL: all parameters are passed on the stack, first argument pushed last. It's the function which free up the stack (RET NbParameters*4 in asm).
- CDECL: all parameters are passed on the stack, first argument pushed last. It's the program which free up the stack after the function has returned (ADD ESP, NbParameters*4 in asm).
I hope it clears thing up. If Blitz use CDECL mode, then it can't use standard windows DLL properly. To test it:
For k=0 To 1000000
CALL(YourFavoriteFunction)
Next
If CDECL is used, then the stack will explode.
Fred - AlphaSND
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by marksibly.
Hi,
Blitz uses CDECL to call DLLs, which means it wont currently work with PB DLLs as they use STDCALL.
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?
It would be nice for PB to do this, as it would allow Blitz to auto-detect the calling convention through repeated calls to 'FindProcAddress'.
The other option is to add a 'calling convention' flag to Blitz's CallDLL command - not so pretty...
Either way, I think it woul dbe nice for Blitz/PB to be able to talk to each other!
Bye,
Mark Sibly,
Author of Blitz
Hi,
Blitz uses CDECL to call DLLs, which means it wont currently work with PB DLLs as they use STDCALL.
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?
It would be nice for PB to do this, as it would allow Blitz to auto-detect the calling convention through repeated calls to 'FindProcAddress'.
The other option is to add a 'calling convention' flag to Blitz's CallDLL command - not so pretty...
Either way, I think it woul dbe nice for Blitz/PB to be able to talk to each other!
Bye,
Mark Sibly,
Author of Blitz
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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
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
at the _beginning_ of your generated output.
The actual CALL (using the new function) would generate this code:
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
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
> 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)"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")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]
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)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
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
Hello Mark and welcome on the PB forums.
Fred - AlphaSND
Hello Mark and welcome on the PB forums.
Are we talking the same thing ? This means you can't call correctly any of the standard Windows DLL like Kernel32.DLL, User32.DLL etc.. as there are all using STDCALL. It's logical as CDECL is slower/bigger than STDCALL.Blitz uses CDECL to call DLLs, which means it wont currently work with PB DLLs as they use STDCALL.
As Daniloa said, all stdcall function in standard windows lib doesn't use this convention. LccWin32 use it, that's true. I could add it automatically, but it would be very strange to the user when calling a function to add a @xx at the end. About the '_' I will remove it soon.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?
Could you indicate to me which DLL out of there are working in CDECL mode ? I just made some search and found nothing. Anyway, you should have a good reason to do that.It would be nice for PB to do this, as it would allow Blitz to auto-detect the calling convention through repeated calls to 'FindProcAddress'.
The other option is to add a 'calling convention' flag to Blitz's CallDLL command - not so pretty...
Yes, would be cool... Can Blitz create DLL to use in PB ? .Either way, I think it woul dbe nice for Blitz/PB to be able to talk to each other!
Fred - AlphaSND
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by MrVainSCL.
Hi @ all
Wow.. is that really "mark sibly" the coder behind blitzbasic who wrote some lines in this forum? Or is it just a fake? However... nice to see the coders behind two different coding languages to talk about some stuff any maybe to help each other in some parts
Keep on ya work guys!
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
Hi @ all
Wow.. is that really "mark sibly" the coder behind blitzbasic who wrote some lines in this forum? Or is it just a fake? However... nice to see the coders behind two different coding languages to talk about some stuff any maybe to help each other in some parts
Keep on ya work guys!
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Danilo.
Mark doesnt believe what we told him.
In his opinion he is correct and all others like
PureBasic, Delphi etc.. are wrong.
Delphi is wrong because it doesnt work with
BlitzBasic... think about it, guys.
Its a big professional compiler with tousands
of professional developers using it.
BlitzBasic is a closed and non-standard programming language.
Mark doesnt want to allow to call all the many million DLLs
out there.
He wants a closed system and you have to write special
CDECL (C-Declaration) DLLs with C/C++ for BlitzBasic.
Yes, you can only call this special DLLs.
You cant use any Windows-DLL.
Try MessageBox() and Beep() with his CallDLL() command.
You cant give arguments to standard DLL functions
because BB uses MemoryBanks for this. Oh well...
Its his own choice.
The problem is that the BlitzBasic-people that dont know
the LowLevel- and API-stuff believe him and say its PureBasic´s fault.
And Delphi is wrong too.
They dont know anything and believe everything that Mark says.
Mark is a God for this kidz... LOL
When this goes on like it is for now, BlitzBasic will die.
But thats not a big problem anyway...
Its a closed system with a few developers that cant talk
to million things outside.
Thats a very important thing today, so you can use few million
resources that are available for everybody who uses the STANDARD.
CDECL: C/C++, maybe VB is for use with this languages only.
FASTCALL: Delphi - not compatible with anything else
STDCALL: compatible with everything... C/C++, Delphi, VB, PureBasic, Pascal ...EVERYTHING
The whole Windows system is STDCALL.
And "_" + "@bytes" is a C-thingy too.
Looks like Mark is new to this stuff, but he can
still learn it - if he wants...
Open your mind.
cya,
...Danilo
(registered PureBasic user)
Mark doesnt believe what we told him.
In his opinion he is correct and all others like
PureBasic, Delphi etc.. are wrong.
Delphi is wrong because it doesnt work with
BlitzBasic... think about it, guys.
Its a big professional compiler with tousands
of professional developers using it.
BlitzBasic is a closed and non-standard programming language.
Mark doesnt want to allow to call all the many million DLLs
out there.
He wants a closed system and you have to write special
CDECL (C-Declaration) DLLs with C/C++ for BlitzBasic.
Yes, you can only call this special DLLs.
You cant use any Windows-DLL.
Try MessageBox() and Beep() with his CallDLL() command.
You cant give arguments to standard DLL functions
because BB uses MemoryBanks for this. Oh well...
Its his own choice.
The problem is that the BlitzBasic-people that dont know
the LowLevel- and API-stuff believe him and say its PureBasic´s fault.
And Delphi is wrong too.
They dont know anything and believe everything that Mark says.
Mark is a God for this kidz... LOL
When this goes on like it is for now, BlitzBasic will die.
But thats not a big problem anyway...
Its a closed system with a few developers that cant talk
to million things outside.
Thats a very important thing today, so you can use few million
resources that are available for everybody who uses the STANDARD.
CDECL: C/C++, maybe VB is for use with this languages only.
FASTCALL: Delphi - not compatible with anything else
STDCALL: compatible with everything... C/C++, Delphi, VB, PureBasic, Pascal ...EVERYTHING
The whole Windows system is STDCALL.
And "_" + "@bytes" is a C-thingy too.
Looks like Mark is new to this stuff, but he can
still learn it - if he wants...
Open your mind.
cya,
...Danilo
(registered PureBasic user)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Danilo.
Shaddup and look at the time when i posted this.
Oh well, the BB forum doesnt show the time... not my problem.
You are annoyed because you cant write the wrapper to
import all PB functions into BB... also not my problem.
If something doesnt work, the BB guys only say its PB´s fault -
but BB is the thing that isnt correct here.
Thats the real problem.
And now ignore me,
...Danilo
(registered PureBasic user)
Shaddup and look at the time when i posted this.
Oh well, the BB forum doesnt show the time... not my problem.
You are annoyed because you cant write the wrapper to
import all PB functions into BB... also not my problem.
If something doesnt work, the BB guys only say its PB´s fault -
but BB is the thing that isnt correct here.
Thats the real problem.
And now ignore me,
...Danilo
(registered PureBasic user)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by MrVainSCL.
Sure, you will know me, some time ago due fact of your 3d bb shooter game... and thats one reason more, why i write here some words too!!!
I think nobody and esp you too, dont must write here any stuff like "...maybe you should think before shooting your fool mouth off again...." to get fighted - i think we all are old enough and could comunicate on another friendly way to discuse about any stuff...!!
But i think you are a very egostic guy (sorry!) ... Just only see your first posting to the PB forum... So please dont get in fight here with any member... We respect all PB, Blitz and other coding comunitys too - but on a friendly way! Thats the only difference to you! Thats all!
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
hi halo:halo wrote:
Mark said he messed up, and is going to fix it. Maybe you should think before shooting your fool mouth off again.
Sure, you will know me, some time ago due fact of your 3d bb shooter game... and thats one reason more, why i write here some words too!!!
I think nobody and esp you too, dont must write here any stuff like "...maybe you should think before shooting your fool mouth off again...." to get fighted - i think we all are old enough and could comunicate on another friendly way to discuse about any stuff...!!
But i think you are a very egostic guy (sorry!) ... Just only see your first posting to the PB forum... So please dont get in fight here with any member... We respect all PB, Blitz and other coding comunitys too - but on a friendly way! Thats the only difference to you! Thats all!
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm