[Implemented] DLL creation is weird!

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] DLL creation is weird!

Post by BackupUser »

Restored from previous forum. Originally posted by Hi-Toro.

Fred,

Is it possible to output DLLs the same way exe's are output? Making it appear in the PB\Compilers\ directory with the name purebasic.dll (completely ignoring the name you *have* to give it in the 'Create Executable' requester) is just so confusing!

It's really cool though -- I got it working with Blitz last night :)

BTW Could you send me the Linux version please Fred, when you have the time? I've started playing with Mandrake, and I do like it a lot :)


--
See ya,
James L Boyd.
http://www.hi-toro.com/
--
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

>I got it working with Blitz last night :)

Can you post an example here please ??

There are some guys in the german forum
that want to write some DLLs for BB and
dont get it to work.
They said BB is using _cdecl, so it doesnt
work with plain PureBasic (but they cant
provide me enough info about BB DLLs).
I think it should be possible with some
ASM inside, so the stack isnt goin crazy...
...but maybe BB can use _stdcall too.

thanks,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

DLL are always stdcall...

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

Post by BackupUser »

Restored from previous forum. Originally posted by Hi-Toro.

OK, Danilo, read the stuff in this posting:

http://www.blitzbasic.com/cgi-bin/showp ... topic=9775

Then read this (part of an email I sent to Halo last night -- the attachments mentioned are at the bottom of this post)...

It's actually very easy, as I've just modified my test to work on some
passed data -- see the attached example, and see that forum post, which
explains the weird way PB creates the actual DLL.

Basically:

· Create a bank in Blitz;
· Call your DLL with the name of the DLL, the name of the function to call,
and the Blitz bank handle;
· In your PB code -- which must be made of *only* ProcedureDLL functions --
create a DLL procedure like this, with these parameters (note that you don't
actually specify these -- or any -- parameters when calling the DLL function
from Blitz. All data passing is done solely via the bank):

ProcedureDLL Whatever (*in, in_size, *out, out_size)
; Code here...
EndProcedure

'*in' is the address of your Blitz bank, and 'in_size' will be filled in by
Blitz with the size of the bank (ignore the 'out' stuff for now -- see
CallDLL docs). Once you know this, it's really easy!

--

Attachment #1 (Blitz):

Code: Select all

AppTitle "DLL Data Test: press a key after each step..."

Print
Print "Creating a bank of 4 bytes..."
Print: WaitKey

bank = CreateBank (4)

Print "Poking values 1-4 into each byte of bank..."
Print: WaitKey

For a = 0 To 3
	PokeByte bank, a, a + 1
Next

Print "Contents of bank before passing to DLL..."
Print: WaitKey

For a = 0 To 3
	Print PeekByte (bank, a)
Next

Print: WaitKey

Print "Calling DLL with bank..."
Print: WaitKey

result = CallDLL ("purebasic", "_HandleData", bank)

Print "Contents of bank after DLL has been called..."
Print: WaitKey

For a = 0 To 3
	Print PeekByte (bank, a)
Next
Attachment #2 (PB):

Code: Select all

ProcedureDLL HandleData (*in, in_size, *out, out_size)

  MessageRequester ("DLL Data Test", "DLL MESSAGE: Bank size passed to DLL: " + Str (in_size) + " bytes.", #MB_ICONINFORMATION)
  MessageRequester ("DLL Data Test", "DLL MESSAGE: Adding 4 to each value...", #MB_ICONINFORMATION)
  
  For a = 0 To 3
    PokeB (*in + a, (a + 1) + 4)
  Next
  
EndProcedure
So... just create the DLL (appears as 'purebasic.dll' in the PB\Compilers\ folder), then put it in the same folder as that Blitz code...



--
See ya,
James L Boyd.
http://www.hi-toro.com/
--
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

@Fred:
but with C/C++ you can make _cdecl DLLs , cant you ??
Shouldnt be a problem when you make the right header
files for it.

@Hi-Toro:
Thanks for the Infos. Its that BlitzBasic isnt good
enough with handling DLLs, i see the point.
"(*in, in_size, *out, out_size)" are hidden parameters,
BB:CallDLL() is very slow and it looks like it doesnt
clean up everything.
You cant call any DLL with variable argument size, only
special DLLs made for BB - right ??
Its using "Banks" for the Arguments... LOL - thats the
new standard for calling DLLs ?? Never heared of it...

BlitzBasic is the weird thing here, not PureBasic...

thanks,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Hi-Toro.

DLL support in Blitz is deliberately extremely basic!


--
See ya,
James L Boyd.
http://www.hi-toro.com/
--
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.
@Fred:
but with C/C++ you can make _cdecl DLLs , cant you ??
Shouldnt be a problem when you make the right header
files for it.
You can do anything, even use eax as first arg (I hope ). DLL format in Windows is always stdcall, else it's not a DLL but a program module.

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

Post by BackupUser »

Restored from previous forum. Originally posted by wickedRush.

Just try to call that PureBasic DLL twice in the same BB code... Usually gives an illegal function call and Blitz stops responding. I know this is not a fault of PureBasic. It never made sense to me why a BB DLL call would use _cdecl. Mark must have had a reason, just never told us why.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Hi-Toro.

Mark did say that it's to prevent 'name-mangling' -- now I just have to find out what that means :wink:

--
See ya,
James L Boyd.
http://www.hi-toro.com/
--


Edited by - Hi-Toro on 29 June 2002 17:03:40
Post Reply