use freebasic dll with msaccess
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
when i type this:
Declare Function addnumbers Lib "C:\testdll\newaddnumbers.dll" Alias "addnumbers" (ByVal x As Integer, ByVal y As Integer) As Integer
and press return, msaccess automatically changes it to:
Declare Function addnumbers Lib "C:\testdll\newaddnumbers.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
Declare Function addnumbers Lib "C:\testdll\newaddnumbers.dll" Alias "addnumbers" (ByVal x As Integer, ByVal y As Integer) As Integer
and press return, msaccess automatically changes it to:
Declare Function addnumbers Lib "C:\testdll\newaddnumbers.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
Re: use freebasic dll with msaccess
This is a mayor difference, therefore, don't ever use "Integer" for this.michaelleewebb wrote:msaccess understands "integer". is 2 bytes long. we have another call "long" is bigger
2 bytes (in FB = Short)
4 bytes (in FB = Long) but, "Integer" is 4 (FBC 32) or 8 (FBC 64)
DLL code:
Code: Select all
' test.dll
Extern "Windows" ' FBC x64 (32 bit uses "windows-ms"
Function ADDNUMS(ByVal v1 As Long, ByVal v2 As Long) As Long Export
Return v1 + v2
End Function
End Extern
' ----- EOF -----
Code: Select all
' test_dll-test.bas
#Inclib "test"
Declare Function AddNumbers Alias "ADDNUMS"(ByVal As Long, ByVal As Long) As Long
Print AddNumbers(2, 7)
Sleep
' ----- EOF -----
Re: use freebasic dll with msaccess
michaelleewebb,
The code I posted further up works perfectly, from MS Access calling the FB dll. Your problem is not whether the dll sits in System32 or Wow64, it is something completely different. As far as I've understood, your MS Access does not even find the DLL file...!
Check if your MS Access and the compiled dll have the same bitness. If MS Access is a 32-bit version, you must compile the FB dll in 32-bit mode, too. Your runtime error is #48, right?
P.S.:
The code I posted further up works perfectly, from MS Access calling the FB dll. Your problem is not whether the dll sits in System32 or Wow64, it is something completely different. As far as I've understood, your MS Access does not even find the DLL file...!
Check if your MS Access and the compiled dll have the same bitness. If MS Access is a 32-bit version, you must compile the FB dll in 32-bit mode, too. Your runtime error is #48, right?
P.S.:
You must use Integer in MS Access.MrSwiss wrote:This is a mayor difference, therefore, don't ever use "Integer" for this
Re: use freebasic dll with msaccess
No, Long seems also defined (as in QB).You must use Integer in MS Access.
Maybe in Access but, never in FB-dll-code (for Access).
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
hummm, am running 64 bit windows 7. 32 bit msaccess (office 2007)
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
hmmm, i running freebasic 64 bit verison. should i change to 32 bit verison ??
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
error code is 48.
Re: use freebasic dll with msaccess
If Access is 32 bit's, then the DLL must have the same bitness ...
(the underlying OS doesn't have anything to do with it)
This means simply, that you'll have to use FBC 32 bit's.
(to compile the DLL)
(the underlying OS doesn't have anything to do with it)
This means simply, that you'll have to use FBC 32 bit's.
(to compile the DLL)
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
jj2007, that worked, downloaded freebasic 32 bit and created a new folder called c:\freebasic32.
created dll add to it:
#include "Windows.bi"
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
added to msaccess module the following:
Declare Function SayHello Lib "C:\FreeBasic32\sayhi.dll" (ByVal pString As String) As Integer
to on click event i added:
Dim Res As Integer
Res = SayHello("Hello")
AND IT WORKED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
created dll add to it:
#include "Windows.bi"
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
added to msaccess module the following:
Declare Function SayHello Lib "C:\FreeBasic32\sayhi.dll" (ByVal pString As String) As Integer
to on click event i added:
Dim Res As Integer
Res = SayHello("Hello")
AND IT WORKED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
from my newbie point of view the problem was with the bits and btyes. as long as i was compiling a 64 bit dll and using msaccess in 32 bit then things were never going to work out. from here i would like to take over myself until i hit another snag. it seems i need to learn how to pass and receive strings, integers, and doubles. thats the stuff i normally use.
thanks to everyone for your help. where can i go to make a small donation to freebasic, i can't find anywhere on your web site.
thanks to everyone for your help. where can i go to make a small donation to freebasic, i can't find anywhere on your web site.
Re: use freebasic dll with msaccess
Try to use the provided code tag's when posting code, it makes posts more
readable, as well as it allowes to easily "copy & paste" of the code.
You don't have to make single posts, whenever you want to add something
to a already made post, instead, use the edit button ...
That would be all the donations, we'll gladly accept. ;-))
readable, as well as it allowes to easily "copy & paste" of the code.
You don't have to make single posts, whenever you want to add something
to a already made post, instead, use the edit button ...
That would be all the donations, we'll gladly accept. ;-))
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
mrswiss, you were correct about integers being different sizes in msaccess and fb. i went back to the addnumbers program. if i declare in fb:
Function AddNumbers(byval x as integer, byval y as integer) As integer EXPORT
and then declare in msaccess:
Declare Function AddNumbers Lib "c:\freebasic32\addnumbers.dll" (ByVal x As Long, ByVal y As Long) As Long
everything works, if in msaccess i use integers instead of longs i get an error message about not being able to find the dll entry point.
Function AddNumbers(byval x as integer, byval y as integer) As integer EXPORT
and then declare in msaccess:
Declare Function AddNumbers Lib "c:\freebasic32\addnumbers.dll" (ByVal x As Long, ByVal y As Long) As Long
everything works, if in msaccess i use integers instead of longs i get an error message about not being able to find the dll entry point.
Re: use freebasic dll with msaccess
Beware: this only works as long, as you use FBC 32 (it will fail too, in FBC 64).
Reason:
"Integer" = "Long", in FBC 32 only, NOT so in FBC 64, where "Integer" = "LongInt".
If you use "Long", because it being 32 bit fixed size, it works with both compilers
likewise (aka: portable code).
Reason:
"Integer" = "Long", in FBC 32 only, NOT so in FBC 64, where "Integer" = "LongInt".
If you use "Long", because it being 32 bit fixed size, it works with both compilers
likewise (aka: portable code).
-
- Posts: 23
- Joined: Jul 09, 2019 21:18
Re: use freebasic dll with msaccess
good to know mrswiss, i think i've got the numbers thing figured out. i'm looking a strings now. i see pointers (shudder). i used to use them back in the turbo c 2.0 days. lots and lots of fun. do you know a way around using pointers ?? i tried changing this line:
Function SayHello(text As string ptr) As integer EXPORT
to this:
Function SayHello(text As string ) As integer EXPORT
it didn't work.
i understand that a pointer in fb is a place in memory that describes the string. it start location, length,etc. if i must use the string pointer is it wise to try to convert it to a regular string then manipulate the string how i want then convert it back to a string pointer and then send it back to msaccess ? i'm thinking msaccess may be surprised by a string that has changed size.
Function SayHello(text As string ptr) As integer EXPORT
to this:
Function SayHello(text As string ) As integer EXPORT
it didn't work.
i understand that a pointer in fb is a place in memory that describes the string. it start location, length,etc. if i must use the string pointer is it wise to try to convert it to a regular string then manipulate the string how i want then convert it back to a string pointer and then send it back to msaccess ? i'm thinking msaccess may be surprised by a string that has changed size.
Re: use freebasic dll with msaccess
Sorry, pointers are essential to easily interface with C/C++ stuff (like WIN-API).i'm looking a strings now. i see pointers (shudder).
A FB-String is actually a Type (not really a base data-type), therefore, mostly not
recognized by other languages, except maybe, if another BASIC dialect.
Code: Select all
Type _String ' very much simplified
As ZString Ptr data ' actual string's data
As Integer slen ' strings length (in Bytes)
As Integer smem ' allocated memory (in Bytes)
End Type
Code: Select all
ByVal As ZString Ptr ' should work ...
the strings data (C-String zero terminated, more precise: Array of Char).
(a Char in C, is simply a Byte in FB)