Qbasicnews.com
July 03, 2020, 09:50:37 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: VB Accessing FB DLL  (Read 1230 times)
Tom_Andrews
New Member

Posts: 11


« on: February 28, 2005, 10:44:22 AM »

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
Logged
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #1 on: March 01, 2005, 05:34:08 AM »

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).
Logged

Tom_Andrews
New Member

Posts: 11


« Reply #2 on: March 01, 2005, 09:22:24 AM »

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.
Logged
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #3 on: March 01, 2005, 01:27:45 PM »

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.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!