wrapper - dll translation

Just starting out? Need help? Post your questions and find answers here.
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

wrapper - dll translation

Post 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.

User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: wrapper - dll translation

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post 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

User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: wrapper - dll translation

Post 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
Last edited by ts-soft on Thu Mar 14, 2013 5:58 pm, edited 1 time in total.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post 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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: wrapper - dll translation

Post 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!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post 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
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: wrapper - dll translation

Post 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.
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post 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
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: wrapper - dll translation

Post 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 = "")
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post 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
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: wrapper - dll translation

Post 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
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post 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
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: wrapper - dll translation

Post by Danilo »

See again my last posting (include + code).
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post by t57042 »

This runs, but no rows are returned - so nothing is displayed.
Richard
Post Reply