Author Topic: How FB program calling O2 dll  (Read 904 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 150
How FB program calling O2 dll
« on: July 30, 2018, 07:25:45 PM »
Hello Charles

How does a Freebasic  exe program call an O2 dll  ?  can you show me how to do it?

how does a FB exe program can make use of O2 libraries functions ?

Thanxx
« Last Edit: July 30, 2018, 07:27:19 PM by Chris Chancellor »

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 617
    • Charles Pegge
Re: How FB program calling O2 dll
« Reply #1 on: July 31, 2018, 11:20:29 AM »
Hi Chris,

I have not done this for years! FreeBasic uses GCC to build its binaries, and GCC requires .a import files for DLL linkage.

For each DLL imported into FreeBasic, you have to write a .def file, listing all the DLL calls.
The call names  have @n suffixes to indicate the number of bytes being passed

Then use dlltool.exe to build your .a file

It's like dancing in wellies.  ;D

There is a complete example in the o2 package:

examples\UseRTL32\FBO2DLLTEST
« Last Edit: July 31, 2018, 11:38:46 AM by Charles Pegge »

Offline Josť Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2472
    • Josť Roca Software
Re: How FB program calling O2 dll
« Reply #2 on: July 31, 2018, 03:01:27 PM »
This nasty business of import libraries is the thing that I more dislike from FreeBasic, to the point that I never use it. In my framework, I use LoadLibrary/FreeLibrary.

Offline Josť Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2472
    • Josť Roca Software
Re: How FB program calling O2 dll
« Reply #3 on: July 31, 2018, 05:09:30 PM »
> There is a complete example in the o2 package:
> examples\UseRTL32\FBO2DLLTEST

Which does not cover the essential problem of working with strings. Beginners don't know that you can't simply use AS STRING and hope that it will work with any language. FreeBasic dynaminc ansi strings use a proprietary format that is incompatible with other languages.

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 150
Re: How FB program calling O2 dll
« Reply #4 on: July 31, 2018, 05:38:19 PM »
Thanxx Charles

i will look into that code and figure out how to do it,  FB 's dll is a much harder to do than O2  dll
O2 dll is so much simpler

Thanxx Jose,  what would be best strings to use  in another language if we are getting FB ansi strings from a FB dll ?

can we use  WSTRING * 100   in FB ?    that means allocate a fix length of 100 characters to be passed from FB dll
maybe i can add a null at the end of the string


Offline Marc Pons

  • Newbie
  • *
  • Posts: 37
  • Programming for hobby
Re: How FB program calling O2 dll
« Reply #5 on: July 31, 2018, 05:53:17 PM »
@Josť sorry it seems you have got a chewin gum under your shoes  :)


Offline Josť Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2472
    • Josť Roca Software
Re: How FB program calling O2 dll
« Reply #6 on: July 31, 2018, 06:54:23 PM »
> can we use  WSTRING * 100   in FB ?    that means allocate a fix length of 100 characters to be passed from FB dll
maybe i can add a null at the end of the string.

Do you know what a WSTRING is? No, you don't. In FreeBasic, a WSTRING is a null terminated unicode string. Being null terminated means that you don't have to add a null and that WSTRING * 100 will have a capacity of 99 unicode characters and a double null terminator. In PowerBasic, a WSTRING is something different: A dynamic unicode OLE string.

You can use wathever you wish as long as the code that will use it is prepared to deal with the passed or returned data. And this is the problem: that you don't know how to write such code and we can teach you in five minutes what it has taken us years of learning.


Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 150
Re: How FB program calling O2 dll
« Reply #7 on: July 31, 2018, 07:48:27 PM »
Thanxx Jose

i will use WSTRING*101   without the null added as it is already terminated with a null character
good learning from you

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 617
    • Charles Pegge
Re: How FB program calling O2 dll
« Reply #8 on: July 31, 2018, 08:28:15 PM »
So we have not put you off using FreeBasic yet, Chris :)

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 150
Re: How FB program calling O2 dll
« Reply #9 on: July 31, 2018, 09:32:59 PM »
No Charles, not at all

we will be using a mixture of C#, O2 and FB to tackle our PB translation to 64bits.

as a matter of fact, O2 is much more better and flexible than FB which is strongly type.
the handling of strings by FB is very wierd,  we would like to use O2 Bstring which is the best possible
to match PB strings !

whatever we can't translate to O2, we will  try out on FB and whatever FB cannot do (such as GUI interface) we
will use C# .    C# will form the front end only and all the backend computations and file handling by O2 and FB.

eventually, C# would be replaced by C++ when we are able to master it.



Offline Josť Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2472
    • Josť Roca Software
Re: How FB program calling O2 dll
« Reply #10 on: July 31, 2018, 09:52:53 PM »
> and whatever FB cannot do (such as GUI interface)

Really? First notice. I wonder how Paul has managed to build his editor and how I have been able to write hundreds of examples that use a GUI.

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 150
Re: How FB program calling O2 dll
« Reply #11 on: July 31, 2018, 10:25:52 PM »

https://www.freebasic.net/forum/viewtopic.php?t=23484

please look at the replies by Pritchard

Offline Josť Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2472
    • Josť Roca Software
Re: How FB program calling O2 dll
« Reply #12 on: July 31, 2018, 11:01:52 PM »
Sorry, I don`t have time to read all this. If you mean that the language has not native procedures to build a GUI, then I agree (neither C++ has them), but this doesn't mean that you can't build a GUI using the Windows API or other libraries.

Offline Paul Squires

  • Jr. Member
  • **
  • Posts: 98
    • PlanetSquires
Re: How FB program calling O2 dll
« Reply #13 on: August 01, 2018, 04:28:14 AM »
That is a 3 year old post. FB has grown in 3 years.

There is nothing in PowerBasic that we can't do in FreeBasic with the possible exception of some esoteric COM stuff (that most PB'ers didn't use anyway).

GUI in FreeBasic is easy especially if you understand WinAPI. My FireFly Visual Designer has proved that, the new WinFBE proves that, all of Jose's WinFBX and CWindow examples prove that. And this is just on the Windows operating system side. There are many more examples of GUI in Linux including several popular cross platform libraries.

Don't be too quick to judge FB. Sure, it has shortcomings but until you learn how to use it properly you are simply over extending yourself by wanting to use C#, O2, FB, etc for your project conversion.
Paul Squires
FireFly Visual Designer SQLitening Database System JellyFish Pro Editor
http://www.planetsquires.com