Page 1 of 4

wrapper - dll translation

Posted: Thu Mar 14, 2013 11:47 am
by t57042
Hello,

Following code is part of a "universal wrapper" to use sqlitening with other languages then Powerbasic.
Just enough to start testing.

Can anyone translate this in purebasix syntax?
Thanks
Richard

Code: Select all

;  ====================================================================
;  |                                                                  |
;  | SQLitening Universal Include                                     |


;=============================<[ Close ]>==============================
Declare Sub      sluClose lib "SQLitening.Dll" alias "slClose"
;   Calls SQLitening.Dll directly.

;========================<[ Get Column Count ]>========================
Declare Function sluGetColumnCount lib "SQLitening.Dll" alias "slGetColumnCount" ( _
                                 byval SetNumber As Long) As Long
;   Calls SQLitening.Dll directly.


;==============================<[ Open ]>==============================
Declare Function sluOpen lib "SQLiteningU.Dll" alias "sluOpen" ( _
                                 byval FileName As Long, _
                                 byval ModChars As Long) As Long
;   FileName is a pointer to a null-terminated string. If not needed you
;            may pass a zero.
;   ModChars is a pointer to a null-terminated string. If not needed you
;            may pass a zero.

;;;==============================<[ Sel ]>===============================
Declare Function sluSel lib "SQLiteningU.Dll" alias "sluSel" ( _
                                 byval Statement As Long, _
                                 byval SetNumber As Long, _
                                 byval ModChars As Long) As Long
;   Statement is a pointer to a null-terminated string.
;   ModChars is a pointer to a null-terminated string. If not needed you
;            may pass a zero.
;
;===========================<[ Field Get ]>============================
Declare Sub      sluF lib "SQLiteningU.Dll" alias "sluF" ( _
                                 byval ColumnNumber As Long, _
                                 byval FieldValue As Long, _
                                 byref SizeOfFieldValue As Long, _
                                 byval SetNumber As Long)

;   FieldValue is a pointer to the memory which will receive the field value.
;              A Null (hex ;00') will be added to end.
;   SizeOfFieldValue is both passed and returned. Pass the size of FieldValue.
;                    It must be at least the size of the returning field value + 1.
;                    The actual length of the returing field value is returned.
;                    If the passed size is too small then error -13 will be raised
;                    and the returning length will be set to -1.

;============================<[ Get Row ]>=============================
Declare Function sluGetRow lib "SQLiteningU.Dll" alias "sluGetRow" ( _
                                 byval SetNumber As Long, _
                                 byval ModChars As Long) As Long
;   ModChars is a pointer to a null-terminated string. If not needed you
;            may pass a zero.


Re: wrapper - dll translation

Posted: Thu Mar 14, 2013 12:10 pm
by ts-soft

Code: Select all

;==========================================================================
; Generated with PureDLLHelper, Copyright ©2012 by Thomas <ts-soft> Schulz
;==========================================================================

Prototype   slClose()
Prototype   slF(*FieldValue, *SizeOfFieldValue.long)
Prototype.l slGetColumnCount(SetNumer.l)
Prototype.l slGetRow(SetNumber.l, ModChars.s = "")
Prototype.l slOpen(FileName.s = "", ModChars.s = "")
Prototype.l slSel(Statement.l, SetNumber.l, ModChars.s = "")

Global slClose.slClose
Global slF.slF
Global slGetColumnCount.slGetColumnCount
Global slGetRow.slGetRow
Global slOpen.slOpen
Global slSel.slSel

Procedure.i SQLitening_LoadDLL()
  Protected hDLL.i

  hDLL = OpenLibrary(#PB_Any, "SQLitening.dll")
  If hDLL <> 0
    slClose = GetFunction(hDLL, "slClose")
    slF = GetFunction(hDLL, "slF")
    slGetColumnCount = GetFunction(hDLL, "slGetColumnCount")
    slGetRow = GetFunction(hDLL, "slGetRow")
    slOpen = GetFunction(hDLL, "slOpen")
    slSel = GetFunction(hDLL, "slSel")

    ProcedureReturn hDLL
  EndIf

  ProcedureReturn #False
EndProcedure

Re: wrapper - dll translation

Posted: Thu Mar 14, 2013 1:07 pm
by t57042
I get an incorrect number of parameters trying to execute the slSel function.
You translated the functions using the Sqlitening.dll.
There are 3 DLL's ;depending on the programming language used.
Could you check the sqlitening docs?

This is the small test I use to try Sqlitening.

Thanks
Richard

Code: Select all

    XIncludeFile "SQLiteningU.inc"

   slOpen ("sample.db3")
  
   slSel ("Select * from Parts where rowid < 11") 
   While slGetRow()
     
           Rec$ = ""
           For i = 1 To  4 ;slGetColumnCount()                               
              Rec$ = Rec$ + sluF(i) + " - "
           Next
           Debug rec$
   Wend
   CloseLibrary(0)
   End


Re: wrapper - dll translation

Posted: Thu Mar 14, 2013 1:38 pm
by ts-soft
You can create your wrapper by simple using this: http://www.purebasic.fr/english/viewtop ... 56#p345256

Code: Select all

;==========================================================================
; Generated with PureDLLHelper, Copyright ©2012 by Thomas <ts-soft> Schulz
;==========================================================================

Prototype  sluF(ColumNumber.l, FieldValue.l, SizeOfField.l, SetNumber.l)
Prototype  sluGetRow(SetNumber.l, ModChars.s = "")
Prototype  sluOpen(FileName.s = "", ModChars.s = "")
Prototype  sluSel(Statement.s, SetNumber.l, ModChars.s = "")

Global sluF.sluF
Global sluGetRow.sluGetRow
Global sluOpen.sluOpen
Global sluSel.sluSel

Procedure.i SQLiteningU_LoadDLL()
  Protected hDLL.i

  hDLL = OpenLibrary(#PB_Any, "SQLiteningU.dll")
  If hDLL <> 0
    sluF = GetFunction(hDLL, "sluF")
    sluGetRow = GetFunction(hDLL, "sluGetRow")
    sluOpen = GetFunction(hDLL, "sluOpen")
    sluSel = GetFunction(hDLL, "sluSel")

    ProcedureReturn hDLL
  EndIf

  ProcedureReturn #False
EndProcedure

Re: wrapper - dll translation

Posted: Thu Mar 14, 2013 5:42 pm
by t57042
Thanks,
I tried again with the SQlitenigU.dll angd get the same error for this line:

Code: Select all

sluSel ("Select * from Parts where rowid < 11")


incorrect number of parameters

Richard

Re: wrapper - dll translation

Posted: Thu Mar 14, 2013 6:00 pm
by ts-soft
I have changed the first parameter to string:

Code: Select all

sluSel(Statement.s, SetNumber.l, ModChars.s = "")
The declaration says, the minimum of parameters a two parameter!

Re: wrapper - dll translation

Posted: Thu Mar 14, 2013 7:38 pm
by t57042
Still get the same error.
This is the calling program derived from exampleA in SQlitening download.

Code: Select all

XIncludeFile "SQLiteningU.inc"

   sluOpen ("sample.db3")
  
   sluSel ("Select * from Parts where rowid < 11") 
   While sluGetRow()
     
           Rec$ = ""
           For i = 1 To  4                           
              Rec$ = Rec$ + sluF(i) + " - "
           Next
           Debug rec$
   Wend
   CloseLibrary(0)
   End

This is the wrapper (first commented part is coming form 'universal wrapper')

Code: Select all

;sqliteningU.inc
;  |                                                                  |
;  | SQLitening Universal Include                                     |



;==============================<[ Open ]>==============================
;Declare Function sluOpen lib "SQLiteningU.Dll" alias "sluOpen" ( _
                                ; byval FileName As Long, _
                                ; byval ModChars As Long) As Long
;   FileName is a pointer to a null-terminated string. If not needed you
;            may pass a zero.
;   ModChars is a pointer to a null-terminated string. If not needed you
;            may pass a zero.

;;;==============================<[ Sel ]>===============================
;Declare Function sluSel lib "SQLiteningU.Dll" alias "sluSel" ( _
                                ; byval Statement As Long, _
                                ; byval SetNumber As Long, _
                                ; byval ModChars As Long) As Long
;   Statement is a pointer to a null-terminated string.
;   ModChars is a pointer to a null-terminated string. If not needed you
;            may pass a zero.
;
;===========================<[ Field Get ]>============================
;Declare Sub      sluF lib "SQLiteningU.Dll" alias "sluF" ( _
                                ; byval ColumnNumber As Long, _
                                ; byval FieldValue As Long, _
                                ; byref SizeOfFieldValue As Long, _
                                ; byval SetNumber As Long)

;   FieldValue is a pointer to the memory which will receive the field value.
;              A Null (hex ;00') will be added to end.
;   SizeOfFieldValue is both passed and returned. Pass the size of FieldValue.
;                    It must be at least the size of the returning field value + 1.
;                    The actual length of the returing field value is returned.
;                    If the passed size is too small then error -13 will be raised
;                    and the returning length will be set to -1.

;============================<[ Get Row ]>=============================
;Declare Function sluGetRow lib "SQLiteningU.Dll" alias "sluGetRow" ( _
                                 ;byval SetNumber As Long, _
                                ; byval ModChars As Long) As Long
;   ModChars is a pointer to a null-terminated string. If not needed you
;            may pass a zero.

       ;==========================================================================
    ; Generated with PureDLLHelper, Copyright ©2012 by Thomas <ts-soft> Schulz
    ;==========================================================================

       ;==========================================================================
    ; Generated with PureDLLHelper, Copyright ©2012 by Thomas <ts-soft> Schulz
    ;==========================================================================

    Prototype  sluF(ColumNumber.l, FieldValue.l, SizeOfField.l, SetNumber.l)
    Prototype  sluGetRow(SetNumber.l, ModChars.s = "")
    Prototype  sluOpen(FileName.s = "", ModChars.s = "")
    Prototype  sluSel(Statement.s, SetNumber.l, ModChars.s = "")
   

    Global sluF.sluF
    Global sluGetRow.sluGetRow
    Global sluOpen.sluOpen
    Global sluSel.sluSel

    Procedure.i SQLiteningU_LoadDLL()
      Protected hDLL.i

      hDLL = OpenLibrary(#PB_Any, "SQLiteningU.dll")
      If hDLL <> 0
        sluF = GetFunction(hDLL, "sluF")
        sluGetRow = GetFunction(hDLL, "sluGetRow")
        sluOpen = GetFunction(hDLL, "sluOpen")
        sluSel = GetFunction(hDLL, "sluSel")

        ProcedureReturn hDLL
      EndIf

      ProcedureReturn #False
    EndProcedure
I have very little (nearly none) experience with DLL's.
The SQlitening DLL can imho be a very good addition to use SQLite in Server/Client applications.
I want to test it out completely, but first it has to run under Purebasic.
Alternative could be to switch to Powerbasic :x


Many thanks
Richard

Re: wrapper - dll translation

Posted: Thu Mar 14, 2013 8:23 pm
by Danilo
t57042 wrote:Still get the same error.
This is the calling program derived from exampleA in SQlitening download.

Code: Select all

XIncludeFile "SQLiteningU.inc"

   sluOpen ("sample.db3")
  
   sluSel ("Select * from Parts where rowid < 11") 
   While sluGetRow()
     
           Rec$ = ""
           For i = 1 To  4                           
              Rec$ = Rec$ + sluF(i) + " - "
           Next
           Debug rec$
   Wend
   CloseLibrary(0)
   End

How many arguments did you give to the function sluSel() in your example above?

How many parameters do you see in the following declaration of sluSel()?

Code: Select all

;;;==============================<[ Sel ]>===============================
;Declare Function sluSel lib "SQLiteningU.Dll" alias "sluSel" ( _
;                                 byval Statement As Long, _
;                                 byval SetNumber As Long, _
;                                 byval ModChars As Long) As Long
;   Statement is a pointer to a null-terminated string.
;   ModChars is a pointer to a null-terminated string. If not needed you
;            may pass a zero.
;
[...]
    Prototype  sluSel(Statement.s, SetNumber.l, ModChars.s = "")
Hint:
t57042 wrote:I get an incorrect number of parameters trying to execute the slSel function.

Re: wrapper - dll translation

Posted: Thu Mar 14, 2013 9:31 pm
by t57042
Well I know the number of parameters is not correct, but I don't know what parameter I should give as the second (thirth) one.

Richard

Re: wrapper - dll translation

Posted: Fri Mar 15, 2013 9:15 am
by Danilo
t57042 wrote:Well I know the number of parameters is not correct, but I don't know what parameter I should give as the second (thirth) one.
According to the manual second parameter is the SetNumber:
SetNumber can be omitted or be any value from 0 to 32767. If omitted then will use zero.
So, 0 = default = omitted. Edit the prototype to:

Code: Select all

Prototype  sluSel(Statement.s, SetNumber.l = 0, ModChars.s = "")

Re: wrapper - dll translation

Posted: Fri Mar 15, 2013 10:39 am
by t57042
I edited the parameters of the prototypes, according to the docs (see beginning code)
Something is still wrong because they want:
pointers to a null-terminated string
How do you indicate that?
The sluOpen function gives me:
bad parameter number expected instead of string
Richard

Code: Select all

;sqliteningU.inc
                        |
;==============================<[ Open ]>==============================
;Declare Function sluOpen lib "SQLiteningU.Dll" alias "sluOpen" ( _
                                ; byval FileName As Long, _
                                ; byval ModChars As Long) As Long
;   FileName is a pointer to a null-terminated string. If not needed you
;            may pass a zero.
;   ModChars is a pointer to a null-terminated string. If not needed you
;            may pass a zero.

;;;==============================<[ Sel ]>===============================
;Declare Function sluSel lib "SQLiteningU.Dll" alias "sluSel" ( _
                                ; byval Statement As Long, _
                                ; byval SetNumber As Long, _
                                ; byval ModChars As Long) As Long
;   Statement is a pointer to a null-terminated string.
;   ModChars is a pointer to a null-terminated string. If not needed you
;            may pass a zero.
;
;===========================<[ Field Get ]>============================
;Declare Sub      sluF lib "SQLiteningU.Dll" alias "sluF" ( _
                                ; byval ColumnNumber As Long, _
                                ; byval FieldValue As Long, _
                                ; byref SizeOfFieldValue As Long, _
                                ; byval SetNumber As Long)

;   FieldValue is a pointer to the memory which will receive the field value.
;              A Null (hex ;00') will be added to end.
;   SizeOfFieldValue is both passed and returned. Pass the size of FieldValue.
;                    It must be at least the size of the returning field value + 1.
;                    The actual length of the returing field value is returned.
;                    If the passed size is too small then error -13 will be raised
;                    and the returning length will be set to -1.

;============================<[ Get Row ]>=============================
;Declare Function sluGetRow lib "SQLiteningU.Dll" alias "sluGetRow" ( _
                                 ;byval SetNumber As Long, _
                                ; byval ModChars As Long) As Long
;   ModChars is a pointer to a null-terminated string. If not needed you
;            may pass a zero.

       ;==========================================================================
    ; Generated with PureDLLHelper, Copyright ©2012 by Thomas <ts-soft> Schulz
    ;==========================================================================

       ;==========================================================================
    ; Generated with PureDLLHelper, Copyright ©2012 by Thomas <ts-soft> Schulz
    ;==========================================================================

    Prototype  sluF(ColumNumber.l, FieldValue.l, SizeOfField.l, SetNumber.l)
    Prototype  sluGetRow(SetNumber.l, ModChars.l =0)
    Prototype  sluOpen(FileName.l =0, ModChars.l= 0)
    Prototype  sluSel(Statement.l, SetNumber.l = 0, ModChars.l =0)
   

    Global sluF.sluF
    Global sluGetRow.sluGetRow
    Global sluOpen.sluOpen
    Global sluSel.sluSel

    Procedure.i SQLiteningU_LoadDLL()
      Protected hDLL.i

      hDLL = OpenLibrary(#PB_Any, "SQLiteningU.dll")
      If hDLL <> 0
        sluF = GetFunction(hDLL, "sluF")
        sluGetRow = GetFunction(hDLL, "sluGetRow")
        sluOpen = GetFunction(hDLL, "sluOpen")
        sluSel = GetFunction(hDLL, "sluSel")

        ProcedureReturn hDLL
      EndIf

      ProcedureReturn #False
    EndProcedure

Code: Select all

XIncludeFile "SQLiteningU.inc"

   sluOpen ("sample.db3")
  
   sluSel ("Select * from Parts where rowid < 11") 
   While sluGetRow()
     
           Rec$ = ""
           For i = 1 To  4                           
              Rec$ = Rec$ + sluF(i) + " - "
           Next
           Debug rec$
   Wend
   CloseLibrary(0)
   End

Re: wrapper - dll translation

Posted: Fri Mar 15, 2013 10:54 am
by Danilo
t57042 wrote:I edited the parameters of the prototypes, according to the docs (see beginning code)
Something is still wrong because they want:
pointers to a null-terminated string
How do you indicate that?
The sluOpen function gives me:
bad parameter number expected instead of string
Richard
You defined the strings as type .l, so you have to use an '@' character in front of all strings now (@"abc" gives the address of that string).

(side note: for pointers use type .i or *pointers generally. Use of .l is OK here because it is a 32bit only DLL, but better use .i anyway for pointer-size-types)

You could declare the string types with .s = "" (FileName and ModChars)
But then it would give ASCII strings if compiled with ASCII, and UNICODE strings when compiled in UNICODE mode.
That does not look right, as you call the same functions in both modes.

If you know what string encoding the DLL uses, you could use types .p-ascii = 0 or .p-utf8 = 0 or .p-unicode = 0
If the DLL uses ASCII only (please check it to make sure), try this for the include:

Code: Select all

    Prototype  sluF(ColumNumber.l, *FieldValue, *SizeOfField, SetNumber.l = 0)
    Prototype  sluGetRow(SetNumber.l = 0, ModChars.p-ascii = 0)
    Prototype  sluOpen(FileName.p-ascii = 0, ModChars.p-ascii = 0)
    Prototype  sluSel(Statement.p-ascii, SetNumber.l = 0, ModChars.p-ascii = 0)
   

    Global sluF.sluF
    Global sluGetRow.sluGetRow
    Global sluOpen.sluOpen
    Global sluSel.sluSel

    Procedure.i SQLiteningU_LoadDLL()
      Protected hDLL.i

      hDLL = OpenLibrary(#PB_Any, "SQLiteningU.dll")
      If hDLL <> 0
        sluF = GetFunction(hDLL, "sluF")
        sluGetRow = GetFunction(hDLL, "sluGetRow")
        sluOpen = GetFunction(hDLL, "sluOpen")
        sluSel = GetFunction(hDLL, "sluSel")

        ProcedureReturn hDLL
      EndIf

      ProcedureReturn #False
    EndProcedure
EDIT: changed it little bit, please try again. ;)

And for the code:

Code: Select all

XIncludeFile "SQLiteningU.inc"

dll = SQLiteningU_LoadDLL()
if dll
   if sluOpen ("sample.db3")
  
       sluSel ("Select * from Parts where rowid < 11") 
       
       
       While sluGetRow()

       
               Rec$ = ""
               For i = 1 To  4
                  buffer$ = Space(100)
                  len = len(buffer$)
                  sluF(i, @buffer$, @len)
                  Rec$ + PeekS(@buffer$,-1,#PB_ASCII) + " - "
               Next
               Debug rec$
       Wend
   endif
   CloseLibrary(dll)
   End
endif

Re: wrapper - dll translation

Posted: Fri Mar 15, 2013 11:38 am
by t57042
Thanks, part is working. This is the calling part:

Code: Select all

; 
XIncludeFile "SQLiteningU.inc"
SQLiteningU_LoadDLL()
sluOpen ("sample.db3")
  
   sluSel ("Select * from Parts where rowid < 11") 
   While sluGetRow()
     
           Rec$ = ""
           For i = 1 To  4                           
              Rec$ = Rec$ + sluF(i) + " - "
           Next
           Debug rec$
   Wend
   CloseLibrary(0)
   End
Runs exept the sluF() function
the sluF() function says: incorrect number of parameters.
This is what is expected.But How?
===========================<[ Field Get ]>============================
;Declare Sub sluF lib "SQLiteningU.Dll" alias "sluF" ( _
; byval ColumnNumber As Long, _
; byval FieldValue As Long, _
; byref SizeOfFieldValue As Long, _
; byval SetNumber As Long)

; FieldValue is a pointer to the memory which will receive the field value.
; A Null (hex ;00') will be added to end.
; SizeOfFieldValue is both passed and returned. Pass the size of FieldValue.
; It must be at least the size of the returning field value + 1.
; The actual length of the returing field value is returned.
; If the passed size is too small then error -13 will be raised
; and the returning length will be set to -1.
This is the slightly adapted include:

Code: Select all

 Prototype  sluF(ColumNumber.l, FieldValue.l, SizeOfField.l, SetNumber.l)
    Prototype  sluGetRow(SetNumber.l=0, ModChars.p-ascii = 0)
    Prototype  sluOpen(FileName.p-ascii = 0, ModChars.p-ascii = 0)
    Prototype  sluSel(Statement.p-ascii, SetNumber.l = 0, ModChars.p-ascii = 0)
   

    Global sluF.sluF
    Global sluGetRow.sluGetRow
    Global sluOpen.sluOpen
    Global sluSel.sluSel

    Procedure.i SQLiteningU_LoadDLL()
      Protected hDLL.i

      hDLL = OpenLibrary(#PB_Any, "SQLiteningU.dll")
      If hDLL <> 0
        sluF = GetFunction(hDLL, "sluF")
        sluGetRow = GetFunction(hDLL, "sluGetRow")
        sluOpen = GetFunction(hDLL, "sluOpen")
        sluSel = GetFunction(hDLL, "sluSel")

        ProcedureReturn hDLL
      EndIf

      ProcedureReturn #False
    EndProcedure
Tks - Richard

Re: wrapper - dll translation

Posted: Fri Mar 15, 2013 11:54 am
by Danilo
See again my last posting (include + code).

Re: wrapper - dll translation

Posted: Fri Mar 15, 2013 12:06 pm
by t57042
This runs, but no rows are returned - so nothing is displayed.
Richard