Bug maybe? This doesn't work.
I modified your code into an EXE (deleted LIBMAIN, added a PBMAIN,
removed WEP). In PBMAIN I called rvInit followed by rvOpen and I do
not see any "mangled" data.
BTW, the WEP function is not used by 32-bit windows... you can safely
delete that function completely! Also, since your LIBMAIN is only
returning non-zero for all 'fdwReason' values, you can omit the
function completely, since PB/DLL will automatically add a LIBMAIN to
the DLL that returns non-zero.
I also note that you are returning the function values as 16-bit
integers... if you are calling this code from VB, are you declaring
the functions to use 16-bit variables too? In Win32, it is much
faster and more efficient to use 32-bit LONG integers, even in your VB
code.
Here is the EXE version of your code, and this works fine for me...
does this work for you too? If so, this tends to indicate that the
problem is with the VB declaration or calling of the two functions,
rvInit and rvOpen.
#COMPILE EXE
#REGISTER ALL
#DIM ALL
TYPE TableType
TableName AS STRING * 70
FileName AS STRING * 8
LKFileHandle AS LONG
OVFileHandle AS LONG
END TYPE
GLOBAL Tables() AS TableType
GLOBAL TotalTables AS LONG
FUNCTION rvInit () EXPORT AS INTEGER
DIM Temp AS LONG
TotalTables = 0
FOR Temp = 1 TO 5
INCR TotalTables
REDIM PRESERVE Tables(1 TO TotalTables) AS GLOBAL tabletype
Tables(TotalTables).TableName = "TABLE " + STR$(TotalTables)
Tables(TotalTables).FileName = "BLAH"
Tables(TotalTables).LKFileHandle = 0
Tables(TotalTables).OVFileHandle = 0
MSGBOX Tables(TotalTables).TableName, , "rvInit"
NEXT
rvInit = -1 ' success
END FUNCTION
FUNCTION rvOpen () EXPORT AS INTEGER
DIM ThisTable AS LONG
FOR ThisTable = 1 TO TotalTables
MSGBOX Tables(ThisTable).TableName, , "rvOpen"
NEXT
rvOpen = -1 'success
END FUNCTION
FUNCTION PBMAIN
rvinit
rvopen
END FUNCTION
I hope this helps!
Quote:
>When I run the code below, the Init populates the Tables array of user
>type TableType correctly.
>But the Open routine doesn't display the correct information when
>accessing the same array again. The strings seems to 'run' into each
>other.
>However, removing the two LONGs from TableType works. Any
>suggestions? I think this is a bug. Code seems simple enough to me.
>----------------------------------------------------------
>#REGISTER ALL
>#COMPILE DLL
>#DIM ALL
>#INCLUDE "WIN32API.INC"
>#INCLUDE "VBAPI32.INC"
>TYPE TableType
> TableName as String * 70
> FileName as String * 8
> LKFileHandle as Long
> OVFileHandle as Long
>END TYPE
>Global Tables() as TableType
>Global TotalTables as Long
>FUNCTION LibMain(BYVAL hInstance AS LONG, BYVAL fwdReason AS LONG,
>BYVAL lpvReserved AS LONG) EXPORT AS LONG
> SELECT CASE fwdReason
> CASE %DLL_PROCESS_ATTACH
> LibMain = 1 'success!
> EXIT FUNCTION
> CASE %DLL_PROCESS_DETACH
> LibMain = 1 'success!
> EXIT FUNCTION
> CASE %DLL_THREAD_ATTACH
> LibMain = 1 'success!
> EXIT FUNCTION
> CASE %DLL_THREAD_DETACH
> LibMain = 1 'success!
> EXIT FUNCTION
> END SELECT
>END FUNCTION
>FUNCTION rvInit () EXPORT AS INTEGER
> Dim Temp as Long
> TotalTables = 0
> FOR Temp = 1 to 5
> INCR TotalTables
> ReDim Preserve Tables(1 TO TotalTables)
> Tables(TotalTables).TableName = "TABLE " + str$(TotalTables)
> Tables(TotalTables).FileName = "BLAH"
> Tables(TotalTables).LKFileHandle = 0
> Tables(TotalTables).OVFileHandle = 0
> msgbox Tables(TotalTables).TableName, , "DEBUG"
> NEXT
> rvInit = -1 ' success
>END FUNCTION
>FUNCTION rvOpen () EXPORT AS INTEGER
> Dim ThisTable as Long
> For ThisTable = 1 to TotalTables
> msgbox Tables(ThisTable).TableName, , "DEBUG"
> Next
> rvOpen = -1 'success
>END FUNCTION
>FUNCTION Wep (BYVAL nParameter AS INTEGER) EXPORT AS WORD
> Wep = 1 ' success
>END FUNCTION
Lance
powerbasic Support
-------------------------------------------------------------------------
PowerBASIC, Inc. | 800-780-7707 Sales | "We put the Power in Basic!"
316 Mid Valley Center | 831-659-8000 Voice | http://www.powerbasic.com