Qbasicnews.com

Full Version: VB Accessing FB DLL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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
Somehow you need the full alias to VB find the FB exported functions, try "_Find@12" and "_Find_Indexed@12" (FB procs begin with an underscore under Windows).
it's not the alias that's the problem, vb freaks out at run time and gives you an error saying can't find entry point "whatever" in the dll if it's the wrong alias.
The problem is VB just crashes and burns when i try to use my functions.
I think it has something to do with passing an array to a dll, but i can't think of what the problem is.
Okay, i didn't notice you were passing the arrays by descriptor (using "()"), FB and VB have completely different internal descriptors so they can't be shared.

Try declaring it as "BYREF matches AS LONG" in the VB include file and "BYVAL matches as LONG PTR" at the FB side, so you can access the array using pointer indexing like "matches[someidx]" (note the "[]'s" instead of "()'s"). That will only work with single-dimension arrays and you will have to pass the array bounds explicitly on some argument, as l|ubound() won't work w/o the descriptors.