use freebasic dll with msaccess
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
use freebasic dll with msaccess
the problem here is probably sitting right in front of me but i don't see it.
i'm using the example program found under the examples/dll progam. i moved the files to the c:\freebasic folder where the fbc.exe program sits. i compiled the mydll.dll file and compiled the test program. the test program works perfect. but when i try to use the dll in msaccess i get the following error message: file not found: c:\freebasic\mydll.dll. i dont see how it cant find it. its sitting right there in the c:\freebasic folder. this is the code i'm using in msaccess to call the dll,
Option Compare Database
Private Declare Function AddNumbers Lib "c:\freebasic\mydll.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
Private Sub Command1_Click()
Dim x As Integer
x = AddNumbers(1, 2)
MsgBox x
End Sub
what i'm i missing ???
i'm using the example program found under the examples/dll progam. i moved the files to the c:\freebasic folder where the fbc.exe program sits. i compiled the mydll.dll file and compiled the test program. the test program works perfect. but when i try to use the dll in msaccess i get the following error message: file not found: c:\freebasic\mydll.dll. i dont see how it cant find it. its sitting right there in the c:\freebasic folder. this is the code i'm using in msaccess to call the dll,
Option Compare Database
Private Declare Function AddNumbers Lib "c:\freebasic\mydll.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
Private Sub Command1_Click()
Dim x As Integer
x = AddNumbers(1, 2)
MsgBox x
End Sub
what i'm i missing ???
Re: use freebasic dll with msaccess
A dll should be in the same folder as the source code calling it.
Otherwise it should be the system32 or sysWOW64 folder, with the associated .dll.a file (import library file) in the freebasic lib folder (along with all the other .a files)
Otherwise it should be the system32 or sysWOW64 folder, with the associated .dll.a file (import library file) in the freebasic lib folder (along with all the other .a files)
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
moved both files to their own folder c:\testdll. i changed the msaccess code to:
Private Declare Function AddNumbers Lib "c:\testdll\mydll.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
so there are 2 files in the testdll folder.
dlltest.accdb
mydll.dll
the dlltest.accdb is the msaccess program.
i would attach a screen shot of the folder but i can't find the attach button. still getting error message : file not found: c:\testdll\mydll.dll.
maybe the dll needs to be registered ? i don't see why, the test program works and the dll is not registered. maybe the dll needs something more ?
Private Declare Function AddNumbers Lib "c:\testdll\mydll.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
so there are 2 files in the testdll folder.
dlltest.accdb
mydll.dll
the dlltest.accdb is the msaccess program.
i would attach a screen shot of the folder but i can't find the attach button. still getting error message : file not found: c:\testdll\mydll.dll.
maybe the dll needs to be registered ? i don't see why, the test program works and the dll is not registered. maybe the dll needs something more ?
Re: use freebasic dll with msaccess
try leaving out .dll in the declaration
Code: Select all
Private Declare Function AddNumbers Lib "c:\testdll\mydll" (ByVal x As Integer, ByVal y As Integer) As Integer
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
tried:
Private Declare Function AddNumbers Lib "c:\testdll\mydll" (ByVal x As Integer, ByVal y As Integer) As Integer
still no joy.
Private Declare Function AddNumbers Lib "c:\testdll\mydll" (ByVal x As Integer, ByVal y As Integer) As Integer
still no joy.
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
tried placing the dll into c:\windows\system32
tried Private Declare Function AddNumbers Lib "mydll.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
tried Private Declare Function AddNumbers Lib "c:\windows\system32\mydll.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
no luck.
tried Private Declare Function AddNumbers Lib "mydll.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
tried Private Declare Function AddNumbers Lib "c:\windows\system32\mydll.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
no luck.
Re: use freebasic dll with msaccess
You cannot put "private" into a declaration, its only allowed in the "implementation".
(within the .DLL in this particular case)
Try: Declare Function AddNumbers Lib "mydll.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
I'm very "rusty" in Access, but the "data-type" from Access might be
different than "Integer" (this is a FB type).
You might have to consult Access documentation, for that sort of thing.
(finding the correct "data-type" from Access's point of view)
(within the .DLL in this particular case)
Try: Declare Function AddNumbers Lib "mydll.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
I'm very "rusty" in Access, but the "data-type" from Access might be
different than "Integer" (this is a FB type).
You might have to consult Access documentation, for that sort of thing.
(finding the correct "data-type" from Access's point of view)
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
yes from this i learned alot
viewtopic.php?t=2878
access and excel need dlls to be setup different more like this in the dll part:
Function cube alias "cube" ( ByVal arg As Double) As Double Export
cube=arg^3
End Function
then in access, in a module more like this:
Declare Function cube Lib "C:\testdll\fb_2_xls.dll" Alias "cube@8" (ByVal arg As Double) As Double
note the cube@8. i need to add up the btyes being sent to msaccess, little bit more than i want to get into right now. thanks to all for your help.
viewtopic.php?t=2878
access and excel need dlls to be setup different more like this in the dll part:
Function cube alias "cube" ( ByVal arg As Double) As Double Export
cube=arg^3
End Function
then in access, in a module more like this:
Declare Function cube Lib "C:\testdll\fb_2_xls.dll" Alias "cube@8" (ByVal arg As Double) As Double
note the cube@8. i need to add up the btyes being sent to msaccess, little bit more than i want to get into right now. thanks to all for your help.
Re: use freebasic dll with msaccess
step 1
Call this file add.bas and compile with -dll switch to get add.dll
step 2
In the same folder as add.dll (from the above compile) use this test.bas (don't use switch -dll)
Once you get one success at this in it's simplest form, you can experiment with things like cdecl and alias for more complex dll's and dll's from other languages.
Call this file add.bas and compile with -dll switch to get add.dll
Code: Select all
function AddNumbers( byval a as integer, byval b as integer) as integer export
function = a + b
end function
'compile as fbc -dll add.bas
step 2
In the same folder as add.dll (from the above compile) use this test.bas (don't use switch -dll)
Code: Select all
#inclib "add"
declare function AddNumbers( byval a as integer, byval b as integer) as integer
print addnumbers(6,4)
sleep
Once you get one success at this in it's simplest form, you can experiment with things like cdecl and alias for more complex dll's and dll's from other languages.
-
- Posts: 2753
- Joined: Jan 02, 2017 0:34
- Location: UK
Re: use freebasic dll with msaccess
When compiling a FreeBASIC dll for use with another language the .a file, for static libraries, is not used for shared (dynamic) libraries; even though it is generated.
If the other language runs in Windows then we need to generate a standard Windows dll. To avoid the need for appending "@N" we use ' Extern "Windows-MS" '.
For example in FreeBASIC we should use
To use "CryptoDW" in PowerBASIC, for example, we would use
Obviously, CryptoRndIII.dll needs to be in the same directory as the PowerBASIC calling code.
I do not know how to Declare in msaccess but I suspect that [1] may well work.
If the other language runs in Windows then we need to generate a standard Windows dll. To avoid the need for appending "@N" we use ' Extern "Windows-MS" '.
For example in FreeBASIC we should use
Code: Select all
#include once "windows.bi" ' To access Windows data types
Extern "Windows-MS"
Function CryptoDW Alias "CryptoDW" As Dword Export
'blah, blah, blah
End Function
End Extern
To use "CryptoDW" in PowerBASIC, for example, we would use
Code: Select all
Declare Function CryptoDW Lib "CryptoRndIII.dll" Alias "CryptoDW" As Dword ' [1]
Obviously, CryptoRndIII.dll needs to be in the same directory as the PowerBASIC calling code.
I do not know how to Declare in msaccess but I suspect that [1] may well work.
Re: use freebasic dll with msaccess
This works fine with Ms Access (special thanks to deltarho - the Extern did the job):
Note that the DLL does not have to be in the same folder as the exe. You just need to give the full path. This should work with any language that can load a Windows DLL, for example:
Code: Select all
Declare Function SayHello Lib "C:\FreeBasic\Whatever.dll" (ByVal pString As String) As Integer
Sub SayHi()
Dim Res As Integer
Res = SayHello("Hello")
End Sub
Code: Select all
#include "Windows.bi" ' for e.g. MessageBox(0, "Hello string", "Hello title", MB_OK)
Extern "Windows-MS"
Function SayHello(text As string ptr) As integer EXPORT
return MessageBox(0, text, "Gimme an answer:", MB_YESNOCANCEL)
End function
End Extern
Note that the DLL does not have to be in the same folder as the exe. You just need to give the full path. This should work with any language that can load a Windows DLL, for example:
Code: Select all
include \masm32\MasmBasic\MasmBasic.inc
Init
Dll "C:\FreeBasic\Whatever.dll"
Declare SayHello, 1
MsgBox 0, Str$("The result is %i", SayHello("Gimme a string")), "Hi", MB_OK
EndOfCode
Re: use freebasic dll with msaccess
Thanks for that tip deltarho.
I don't have visual basic or microsoft office, but the dll can be created in fb with extern "windows-MS" and recalled in fb with extern "windows-MS"
e.g. (IN FREEBASIC)
extern "windows-MS"
declare function AddNumbers lib "add.dll" alias "AddNumbers"( byval a as integer, byval b as integer) as integer
end extern
However the path ( lib "add.dll" ) in the declaration doesn't work with a full path in fb
e.g.
lib "C:\Users\User\Desktop\testdll\add.dll" produces an error
It looks like in freebasic the dll must be in the same folder as the calling source code, or in the system folder with the import .dll.a file in the fb lib folder.
I don't have visual basic or microsoft office, but the dll can be created in fb with extern "windows-MS" and recalled in fb with extern "windows-MS"
e.g. (IN FREEBASIC)
extern "windows-MS"
declare function AddNumbers lib "add.dll" alias "AddNumbers"( byval a as integer, byval b as integer) as integer
end extern
However the path ( lib "add.dll" ) in the declaration doesn't work with a full path in fb
e.g.
lib "C:\Users\User\Desktop\testdll\add.dll" produces an error
It looks like in freebasic the dll must be in the same folder as the calling source code, or in the system folder with the import .dll.a file in the fb lib folder.
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
well if everyone else is going to keep trying so am i.
i did all of the following in the c:\freebasic folder.
i created a bas file named sayhello.bas in it i copied and pasted:
#include "Windows.bi" ' for e.g. MessageBox(0, "Hello string", "Hello title", MB_OK)
Extern "Windows-MS"
Function SayHello(text As string ptr) As integer EXPORT
return MessageBox(0, text, "Gimme an answer:", MB_YESNOCANCEL)
End function
End Extern
i used this command to create the dll:
fbc -dll sayhello.bas
i got a warning, but it created the dll:
sayhello.bas(5) waring 3(1): passing different pointer types. at parameter 2 of MESSAGEBOX()
i copied the dll to the folder c:\testdll, this is where the msaccess program is.
i started the msaccess program with a short cut thats set to start in c:\testdll.
msaccess doesn't like the decare statement unless you put it in a module, so i created a module name dlls and copied this into it:
Declare Function SayHello Lib "C:\testdll\sayhello.dll" (ByVal pString As String) As Integer
then in my form on the command1 button event "on click" i added the following:
Private Sub Command1_Click()
Dim Res As Integer
Res = SayHello("Hello")
End Sub
i'm still getting the error message: file not found: c:\testdll\sayhello.dll
i tried variations in the declare statement such as:
declare Function SayHello Lib "sayhello.dll" (ByVal pString As String) As Integer
declare Function SayHello Lib "sayhello" (ByVal pString As String) As Integer
still same error message.
thank you all for your support, anyone have an idea ??
i did all of the following in the c:\freebasic folder.
i created a bas file named sayhello.bas in it i copied and pasted:
#include "Windows.bi" ' for e.g. MessageBox(0, "Hello string", "Hello title", MB_OK)
Extern "Windows-MS"
Function SayHello(text As string ptr) As integer EXPORT
return MessageBox(0, text, "Gimme an answer:", MB_YESNOCANCEL)
End function
End Extern
i used this command to create the dll:
fbc -dll sayhello.bas
i got a warning, but it created the dll:
sayhello.bas(5) waring 3(1): passing different pointer types. at parameter 2 of MESSAGEBOX()
i copied the dll to the folder c:\testdll, this is where the msaccess program is.
i started the msaccess program with a short cut thats set to start in c:\testdll.
msaccess doesn't like the decare statement unless you put it in a module, so i created a module name dlls and copied this into it:
Declare Function SayHello Lib "C:\testdll\sayhello.dll" (ByVal pString As String) As Integer
then in my form on the command1 button event "on click" i added the following:
Private Sub Command1_Click()
Dim Res As Integer
Res = SayHello("Hello")
End Sub
i'm still getting the error message: file not found: c:\testdll\sayhello.dll
i tried variations in the declare statement such as:
declare Function SayHello Lib "sayhello.dll" (ByVal pString As String) As Integer
declare Function SayHello Lib "sayhello" (ByVal pString As String) As Integer
still same error message.
thank you all for your support, anyone have an idea ??
Re: use freebasic dll with msaccess
perhaps you need to use alias
Code: Select all
Declare Function SayHello Lib "C:\testdll\sayhello.dll" Alias "SayHello" (ByVal pString As String) As Integer
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
tried:
Declare Function SayHello Lib "C:\testdll\sayhello.dll" Alias "SayHello" (ByVal pString As String) As Integer
still same error message
tried placing dll in c:\windows\system32
same error message
removed dll from c:\windows\system32
Declare Function SayHello Lib "C:\testdll\sayhello.dll" Alias "SayHello" (ByVal pString As String) As Integer
still same error message
tried placing dll in c:\windows\system32
same error message
removed dll from c:\windows\system32
Who is online
Users browsing this forum: No registered users and 17 guests