02-28-2005, 06:44 PM
I'm having trouble using VB to access a dll writen in FB, If anyone could look over my code i'd be very thankful
Memsearch.bas
Memsearch.bi
VB Declares
Thanks in advance
Memsearch.bas
Code:
'$dynamic
defint a-z
'$include: 'win\kernel32.bi'
'$include: 'MemSearch.bi'
'$include: 'crt.bi'
dim shared hInstance as long
type MemNode
DataLoc as long
next as MemNode ptr
end type
''::::::
''
'' DllMain is the entry-point (ALWAYS needed with DLL's), don't change the prototype
''
function DllMain ( byval hModule as long, byval reason as long, byval lpReserved as long ) as integer
select case reason
case DLL_PROCESS_ATTACH
hInstance = hModule
case DLL_THREAD_ATTACH, DLL_THREAD_DETACH, DLL_PROCESS_DETACH
end select
DllMain = TRUE
end function
''::::::
''
''
''
function Find ( byref DataArray() as byte, byval target as byte, byref matches() as long) as long
dim FirstNode as MemNode
dim PrevNode as MemNode ptr
dim CurNode as MemNode ptr
dim nummatches as long
nummatches = 0
FirstNode.dataloc = 0
PrevNode = @FirstNode
for l1 = 0 to ubound(DataArray)
if DataArray(l1) = target then
nummatches = nummatches + 1
CurNode = malloc(8)
PrevNode->next = CurNode
CurNode->DataLoc = l1
PrevNode = CurNode
end if
next l1
CurNode = @FirstNode
redim matches(nummatches)
for l1 = 0 to nummatches
matches(l1) = CurNode->DataLoc
CurNode = CurNode->next
next l1
Find = nummatches
end function
function Find_Indexed ( byref DataArray() as byte, byval target as byte, byref matches() as long) as long
dim FirstNode as MemNode
dim PrevNode as MemNode ptr
dim CurNode as MemNode ptr
dim nummatches as long
nummatches = 0
FirstNode.dataloc = 0
PrevNode = @FirstNode
for l1 = 0 to ubound(DataArray)
if DataArray(matches(l1)) = target then
nummatches = nummatches + 1
CurNode = malloc(8)
PrevNode->next = CurNode
CurNode->DataLoc = matches(l1)
PrevNode = CurNode
end if
next l1
CurNode = @FirstNode
redim matches(nummatches)
for l1 = 0 to nummatches
matches(l1) = CurNode->DataLoc
CurNode = CurNode->next
next l1
Find_Indexed = nummatches
end function
Memsearch.bi
Code:
declare function Find lib "MemSearch" alias "Find" ( byref startingloc() as byte, byval target as byte, byref matches() as long) as long
declare function Find_Indexed lib "MemSearch" alias "Find_Indexed" ( byref DataArray() as byte, byval target as byte, byref matches() as long) as long
VB Declares
Code:
Private Declare Function Find Lib "MemSearch.dll" Alias "Find@12" (DataArray() As Byte, ByVal Target As Byte, matches() As Long) As Long
Private Declare Function Find_Indexed Lib "MemSearch.dll" Alias "Find_Indexed@12" (DataArray() As Byte, ByVal Target As Byte, matches() As Long) As Long
Thanks in advance