I'm trying to use a PowerBasic DLL I created with PBDLL 6 in Visual Basic 6.0 SP3. It errors out after calling the DLL function two or three times. The windows error and the VB & PB code is shown below. I would really appreciate some advice.
Thanks, Ron Weber
------------------
Thanks, Ron Weber
Code:
====================================================== Windows 98 - 4.10.1998 - error: This program has performed an illegal operation and will be shut down. If the problem persists, contact the program vendor. VB6 caused an invalid page fault in module KERNEL32.DLL at 0177:bff7a4a3. Registers: EAX=00000018 CS=0177 EIP=bff7a4a3 EFLGS=00010206 EBX=00000002 SS=017f ESP=007fe7f0 EBP=007fe800 ECX=005d0008 DS=017f ESI=005d0000 FS=4b4f EDX=00000020 ES=017f EDI=005d000c GS=0000 Bytes at CS:EIP: 8b 03 25 fc ff ff 0f 3b 45 0c 0f 83 81 00 00 00 Stack dump: 0000001a 7ff527a8 00000000 881a47df 007fe814 bff88d9b 005d0000 00000020 00000000 007fe86c 7ff314f0 005d0000 00000000 0000001a 7ff31520 7ffdd00c ====================================================== Visual Basic 6.0 - SP3 - Module1.bas: ' DataCenter database record. Type DataCenterDB VarTable As String * 6 VarName As String * 100 VarValue As String * 10000 End Type Declare Function GetVar Lib "DC.DLL" Alias "GETVAR" (ByVal x As String, ByVal y As String, ByVal z As String) As String ====================================================== Visual Basic 6.0 - SP3 - frmCreate.bas: Private Sub cmdGetRecord_Click() Dim p As String Dim t As String Dim n As String Dim v As String p = "D:\SIMPLE COMPUTER SOLUTIONS\Software Products\VB 6.0\DataCenter\PowerTree" t = "IN" n = "VAR-48884.4" v = GetVar(p, t, n) MsgBox v End Sub ====================================================== PBDLL 6 - DC.DLL #COMPILE DLL #INCLUDE "*********" TYPE DataCenterDB VarTable AS STRING * 6 VarName AS STRING * 100 VarValue AS STRING * 10000 END TYPE FUNCTION GetVar (BYVAL pname AS STRING, BYVAL t AS STRING, BYVAL n AS STRING) EXPORT AS STRING ON ERROR GOTO Error_Routine CLOSE DIM hFile AS LONG ' data file handle DIM rec AS DataCenterDB ' data file record DIM recs AS LONG ' count of records in data file DIM KeyBlock AS *********** ' index file information DIM combo AS STRING * 106 ' combined 'Table' and 'DataName' DIM tout AS LONG DIM e AS STRING IF pname <> "" AND RIGHT$(pname,1) <> "\" THEN pname = pname + "\" ' Open the data file Open_DB: hFile = FREEFILE tout = 0 Open_Again: ERRCLEAR e = "OPEN" OPEN pname + "DataCenter.DB" FOR RANDOM LOCK READ WRITE AS hFile LEN = LEN(rec) e = "" IF ERR THEN GetVar = "Error - Unable to open data file DataCenter.DB" EXIT FUNCTION END IF ' Get the total number of records in the file and check for sanity. recs = LOF(hFile) \ LEN(rec) IF recs * LEN(rec) <> LOF(hFile) THEN GetVar = "Error - Corrupt data file DataCenter.DB (bad record length)" EXIT FUNCTION END IF ' Store Table and Data Name into 'rec' variable. rec.VarTable = UCASE$(t) rec.VarName = UCASE$(n) combo = rec.VarTable + rec.VarName ' Initialize index. ************************ ********************** ***************************************** IF **************** <> 0 THEN GetVar = "Error - Could not initialize DataCenter.PTX" EXIT FUNCTION END IF ' See if Data Name already exists. ******************** ' Get record. IF **************** = 0 THEN tout = 0 e = "GET" GET hFile, KeyBlock.RecordNumber, rec e = "" GetVar = TRIM$(rec.VarValue) ELSE MSGBOX "Variable Not Found" END IF **************** CLOSE hFile EXIT FUNCTION Error_Routine: IF e = "OPEN" AND tout < 30000 THEN tout = tout + 1 RESUME Open_Again END IF IF e = "GET" AND tout < 30000 THEN tout = tout + 1 CLOSE hFile RESUME Open_DB END IF CLOSE END FUNCTION
Comment