Qbasicnews.com

Qbasic "like" compilers/interpreters => FB Discussion & Programming Help => Topic started by: GalaTyphoon on February 09, 2005, 05:55:54 AM



Title: Visual Basic call to FB DLL problem...
Post by: GalaTyphoon on February 09, 2005, 05:55:54 AM
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 ?


Title: Visual Basic call to FB DLL problem...
Post by: subxero on February 09, 2005, 05:34:18 PM
What code are you using to call the routine?


Title: Visual Basic call to FB DLL problem...
Post by: GalaTyphoon on February 09, 2005, 09:54:03 PM
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


Title: Visual Basic call to FB DLL problem...
Post by: zydon on February 09, 2005, 10:15:27 PM
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.


Title: Visual Basic call to FB DLL problem...
Post by: GalaTyphoon on February 10, 2005, 12:54:42 AM
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...


Title: Visual Basic call to FB DLL problem...
Post by: v3cz0r on February 10, 2005, 01:21:49 AM
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.


Title: Visual Basic call to FB DLL problem...
Post by: zydon on February 10, 2005, 01:37:50 AM
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.


Title: Visual Basic call to FB DLL problem...
Post by: GalaTyphoon on February 10, 2005, 01:59:24 AM
Great  :bounce:
"@8" thingy worked,  many thanks to all of you...