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/
--