Btrieve - declarion help

New to FreeBASIC? Post your questions here.
Post Reply
jos
Posts: 2
Joined: Mar 06, 2024 14:01

Btrieve - declarion help

Post by jos »

Hello,
I ’am completely new to FreeBasic, but i have made a program in PowerBasic for Windows that I want to use ( database Btrieve/Pervasive) . I have tried with a number of different variants but nothing works. After correcting a series of errors, the errors are now localized to declarations and calls.
I am now in need of some help or guidance. How should the declaration and call be declared, where should it be stored to be found for the compiler?

Thank’s in advance

Code: Select all

Declare Function BTRCALL Lib "wbtrv32.dll" (ByVal Word,  Asciiz, any, Integer, Any, ByVal Byte, ByVal Byte) As Integer

Const KEY_BUF_LEN = 255

Type RecordBuffer ’ test file
   Number           As Double
   Dummy            As String * 26
End Type

' ** START **

dim DataBuf          As RecordBuffer
dim PosBlk           As ZString *129 'Asciiz * 129
dim BufLen           As Integer
Dim FilName          As String
Dim KeyBuffer        As ZString *KEY_BUF_LEN + 1 'Asciiz * KEY_BUF_LEN + 1
Dim KeyBufLen        As Byte
Dim KeyNumber        As Integer
Dim Stat             As Integer
Dim KeyNum           As Integer   
Dim TMP              As string

FILNAME   = "TEST.BTR"
PosBlk    = Space$(128)
KeyBuffer = Space$(KEY_BUF_LEN)

'>> Open File
KeyBufLen = KEY_BUF_LEN
KeyBuffer = FILNAME
BufLen    = Len(DataBuf)
KeyNum    = 0
Stat = BTRCALL(0, PosBlk, DataBuf, BufLen, KeyBuffer, KeyBufLen, KeyNum)

'>> Get First Record
BufLen    = Len(DataBuf)
KeyBuffer = Space$(255)
KeyBufLen = KEY_BUF_LEN
Stat = BTRCALL(12, PosBlk, DataBuf, BufLen, KeyBuffer, KeyBufLen, 0)
If Stat <> 0 Then
   TMP = TMP & "**Error on GETFIRST. " & Str$(Stat) & chr$(13,10)
Else
   TMP = TMP & "GETFIRST = " & DataBuf.Dummy & chr$(13,10)
End If

'>> Get Next Record
BufLen    = Len(DataBuf)
KeyBuffer = Space$(KEY_BUF_LEN)
KeyBufLen = KEY_BUF_LEN
Stat = BTRCALL(6, PosBlk, DataBuf, BufLen, KeyBuffer, KeyBufLen, 0)
If Stat <> 0 Then
   TMP = TMP &  "**Error on GETNEXT. " & Str$(Stat) & chr$(13,10)
Else
   TMP = TMP & "GETNEXT  = " & DataBuf.Dummy & chr$(13,10)
End If

'>> Close File
Stat = BTRCALL(1, PosBlk, DataBuf, BufLen, KeyBuffer, KeyBufLen, KeyNum)
If Stat <> 0 Then
   TMP = TMP & "**Error on Close!" & Str$(Stat) & chr$(13,10)
Else
   TMP = TMP & "CLOSE OK." & chr$(13,10)
End If

? TMP
Lothar Schirm
Posts: 445
Joined: Sep 28, 2013 15:08
Location: Germany

Re: Btrieve - declarion help

Post by Lothar Schirm »

I do not know how Function BTRCALL is defined, but the main error seems to be in the first line:

Code: Select all

Declare Function BTRCALL Lib "wbtrv32.dll" (ByVal Word,  Asciiz, any, Integer, Any, ByVal Byte, ByVal Byte) As Integer
You have a long list of parameters without defining their types. A correct parameter list (fictive) looks like this:

Code: Select all

Function(ByVal s As String, ByVal k As Integer, ByVal x As Double, ByVal something_else As Byte, ByRef anything_else As Any, ...) As Integer 
You should also not use suffixes ($), this causes a lot of warnings.
And I get a compiler error at line 5 (Type RecordBuffer ’ test file). Is there any hidden character that I cannot see?
fxm
Moderator
Posts: 12193
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Btrieve - declarion help

Post by fxm »

Lothar Schirm wrote: Mar 07, 2024 15:20 And I get a compiler error at line 5 (Type RecordBuffer ’ test file). Is there any hidden character that I cannot see?
No, simply replace with ' !
jos
Posts: 2
Joined: Mar 06, 2024 14:01

Re: Btrieve - declarion help

Post by jos »

Thank you very much for the guidance. Much appreciated.

Less errors but doesn't work.

How can the declaration BTRCALL Lib "wbtrv32.dll" know that it is an external dll to be called?
Much appreciated for more input.

Thanks in advance
Lothar Schirm
Posts: 445
Joined: Sep 28, 2013 15:08
Location: Germany

Re: Btrieve - declarion help

Post by Lothar Schirm »

I do not know anything about Btrieve and do not have experiences in working with dlls. I am exclusively programming in FreeBasic as a hobby, sometimes I also play a little bit with simple Windows GUIs. I think if you want to include an external library, you have do include a header file (in this case "wbtrv32.bi" or similiar) at the top of our code which contains all your declarations, types, constants etc. Syntax:

Code: Select all

"#Include "wbtrv32.bi"
Lothar Schirm
Posts: 445
Joined: Sep 28, 2013 15:08
Location: Germany

Re: Btrieve - declarion help

Post by Lothar Schirm »

May this be helpful? viewtopic.php?t=16171
Post Reply