Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Visual Basic call to FB DLL problem...
#1
i tried to call the addnumbers function which is in the Mydll sample from Visual Basic, but i couldn't figure out how to.
i wasn't able to call the addnumbers function from VB. FB compiled the dll with no problem but when i called it from VB, it raised runtime error 453 "Can't find DLL entry point ADDNUMBERS in C\FreeBASIC\examples\dll\mydll.dll"

i have uppercased the function names but it didn't matter. Actually, i'm stucked, can somebody help me please ?
Reply
#2
What code are you using to call the routine?
color=blue]subxero - admin at this place.[/color]
Reply
#3
Thanks for reply. This is the VB code.
Code:
Private Declare Function AddNumbers Lib "C:\FreeBASIC\examples\dll\mydll.dll" Alias "ADDNUMBERS" (ByVal operand1 As Long, ByVal operand2 As Long) As Long
Private Sub Form_Load()
  MsgBox AddNumbers(10, 20)
End Sub
Reply
#4
Window API reference call is a case-sensitive. In this case, the Alias string must follow the actual one:

Code:
Private Declare Function AddNumbers Lib "C:\FreeBASIC\examples\dll\mydll.dll" Alias "AddNumbers" (ByVal operand1 As Long, ByVal operand2 As Long) As Long
Private Sub Form_Load()
  MsgBox AddNumbers(10, 20)
End Sub

It should working in VB I hope. I've no VB to test it.
= inc(¢) Big Grin
Reply
#5
thanks zydon however it didn't work.

for clarity the code below ise FreeBasic DLL side

Code:
option explicit
#ifdef FB__WIN32
'$include: 'win\kernel32.bi'
#endif

declare function AddNumbers lib "mydll" Alias "AddNumbers" ( byval operand1 as integer, byval operand2 as integer ) as integer

    dim shared hInstance as long

    
#ifdef FB__WIN32

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
#endif


function AddNumbers ( byval operand1 as integer, byval operand2 as integer ) as integer

    AddNumbers = operand1 + operand2
    
end function

and here it's the Vb side again;

Code:
Private Declare Function AddNumbers Lib "C:\FreeBASIC\examples\dll\mydll.dll" (ByVal operand1 As Long, ByVal operand2 As Long) As Long

Private Sub Form_Load()
  MsgBox AddNumbers(10, 20)
End Sub

this is not working. i've tried all the cases (upper or lower case).
i wonder if it is about compiler parameters...
Reply
#6
I've no clue how VB will "mangle" the imported names, try adding ALIAS "AddNumbers@8" to the VB prototype, or declare it as CDECL at the FB side and as ALIAS "_AddNumbers" at VB.

Or maybe LIB can't contain the full path to the DLL? Put the .DLL at the same dir where the client .EXE is, that's where Windows first checks for DLL's, then at the PATH env variable.
Reply
#7
You right v1ctor, I also found the same thing. I tried to call using Rapid-Q basic it's failed to find "AddNumbers" entry points from the dll. Then I use "AddNumbers@8" after using Quikview it show the additional "@8" for it's arguments on the it's reference name.

I use the following Rapid-Q code to make it work:

[syntax="Rapid-Q"]
$apptype console

declare function AddNumbers lib "mydll.dll" alias "AddNumbers@8" _
( byval op1 as long, byval op2 as long ) as long

print "1 + 2 ="; AddNumbers( 1, 2 )

input "Press Enter to exit..", k!
[/syntax]

ps - tried to include mydll.def in the same directory with the following content:

Code:
LIBRARY mydll
EXPORTS AddNumbers

somehow, the file mydll.def get deleted after the dll compiled and the reference name still show additional "@8" thing.
= inc(¢) Big Grin
Reply
#8
Great :bounce:
"@8" thingy worked, many thanks to all of you...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)