wrapper - dll translation

Just starting out? Need help? Post your questions and find answers here.
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: You can also link the DLLs directly to your executable instead loading DLLs dynamically.

Run this code to create the import libs:

Code: Select all

;
; [X] Create temporary executable in the source directory
;
dir$ = GetPathPart(ProgramFilename())
RunProgram(#PB_Compiler_Home+"Compilers\POLIB.exe","SQLitening.dll /MACHINE:x86 /OUT:SQLitening.lib",dir$)
RunProgram(#PB_Compiler_Home+"Compilers\POLIB.exe","SQLiteningS.dll /MACHINE:x86 /OUT:SQLiteningS.lib",dir$)
RunProgram(#PB_Compiler_Home+"Compilers\POLIB.exe","SQLiteningU.dll /MACHINE:x86 /OUT:SQLiteningU.lib",dir$)
(requires the DLLs in same directory)

Check that the 3 .lib files are created.

Now you can use 'Import' for the functions:

Code: Select all

Import "SQLiteningU.lib"
    sluF(ColumNumber.l, *FieldValue, *SizeOfField, SetNumber.l = 0)
    sluGetRow(SetNumber.l = 0, ModChars.p-ascii = 0)
    sluOpen(FileName.p-ascii = 0 , ModChars.p-ascii = 0)
    sluSel(Statement.p-ascii, SetNumber.l = 0, ModChars.p-ascii = 0)
EndImport

Import "SQLitening.lib"
    slGetColumnCount(SetNumber.l = 0)
EndImport


err = sluOpen (GetPathPart(ProgramFilename())+"sample.db3")
If Not err

    err = sluSel("Select * from Parts where rowid < 11") 
    If Not err

        Debug "ColumnCount: "+slGetColumnCount()

        While sluGetRow()
            
            Rec$ = ""
            For i = 1 To 4
                buffer$ = Space(100)
                len = Len(buffer$)
                sluF(i, @buffer$, @len)
                Rec$ + PeekS(@buffer$,len,#PB_Ascii) + " - "
            Next
            Debug rec$
        Wend
    Else
        Debug "Error with sluSel(): "+Str(err)
    EndIf
Else
    Debug "can't open sample.db3 - Error code: "+Str(err)
EndIf
@ts-soft:
Could you add this to your tool? Let the user choose to create dynamic loading includes or Import includes.
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 »

Danilo wrote: @ts-soft:
Could you add this to your tool? Let the user choose to create dynamic loading includes or Import includes.
See here: http://www.purebasic.fr/english/viewtop ... 27&t=52712
Drop the DLL on the GUI and the creation of ImportLib is done :wink:
With autodetection of x86 or x64!

Greetings - Thomas
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
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 »

ts-soft wrote:
Danilo wrote: @ts-soft:
Could you add this to your tool? Let the user choose to create dynamic loading includes or Import includes.
See here: http://www.purebasic.fr/english/viewtop ... 27&t=52712
Drop the DLL on the GUI and the creation of ImportLib is done :wink:
With autodetection of x86 or x64!
Nice, thank you! :)
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post by t57042 »

UPGRADE ON WRAPPER for SQlitening.

With the help of PureDLLHelper(Copyright ©2012 by Thomas <ts-soft> Schulz - tks marvelous piece of work :D ) I created the frame for the wrapper.
2 DLL's are needed: the main is SQliteningU.dll - but some functions must be called directly from SQlitening.dll.

This is the main program:

Code: Select all

XIncludeFile "SQLiteningPB.inc"
    dll = SQLiteningU_LoadDLL()
    dll2 = SQLitening_LoadDLL()
    If dll And dll2
        err = sluOpen ("sample.db3")
        If Not err
           
            err = sluSel("Select * from Parts where rowid < 11 order by price")
            If Not err
                NumFlds = slGetColumnCount()

                While sluGetRow()
                   
                  Rec$ = ""
                    For i=1 To NumFlds 
                        buffer$ = Space(100)
                        len = Len(buffer$)
                        sluF(i, @buffer$, @len)
                        Rec$ + PeekS(@buffer$,len,#PB_Ascii) + " - "
                    Next
                    Debug rec$
                 Wend                                
            Else
                Debug "Error with sluSel(): "+Str(err)
            EndIf
              
            st$="create table if not exists test (field1,field2)"
            err=sluExe(st$)
            If Not err
              MessageRequester("","table created")
            Else
                Debug "Error with sluExe(): "+Str(err)
            EndIf  
        Else
            Debug "can't open sample.db3 - Error code: "+Str(err)
          EndIf
        slclose()            
        CloseLibrary(dll)
        CloseLibrary(dll2)
        End
    EndIf
This is the wrapper:

Code: Select all

;SQLiteningPB.inc
;==========================================================================
; Generated with PureDLLHelper, Copyright ©2012 by Thomas <ts-soft> Schulz
;************************************************************************
;Functions from SQliteningU.dll
;************************************************************************

;===========================<[ 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.
Prototype  sluF(ColumNumber.l, *FieldValue, *SizeOfField, SetNumber.l = 0)
;==========================================================================

;============================<[ 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.
Prototype  sluGetRow(SetNumber.l = 0, ModChars.p-ascii = 0)
;==========================================================================

;==============================<[ 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.
Prototype  sluOpen(FileName.p-ascii = 0 , ModChars.p-ascii = 0)
;==========================================================================

;;;==============================<[ 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.p-ascii, SetNumber.l = 0, ModChars.p-ascii = 0)
;==========================================================================

;'==============================<[ Exe ]>===============================
;Declare Function sluExe lib "SQLiteningU.Dll" alias "sluExe" (_
 ;                                byval Statement 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  sluExe(Statement.p-ascii,  ModChars.p-ascii = 0)
;==========================================================================

;============================<[ Sel Str ]>=============================
;Declare Sub sluSelStr lib "SQLiteningU.Dll" alias "sluSelStr" ( _
 ;                                byval Statement As Long, _
  ;                               byval ModChars As Long, _
   ;                              byval FieldsAndRows As Long, _
    ;                             byref SizeOfFieldsAndRows 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.
;   FieldsAndRows is a pointer to the memory which will receive the fields
;                 and rows. The fields and rows are returned as a $VT:$BS
;                 delimited text string.
;   SizeOfFieldsAndRows is both passed and returned. Pass the size of
;                       FieldsAndRows. It must be at least the size of
;                       the returning fields and rows. The actual length
;                       of the returing fields and rows is returned.
;                       If the passed size is too small then the returning
;                       length will be set to -1.
Prototype  sluSelStr(Statement.p-ascii, ModChars.p-ascii , FieldsAndRows.p-ascii, d)
;==========================================================================

;************************************************************************
;Functions from SQlitening.dll
;************************************************************************

;'========================<[ Get Column Count ]>========================
;Declare Function sluGetColumnCount lib "SQLitening.Dll" alias "slGetColumnCount" ( _
 ;                                byval SetNumber As Long) As Long
;   Calls SQLitening.Dll directly.
Prototype  slGetColumnCount(SetNumber.l = 0)
;==========================================================================
;=============================<[ Close ]>==============================
;Declare Sub      sluClose lib "SQLitening.Dll" alias "slClose"
;'   Calls SQLitening.Dll directly.
Prototype  slClose()
;========================================================================

Prototype  sluAttach(a, b, c)
Prototype  sluBuildBindDat(a, b, c, d, e)
Prototype  sluBuildInsertOrUpdate(a, b, c, d, e, f, g)
Prototype  sluConnect(a, b, c, d, e)
Prototype  sluConvertDat(a, b, c, d, e)
Prototype  sluCopyDatabase(a, b, c)
;Prototype  sluExe(a, b)
Prototype  sluExeBind(a, b, c, d)
;Prototype  sluF(a, b, c, d)
Prototype  sluFN(a, b, c, d)
Prototype  sluFNX(a, b, c, d, e)
Prototype  sluFX(a, b, c, d, e)
Prototype  sluGetColumnName(a, b, c, d)
Prototype  sluGetColumnNumber(a, b)
Prototype  sluGetDatabaseAndFileNames(a, b)
Prototype  sluGetError(a, b)
Prototype  sluGetFieldDataTypes(a, b, c)
Prototype  sluGetFile(a, b, c, d)
Prototype  sluGetHandle(a, b)
;Prototype  sluGetRow(a, b)
Prototype  sluGetStatus(a, b, c)
Prototype  sluGetTableColumnNames(a, b, c)
Prototype  sluGetTableNames(a, b, c)
Prototype  sluIsColumnNameValid(a, b)
Prototype  sluIsDatabaseNameValid(a)
Prototype  sluIsTableNameValid(a)
;Prototype  sluOpen(a, b)
Prototype  sluPopDatabase(a)
Prototype  sluPopSet(a, b, c)
Prototype  sluPushDatabase(a)
Prototype  sluPushSet(a, b, c)
Prototype  sluPutFile(a, b, c, d)
Prototype  sluRunProc(a, b, c, d, e, f, g, h, i, j)
;Prototype  sluSel(a, b, c)
Prototype  sluSelBind(a, b, c, d, e)
;Prototype  sluSelStr(a, b, c, d)
Prototype  sluSetProcessMods(a)
Prototype  sluSetRelNamedLocks(a, b, c, d, e)
Prototype  sulGetChangeCount(a)

Prototype  IRISDATE(a)
Prototype  slCloseSet(a)
Prototype  slDisconnect()
Prototype  slGetColumnName(a, b)
Prototype  slGetColumnNumber(a, b)
Prototype  slGetErrorNumber()
Prototype  slGetInsertID()
Prototype  slGetUnusedSetNumber()
Prototype  slIsColumnNumberValid(a, b)
Prototype  slIsFieldNull(a, b)
Prototype  slIsOpen()
Prototype  slIsSetNumberValid(a)


Global sluAttach.sluAttach
Global sluBuildBindDat.sluBuildBindDat
Global sluBuildInsertOrUpdate.sluBuildInsertOrUpdate
Global sluConnect.sluConnect
Global sluConvertDat.sluConvertDat
Global sluCopyDatabase.sluCopyDatabase
Global sluExe.sluExe
Global sluExeBind.sluExeBind
Global sluF.sluF
Global sluFN.sluFN
Global sluFNX.sluFNX
Global sluFX.sluFX
Global sluGetColumnName.sluGetColumnName
Global sluGetColumnNumber.sluGetColumnNumber
Global sluGetDatabaseAndFileNames.sluGetDatabaseAndFileNames
Global sluGetError.sluGetError
Global sluGetFieldDataTypes.sluGetFieldDataTypes
Global sluGetFile.sluGetFile
Global sluGetHandle.sluGetHandle
Global sluGetRow.sluGetRow
Global sluGetStatus.sluGetStatus
Global sluGetTableColumnNames.sluGetTableColumnNames
Global sluGetTableNames.sluGetTableNames
Global sluIsColumnNameValid.sluIsColumnNameValid
Global sluIsDatabaseNameValid.sluIsDatabaseNameValid
Global sluIsTableNameValid.sluIsTableNameValid
Global sluOpen.sluOpen
Global sluPopDatabase.sluPopDatabase
Global sluPopSet.sluPopSet
Global sluPushDatabase.sluPushDatabase
Global sluPushSet.sluPushSet
Global sluPutFile.sluPutFile
Global sluRunProc.sluRunProc
Global sluSel.sluSel
Global sluSelBind.sluSelBind
Global sluSelStr.sluSelStr
Global sluSetProcessMods.sluSetProcessMods
Global sluSetRelNamedLocks.sluSetRelNamedLocks
Global sulGetChangeCount.sulGetChangeCount

Global IRISDATE.IRISDATE
Global slClose.slClose
Global slCloseSet.slCloseSet
Global slDisconnect.slDisconnect
Global slGetColumnCount.slGetColumnCount
Global slGetColumnName.slGetColumnName
Global slGetColumnNumber.slGetColumnNumber
Global slGetErrorNumber.slGetErrorNumber
Global slGetInsertID.slGetInsertID
Global slGetUnusedSetNumber.slGetUnusedSetNumber
Global slIsColumnNumberValid.slIsColumnNumberValid
Global slIsFieldNull.slIsFieldNull
Global slIsOpen.slIsOpen
Global slIsSetNumberValid.slIsSetNumberValid


Procedure.i SQLiteningU_LoadDLL()
  Protected hDLL.i

  hDLL = OpenLibrary(#PB_Any, "SQLiteningU.dll")
  If hDLL <> 0
    sluAttach = GetFunction(hDLL, "sluAttach")
    sluBuildBindDat = GetFunction(hDLL, "sluBuildBindDat")
    sluBuildInsertOrUpdate = GetFunction(hDLL, "sluBuildInsertOrUpdate")
    sluConnect = GetFunction(hDLL, "sluConnect")
    sluConvertDat = GetFunction(hDLL, "sluConvertDat")
    sluCopyDatabase = GetFunction(hDLL, "sluCopyDatabase")
    sluExe = GetFunction(hDLL, "sluExe")
    sluExeBind = GetFunction(hDLL, "sluExeBind")
    sluF = GetFunction(hDLL, "sluF")
    sluFN = GetFunction(hDLL, "sluFN")
    sluFNX = GetFunction(hDLL, "sluFNX")
    sluFX = GetFunction(hDLL, "sluFX")
    sluGetColumnName = GetFunction(hDLL, "sluGetColumnName")
    sluGetColumnNumber = GetFunction(hDLL, "sluGetColumnNumber")
    sluGetDatabaseAndFileNames = GetFunction(hDLL, "sluGetDatabaseAndFileNames")
    sluGetError = GetFunction(hDLL, "sluGetError")
    sluGetFieldDataTypes = GetFunction(hDLL, "sluGetFieldDataTypes")
    sluGetFile = GetFunction(hDLL, "sluGetFile")
    sluGetHandle = GetFunction(hDLL, "sluGetHandle")
    sluGetRow = GetFunction(hDLL, "sluGetRow")
    sluGetStatus = GetFunction(hDLL, "sluGetStatus")
    sluGetTableColumnNames = GetFunction(hDLL, "sluGetTableColumnNames")
    sluGetTableNames = GetFunction(hDLL, "sluGetTableNames")
    sluIsColumnNameValid = GetFunction(hDLL, "sluIsColumnNameValid")
    sluIsDatabaseNameValid = GetFunction(hDLL, "sluIsDatabaseNameValid")
    sluIsTableNameValid = GetFunction(hDLL, "sluIsTableNameValid")
    sluOpen = GetFunction(hDLL, "sluOpen")
    sluPopDatabase = GetFunction(hDLL, "sluPopDatabase")
    sluPopSet = GetFunction(hDLL, "sluPopSet")
    sluPushDatabase = GetFunction(hDLL, "sluPushDatabase")
    sluPushSet = GetFunction(hDLL, "sluPushSet")
    sluPutFile = GetFunction(hDLL, "sluPutFile")
    sluRunProc = GetFunction(hDLL, "sluRunProc")
    sluSel = GetFunction(hDLL, "sluSel")
    sluSelBind = GetFunction(hDLL, "sluSelBind")
    sluSelStr = GetFunction(hDLL, "sluSelStr")
    sluSetProcessMods = GetFunction(hDLL, "sluSetProcessMods")
    sluSetRelNamedLocks = GetFunction(hDLL, "sluSetRelNamedLocks")
    sulGetChangeCount = GetFunction(hDLL, "sulGetChangeCount")

    ProcedureReturn hDLL
  EndIf

  ProcedureReturn #False
EndProcedure

Procedure.i SQLitening_LoadDLL()
  Protected hDLL.i

  hDLL = OpenLibrary(#PB_Any, "SQLitening.dll")
  If hDLL <> 0
    IRISDATE = GetFunction(hDLL, "IRISDATE")
    slAttach = GetFunction(hDLL, "slAttach")
    slBuildBindDat = GetFunction(hDLL, "slBuildBindDat")
    slBuildInsertOrUpdate = GetFunction(hDLL, "slBuildInsertOrUpdate")
    slClose = GetFunction(hDLL, "slClose")
    slCloseSet = GetFunction(hDLL, "slCloseSet")
    slConnect = GetFunction(hDLL, "slConnect")
    slConvertDat = GetFunction(hDLL, "slConvertDat")
    slCopyDatabase = GetFunction(hDLL, "slCopyDatabase")
    slDisconnect = GetFunction(hDLL, "slDisconnect")
    slExe = GetFunction(hDLL, "slExe")
    slExeBind = GetFunction(hDLL, "slExeBind")
    slF = GetFunction(hDLL, "slF")
    slFN = GetFunction(hDLL, "slFN")
    slFNX = GetFunction(hDLL, "slFNX")
    slFX = GetFunction(hDLL, "slFX")
    slGetChangeCount = GetFunction(hDLL, "slGetChangeCount")
    slGetColumnCount = GetFunction(hDLL, "slGetColumnCount")
    slGetColumnName = GetFunction(hDLL, "slGetColumnName")
    slGetColumnNumber = GetFunction(hDLL, "slGetColumnNumber")
    slGetDatabaseAndFileNames = GetFunction(hDLL, "slGetDatabaseAndFileNames")
    slGetError = GetFunction(hDLL, "slGetError")
    slGetErrorNumber = GetFunction(hDLL, "slGetErrorNumber")
    slGetFieldDataTypes = GetFunction(hDLL, "slGetFieldDataTypes")
    slGetFile = GetFunction(hDLL, "slGetFile")
    slGetHandle = GetFunction(hDLL, "slGetHandle")
    slGetInsertID = GetFunction(hDLL, "slGetInsertID")
    slGetRow = GetFunction(hDLL, "slGetRow")
    slGetStatus = GetFunction(hDLL, "slGetStatus")
    slGetTableColumnNames = GetFunction(hDLL, "slGetTableColumnNames")
    slGetTableNames = GetFunction(hDLL, "slGetTableNames")
    slGetUnusedSetNumber = GetFunction(hDLL, "slGetUnusedSetNumber")
    slIsColumnNameValid = GetFunction(hDLL, "slIsColumnNameValid")
    slIsColumnNumberValid = GetFunction(hDLL, "slIsColumnNumberValid")
    slIsDatabaseNameValid = GetFunction(hDLL, "slIsDatabaseNameValid")
    slIsFieldNull = GetFunction(hDLL, "slIsFieldNull")
    slIsOpen = GetFunction(hDLL, "slIsOpen")
    slIsSetNumberValid = GetFunction(hDLL, "slIsSetNumberValid")
    slIsTableNameValid = GetFunction(hDLL, "slIsTableNameValid")
    slOpen = GetFunction(hDLL, "slOpen")
    slPopDatabase = GetFunction(hDLL, "slPopDatabase")
    slPopSet = GetFunction(hDLL, "slPopSet")
    slPushDatabase = GetFunction(hDLL, "slPushDatabase")
    slPushSet = GetFunction(hDLL, "slPushSet")
    slPutFile = GetFunction(hDLL, "slPutFile")
    slRunProc = GetFunction(hDLL, "slRunProc")
    slSel = GetFunction(hDLL, "slSel")
    slSelAry = GetFunction(hDLL, "slSelAry")
    slSelBind = GetFunction(hDLL, "slSelBind")
    slSelStr = GetFunction(hDLL, "slSelStr")
    slSetProcessMods = GetFunction(hDLL, "slSetProcessMods")
    slSetRelNamedLocks = GetFunction(hDLL, "slSetRelNamedLocks")

    ProcedureReturn hDLL
  EndIf

  ProcedureReturn #False
EndProcedure

Somebody knows how to adapt the PROTOTYPE in this function?

Code: Select all

;============================<[ Sel Str ]>=============================
;Declare Sub sluSelStr lib "SQLiteningU.Dll" alias "sluSelStr" ( _
 ;                                byval Statement As Long, _
  ;                               byval ModChars As Long, _
   ;                              byval FieldsAndRows As Long, _
    ;                             byref SizeOfFieldsAndRows 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.
;   FieldsAndRows is a pointer to the memory which will receive the fields
;                 and rows. The fields and rows are returned as a $VT:$BS
;                 delimited text string.
;   SizeOfFieldsAndRows is both passed and returned. Pass the size of
;                       FieldsAndRows. It must be at least the size of
;                       the returning fields and rows. The actual length
;                       of the returing fields and rows is returned.
;                       If the passed size is too small then the returning
;                       length will be set to -1.
Prototype  sluSelStr(Statement.p-ascii, ModChars.p-ascii , FieldsAndRows.p-ascii, d)
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:Somebody knows how to adapt the PROTOTYPE in this function?

Code: Select all

;============================<[ Sel Str ]>=============================
;Declare Sub sluSelStr lib "SQLiteningU.Dll" alias "sluSelStr" ( _
 ;                                byval Statement As Long, _
  ;                               byval ModChars As Long, _
   ;                              byval FieldsAndRows As Long, _
    ;                             byref SizeOfFieldsAndRows 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.
;   FieldsAndRows is a pointer to the memory which will receive the fields
;                 and rows. The fields and rows are returned as a $VT:$BS
;                 delimited text string.
;   SizeOfFieldsAndRows is both passed and returned. Pass the size of
;                       FieldsAndRows. It must be at least the size of
;                       the returning fields and rows. The actual length
;                       of the returing fields and rows is returned.
;                       If the passed size is too small then the returning
;                       length will be set to -1.
Prototype  sluSelStr(Statement.p-ascii, ModChars.p-ascii , FieldsAndRows.p-ascii, d)

Code: Select all

Prototype  sluSelStr(Statement.p-ascii, ModChars.p-ascii , *FieldsAndRows.Ascii, *SizeOfFieldsAndRows.Long)
Usage:

Code: Select all

len.l = 10000
buffer.i = AllocateMemory(len)

sluSelStr(Statement$, ModChars$, buffer, @len)

If len = -1
  ; buffer too small
Else
  s.s = PeekS(buffer,-1,#PB_Ascii)
EndIf

FreeMemory(buffer)
Same principle as sluF.
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post by t57042 »

Hi Danilo,
sluselstr ok. thanks

What is wrong with this?

Code: Select all

'========================<[ Get Column Name ]>=========================
;Declare Sub      sluGetColumnName lib "SQLiteningU.Dll" alias "sluGetColumnName" ( _
 ;                                byval ColumnNumber As Long, _
  ;                               byval ColumnName As Long, _
   ;                              byref SizeOfColumnName As Long, _
    ;                             byval SetNumber As Long)
;   ColumnName is a pointer to the memory which will receive the column
;              name(s).  Will return all column names if the passed column
;              number is zero. If all column names are returned then it is
;              a delimited text string which is $NUL seperated.  A Null
;              (hex '00') will be added to end (meaningless if all column
;              names are returned).
;   SizeOfColumnName is both passed and returned. Pass the size of ColumnName.
;                    It must be at least the size of the returning column name + 1.
;                    The actual length of the returing column name(s) is returned.
;                    If the passed size is too small then returning length will be
;                    set to -1.
Prototype  sluGetColumnName(colNumber.l, *colName.ascii, *SizeOfColumnName.Long, SetNumber.l=0)

Code: Select all

lengt.l = 10000
            buffer.i = AllocateMemory(lengt)
            sluGetColumnName(1, buffer, @lengt)
            If lengt = -1
              Debug "buffer too small"
            Else
              s$ = PeekS(buffer,-1,#PB_Ascii)
            EndIf 
            FreeMemory(buffer)
            Debug s$
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:What is wrong with this?
Looks good. What do you get?
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post by t57042 »

buffer to small and a repetition of the result of the previous query

Richard
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post by t57042 »

CORRECTION:
buffer to small and a repetition of the result of the previous query
I get 'buffer to small'

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:I get 'buffer to small'
You get -1.

-1 could also mean there is an error. Use sluGetError() / slGetError() to get the error description.
In this case, it returns "-14 = Invalid set number" - because sluGetColumnName() requires a valid SetNumber.

I guess you want to get the column names of the table!? Use sluGetTableColumnNames() for that. ;)

See example:

Code: Select all

Import "SQLiteningU.lib"
    sluF(ColumNumber.l, *FieldValue, *SizeOfField, SetNumber.l = 0)
    sluGetRow(SetNumber.l = 0, ModChars.p-ascii = 0)
    sluOpen(FileName.p-ascii = 0 , ModChars.p-ascii = 0)
    sluSel(Statement.p-ascii, SetNumber.l = 0, ModChars.p-ascii = 0)
    
    sluGetColumnName(colNumber.l, *colName.ascii, *SizeOfColumnName.Long, SetNumber.l)
    sluGetTableColumnNames(TableName.p-ascii, *colName.ascii, *SizeOfColumnName.Long)
    sluGetError(*buffer.Ascii, *bufferLen.Long)
EndImport

Import "SQLitening.lib"
    slGetColumnCount(SetNumber.l = 0)
EndImport

Procedure.s slGetError()
    Protected err$
    Protected len.l = 1024
    Protected buffer.i = AllocateMemory(len)
    
    sluGetError(buffer,@len)
    If len <> -1
        err$ = PeekS(buffer,-1,#PB_Ascii)
    EndIf
    
    FreeMemory(buffer)
    ProcedureReturn err$
EndProcedure


err = sluOpen (GetPathPart(ProgramFilename())+"sample.db3")
If Not err
    
    err = sluSel("Select * from Parts where rowid < 11") 
    If Not err
        
        Debug "ColumnCount: "+slGetColumnCount()
        
        Debug "sluGetRow:"
        While sluGetRow()
            
            Rec$ = ""
            For i = 1 To 4
                buffer$ = Space(100)
                len = Len(buffer$)
                sluF(i, @buffer$, @len)
                Rec$ + PeekS(@buffer$,len,#PB_Ascii) + " - "
            Next
            Debug rec$
        Wend
        Debug "----------"
        
        Debug "sluGetColumnName:"
            len = 10000
            buffer.i = AllocateMemory(len)
            sluGetColumnName(1, buffer, @len, 0)
            If len = -1
                Debug slGetError()
            Else
                s$ = PeekS(buffer,-1,#PB_Ascii)
                Debug s$
            EndIf
            FreeMemory(buffer)
        Debug "----------"

        Debug "sluGetTableColumnNames:"
            len = 10000
            buffer.i = AllocateMemory(len)
            sluGetTableColumnNames("Parts", buffer, @len)
            If len = -1
                Debug slGetError()
            Else
                start = buffer
                name$ = ""
                Repeat
                    s$ = PeekS(start,-1,#PB_Ascii)
                    start + Len(s$) + 1
                    If s$ <> ""
                        Debug s$
                        name$ + s$ + Chr(10)
                    EndIf
                Until s$ = ""
                MessageRequester("Column names for table 'Parts'",name$)
            EndIf
        FreeMemory(buffer)
        Debug "----------"
        
        
        
    Else
        Debug "Error with sluSel(): "+Str(err)
    EndIf
Else
    Debug "can't open sample.db3 - Error code: "+Str(err)
EndIf
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post by t57042 »

Thanks Danilo.
A question - where do you find the IMPORT files SQLiteningU.lib and Import "SQLitening.lib"?

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:Thanks Danilo.
A question - where do you find the IMPORT files SQLiteningU.lib and Import "SQLitening.lib"?
Found them in the same directory where I had run the following code: Run this code to create the import libs
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post by t57042 »

Thanks Danilo, another problem.
The sluConnect function connects to the server to work in remote mode.

Following 3 lines work:

Code: Select all

sluConnect()
sluConnect("")
sluConnect("localhost")
Connecting via an IP adress (correct and tested with ping) does not work:

Code: Select all

 sluConnect("192.168.1.103")
I get :
error -16 cannot connect
statement= connect -- server = 192.168.1.103 Port = 0
Richard

Code: Select all

;============================<[ Connect ]>=============================
;Declare Function sluConnect lib "SQLiteningU.Dll" alias "sluConnect" (_
 ;                                byval Server As Long, _
  ;                               byval Port As Long, _
   ;                              byval ModChars As Long, _
    ;                             byval OutData As Long, _
     ;                           byref SizeOfOutData As Long) As Long
;   Server 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.
;   DataOut is a pointer to the returning out data. If not needed you
;           may pass a zero.
;   SizeOfOutData is both passed and returned. Pass the size of OutData.
;                 It must be at least the size of the returning out data.
;                 The actual length of the returing out data is returned.
;                 If the passed size is too small then the returning length will
;                 be set to -1.
Prototype  sluConnect(Server.p-ascii=0, Port.l = 0, ModChars.p-ascii=0,Outdata.p-ascii=0, *bufferLen.Long=0)
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:Connecting via an IP adress (correct and tested with ping) does not work:

Code: Select all

 sluConnect("192.168.1.103")
I get :
error -16 cannot connect
statement= connect -- server = 192.168.1.103 Port = 0
Check which port is used and set it as 2nd argument.
If Port is zero or omitted it will default to 51234.
What is the correct port on your server? Firewall settings checked? Routing checked?
t57042 wrote:

Code: Select all

;============================<[ Connect ]>=============================
;Declare Function sluConnect lib "SQLiteningU.Dll" alias "sluConnect" (_
 ;                                byval Server As Long, _
  ;                               byval Port As Long, _
   ;                              byval ModChars As Long, _
    ;                             byval OutData As Long, _
     ;                           byref SizeOfOutData As Long) As Long
;   Server 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.
;   DataOut is a pointer to the returning out data. If not needed you
;           may pass a zero.
;   SizeOfOutData is both passed and returned. Pass the size of OutData.
;                 It must be at least the size of the returning out data.
;                 The actual length of the returing out data is returned.
;                 If the passed size is too small then the returning length will
;                 be set to -1.
Prototype  sluConnect(Server.p-ascii=0, Port.l = 0, ModChars.p-ascii=0,Outdata.p-ascii=0, *bufferLen.Long=0)
Outdata is outgoing. You can't use p-ascii with it - p-ascii is only for incoming parameters.

Use same method ("buffer, @len") as before:

Code: Select all

Prototype  sluConnect(Server.p-ascii=0, Port.l=0, modChars.p-ascii=0, *outData=0, *outDataLen.Long=0)
Don't forget: sluConnect returns 0 for OK, error number if failed.
t57042
Enthusiast
Enthusiast
Posts: 203
Joined: Fri Feb 22, 2008 12:28 pm
Location: Belgium

Re: wrapper - dll translation

Post by t57042 »

What is the correct port on your server? Firewall settings checked? Routing checked?
How can I check that? Is the default port not always ok?
btw

Code: Select all

 sluconnect("localhost",0)
--> this works

Richard
Post Reply