Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Basic Misc > Calling a FreeB...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 1443 of 1466
Post > Topic >>

Calling a FreeBASIC-DLL from VB

by Wolfgang Enzinger <weusenet@[EMAIL PROTECTED] > Mar 16, 2008 at 01:09 PM

Hi,

I'm currently trying to write a DLL in FreeBASIC for calling from VB.
However, VB seems to load the DLL but cannot find my exported procedure
whatever I try.

This is my FB source (VBTest.bas):

DECLARE FUNCTION AddNumbers STDCALL ( _
   BYVAL operand1 AS INTEGER, BYVAL operand2 AS INTEGER ) _
   AS INTEGER

FUNCTION AddNumbers STDCALL ( _
   BYVAL operand1 AS INTEGER, BYVAL operand2 AS INTEGER ) _
   AS INTEGER EXPORT
   RETURN operand1 + operand2
END FUNCTION

Compilation using
fbc.exe -dll -export VBTest.bas
results in a file VBTest.dll.

Then my VB code:

Declare Function AddNumbers _
  Lib "VBTest.dll" _
  (ByVal operand1 As Long, ByVal operand2 As Long) _
  As Long

Sub main()
Debug.Print AddNumbers(1, 2)
End Sub

This fails with an error message saying that AddNumbers() cannot be found
in VBTest.dll. Obviously this is a correct error description because when
I
try this:

Sub main()
Dim hLib&, l&
hLib = LoadLibrary("VBTest.dll")
  If hLib Then
  l = GetProcAddress(hLib, "AddNumbers")
  FreeLibrary hLib
  End If
End Sub

then LoadLibrary() succeeds but GetProcAddress() returns 0.

I tried some variations like using an ALIAS clause but none of them
helped.
Anybody knows what I'm doing wrong here?

Any help much appreciated.

Wolfgang




 2 Posts in Topic:
Calling a FreeBASIC-DLL from VB
Wolfgang Enzinger <weu  2008-03-16 13:09:50 
Re: Calling a FreeBASIC-DLL from VB
Wolfgang Enzinger <&qu  2008-03-30 12:19:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon May 12 9:52:37 CDT 2008.