Page 2 of 2

Re: call to POWERBASIC dll

Posted: Fri Jun 16, 2017 9:29 am
by Mijikai
Coded an example:

Code: Select all

;By Mijikai
Procedure.s CallScramble(Input.s,Seed.i)
  Protected BufferSize.i
  Protected Buffer.i
  Protected Offset.i
  Protected *GetByte.Byte
  Protected *SetByte.Byte
  Protected *SetSize.Long
  Static Lib.i
  If Not Lib
    Lib = OpenLibrary(#PB_Any,"scrambler.dll")
  EndIf
  If Lib
    BufferSize.i = Len(Input)
    Buffer.i = AllocateMemory(BufferSize + 9)
    If Buffer
      *SetSize = Buffer
      *SetSize\l = Buffer + 8
      *SetSize = Buffer + 4
      *SetSize\l = BufferSize
      For Offset = 0 To BufferSize
        *GetByte = @Input + Offset * 2
        *SetByte = Buffer + Offset + 8
        *SetByte\b = *GetByte\b
      Next
      Offset = CallFunction(Lib,"SCRAMBLE",Buffer,@Seed)
      FreeMemory(Buffer)
      If Offset
        ProcedureReturn PeekS(Offset,-1,#PB_Ascii)
      EndIf
    EndIf
  EndIf 
EndProcedure

Debug CallScramble("abcdefghijklmnopqrstuvwxyzABCEDEGHIJKLMNOPQRSTUVWXYZ",93235)
;PB v. 5.60 x86

Re: call to POWERBASIC dll

Posted: Sat Jun 24, 2017 5:52 pm
by williamvanhoecke
Hi Mijikai, thanks
Not sure how you figered it out though and yes...however weared it is to call this simple dll, this seems to work !!!

You are doing things here that are not documented
... what does the ! in front of dd mean ??
... data should be called with read command ??
... does a pointer (?T) to the 2 data.l lines pas the data to the callScramble routine

As I said, I am new to purebasic, and I do not understand to much of the the 'Datasection' you are using here
ccould it be done with a 'Structure...End Struccture'

Re: call to POWERBASIC dll

Posted: Sat Jun 24, 2017 6:17 pm
by Mijikai
A pb structure should also work i just did it manually for testing purposes :)

!: indicates that inline assembly is used (its in the helpfile)
dd: in asm 'dd' stands for double-word (the data stored after 'dd' is 4 Bytes)
?T: yes the pointer to that structure is passed

Also be aware that the function expects an Ascii string!

Re: call to POWERBASIC dll

Posted: Sat Jun 24, 2017 7:14 pm
by Mijikai
Coded an example with structures:

Code: Select all

;by Mijikai

Procedure.s CallScrambler(Input.s,Seed.i,UnScramble.i)
  Structure POWERBASIC_STR
    Ptr.l
    Size.l
  EndStructure
  Protected *String.POWERBASIC_STR
  Protected Result.i
  Static Lib.i
  If Not Lib
    Lib = OpenLibrary(#PB_Any,"scrambler.dll")
  EndIf
  If Lib And Input
    Input = "00000000" + Input;expand string by 8 chars to trick the ascii function!
    *String = Ascii(Input);allocate memory -> structure + string
    If *String
      *String\Ptr = *String + 8
      *String\Size = Len(Input) - 8
      If UnScramble
        Result = CallFunction(Lib,"UNSCRAMBLE",*String,@Seed)
      Else
        Result = CallFunction(Lib,"SCRAMBLE",*String,@Seed)
      Endif
      FreeMemory(*String)
      If Result
        ProcedureReturn PeekS(Result,-1,#PB_Ascii)
      EndIf
    EndIf
  EndIf
EndProcedure


Debug  CallScrambler("abcdefghijklmnopqrstuvwxyzABCEDEGHIJKLMNOPQRSTUVWXYZ",93235,#False)
;PB v. 5.60 x86

Re: call to POWERBASIC dll

Posted: Mon Jun 26, 2017 11:39 pm
by williamvanhoecke
Hi Mijikai
Thank you so much.
Your code works fine.
there's a lot I have to learn. :?