Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-02

How to access libraries from other languages?

12 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Chavoux Luyt

Hi guys,

The recent threat on Raspberry libraries made me think. I remember that it was possible in Delphi to access .ddl libraries written in C or C++ (a bit more work) by wrapping them and using a "far" call? I did this a while ago, so not clear on the details anymore. Typically I would write a driver etc. for hardware in C/C++ and then have a Delphi wrapper class that I could use to access the hardware. I assume this is still possible in Lazarus? Are there any tutorials etc. or will the old Delphi methods still work? Will this also work with Linux .so files? For that matter, are there any other way for Lazarus to get direct access to the hardware (except maybe use inline assembler)?

Thanks for bringing me back up to speed!

Cheers,
Chavoux
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150215/96d108f2/attachment.html>

Reply by email

Sven Barth
to Chavoux Luyt
Chavoux Luyt wrote 14 lines
Hi guys, The recent threat on Raspberry libraries made me think. I remember that it was possible in Delphi to access .ddl libraries written in C or C++ (a bit more work) by wrapping them and using a "far" call? I did this a while ago, so not clear on the details anymore. Typically I would write a driver etc. for hardware in C/C++ and then have a Delphi wrapper class that I could use to access the hardware. I assume this is still possible in Lazarus? Are there any tutorials etc. or will the old Delphi methods still work? Will this also work with Linux .so files? For that matter, are there any other way for Lazarus to get direct access to the hardware (except maybe use inline assembler)? Thanks for bringing me back up to speed!

C libraries are no problem. In fact we have many import units for various C libraries (e.g. X11, Gtk, etc.). C++ is more problematic. In theory the compiler contains support for C++ classes, but that is nowhere near usable currently so a C++ API needs to be flattened to a C one like is done with the Qt libraries.

Regards,
Sven

Reply by email

Den
to Sven Barth

lol, speaking of which Sven, what's the progress report on the C++ Classes? :D

- Dennis

Sven Barth wrote 31 lines
On 15.02.2015 16:46, Chavoux Luyt wrote: > Hi guys, > > The recent threat on Raspberry libraries made me think. I remember that > it was possible in Delphi to access .ddl libraries written in C or C++ > (a bit more work) by wrapping them and using a "far" call? I did this a > while ago, so not clear on the details anymore. Typically I would write > a driver etc. for hardware in C/C++ and then have a Delphi wrapper class > that I could use to access the hardware. I assume this is still possible > in Lazarus? Are there any tutorials etc. or will the old Delphi methods > still work? Will this also work with Linux .so files? For that matter, > are there any other way for Lazarus to get direct access to the hardware > (except maybe use inline assembler)? > > Thanks for bringing me back up to speed! C libraries are no problem. In fact we have many import units for various C libraries (e.g. X11, Gtk, etc.). C++ is more problematic. In theory the compiler contains support for C++ classes, but that is nowhere near usable currently so a C++ API needs to be flattened to a C one like is done with the Qt libraries. Regards, Sven -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

zeljko
to Sven Barth
Sven Barth wrote 9 lines
Am 16.02.2015 04:48 schrieb "Den" < <mailto:>>: > > lol, speaking of which Sven, what's the progress report on the C++ Classes? :D Currently not working on it. Generics and packages have higher priority. But I plan to continue it especially since the API of our company's OS is C++ based ^^

That will be the one of the greatest features :)

zeljko

Reply by email

Sven Barth
to zeljko
"zeljko" wrote 16 lines
On 02/16/2015 08:04 AM, Sven Barth wrote: > > Am 16.02.2015 04:48 schrieb "Den" < > <mailto:>>: > > > > > lol, speaking of which Sven, what's the progress report on the C++ > Classes? :D > > Currently not working on it. Generics and packages have higher priority. > But I plan to continue it especially since the API of our company's OS > is C++ based ^^ That will be the one of the greatest features :)

Don't look forward to it too much. It will likely only work for simple cases. E.g. once a C++ class uses operators (without providing the functionality in other ways) it will likely break down...

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150216/23ebc05a/attachment.html>

Reply by email

zeljko
to Sven Barth
Sven Barth wrote 23 lines
Am 16.02.2015 08:35 schrieb "zeljko" < <mailto:>>: > > On 02/16/2015 08:04 AM, Sven Barth wrote: >> >> Am 16.02.2015 04:48 schrieb "Den" < <mailto:> >> <mailto: <mailto:>>>: >> >> > >> > lol, speaking of which Sven, what's the progress report on the C++ >> Classes? :D >> >> Currently not working on it. Generics and packages have higher priority. >> But I plan to continue it especially since the API of our company's OS >> is C++ based ^^ > > > That will be the one of the greatest features :) Don't look forward to it too much. It will likely only work for simple cases. E.g. once a C++ class uses operators (without providing the functionality in other ways) it will likely break down...

I thought that it'll really work. Without ability to override virtual methods it's unuseable for me.

z

Reply by email

Den
to zeljko

Indeed.. It's no easy task for sure. Sven would have to implement all features of the C++ Class that C++ supports. I'm guessing Sven is gonna go with the basic VMT C++ support, which would probably include virtual method overriding, am I right Sven?

- Dennis

zeljko wrote 40 lines
On 02/16/2015 11:08 AM, Sven Barth wrote: > Am 16.02.2015 08:35 schrieb "zeljko" < > <mailto:>>: > > > > On 02/16/2015 08:04 AM, Sven Barth wrote: > >> > >> Am 16.02.2015 04:48 schrieb "Den" < > <mailto:> > >> <mailto: <mailto:>>>: > >> > >> > > >> > lol, speaking of which Sven, what's the progress report on the > C++ > >> Classes? :D > >> > >> Currently not working on it. Generics and packages have higher > priority. > >> But I plan to continue it especially since the API of our > company's OS > >> is C++ based ^^ > > > > > > That will be the one of the greatest features :) > > Don't look forward to it too much. It will likely only work for simple > cases. E.g. once a C++ class uses operators (without providing the > functionality in other ways) it will likely break down... I thought that it'll really work. Without ability to override virtual methods it's unuseable for me. z -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Sven Barth
to zeljko: I thought that it'll really work. Without ability to override virtual methods it's…
"zeljko" wrote 19 lines
On 02/16/2015 11:08 AM, Sven Barth wrote: > > Am 16.02.2015 08:35 schrieb "zeljko" < > <mailto:>>: > > > > > On 02/16/2015 08:04 AM, Sven Barth wrote: > >> > >> Am 16.02.2015 04:48 schrieb "Den" < > <mailto:> > >> <mailto: <mailto:>>>: > > >> > >> > > >> > lol, speaking of which Sven, what's the progress report on the C++ > >> Classes? :D > >> > >> Currently not working on it. Generics and packages have higher

priority.

> >> But I plan to continue it especially since the API of our company's

OS

Show quoted text 11 lines
> >> is C++ based ^^ > > > > > > That will be the one of the greatest features :) > > Don't look forward to it too much. It will likely only work for simple > cases. E.g. once a C++ class uses operators (without providing the > functionality in other ways) it will likely break down... I thought that it'll really work. Without ability to override virtual

methods it's unuseable for me.

I consider virtual methods as "simple cases" ;) After all I need them as well...
What I meant in my example however are especially operators that are not supported in Pascal like "[]" or "()" or dereferenciation. Also Pascal operator overloads work differently by being static methods instead of members that can use "this"/"Self".

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150216/22a6b186/attachment.html>

Reply by email

Sven Barth
to Den: Indeed.. It's no easy task for sure. Sven would have to implement all features of the…
"Den" wrote
Indeed.. It's no easy task for sure. Sven would have to implement

all features of the C++ Class that C++ supports. I'm guessing Sven is gonna go with the basic VMT C++ support, which would probably include virtual method overriding, am I right Sven?

More or less, yes. Plus support for automatic calling of con- and destructors depending on scope entry/exit for instances located on the stack. Maybe also special handling for cppclass generics to get the mangled names right.
With these most cases should be covered, but not every C++ class under the sun will be usable then.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150216/01d2a780/attachment.html>

Reply by email

Chavoux Luyt

Hi again...

<snip>

From: Den

Show quoted text 44 lines
Subject: Re: [Lazarus] How to access libraries from other languages? To: Message-ID: Content-Type: text/plain; charset=windows-1252; format=flowed Indeed.. It's no easy task for sure. Sven would have to implement all features of the C++ Class that C++ supports. I'm guessing Sven is gonna go with the basic VMT C++ support, which would probably include virtual method overriding, am I right Sven? - Dennis On 2015-02-16 04:19 AM, zeljko wrote: > On 02/16/2015 11:08 AM, Sven Barth wrote: >> Am 16.02.2015 08:35 schrieb "zeljko" < >> <mailto:>>: >> > >> > On 02/16/2015 08:04 AM, Sven Barth wrote: >> >> >> >> Am 16.02.2015 04:48 schrieb "Den" < >> <mailto:> >> >> <mailto: <mailto:>>>: >> >> >> >> > >> >> > lol, speaking of which Sven, what's the progress report on the >> C++ >> >> Classes? :D >> >> >> >> Currently not working on it. Generics and packages have higher >> priority. >> >> But I plan to continue it especially since the API of our >> company's OS >> >> is C++ based ^^ >> > >> > >> > That will be the one of the greatest features :) >> >> Don't look forward to it too much. It will likely only work for simple >> cases. E.g. once a C++ class uses operators (without providing the >> functionality in other ways) it will likely break down... > > I thought that it'll really work. Without ability to override virtual > methods it's unuseable for me.

I was maybe thinking more low-level (e.g. when using a compiled C++ library without the source code)? All C++ class methods are translated into (mangled) functions in any case, so as long as Lazarus can wrap these as methods in a class of its own it should work? It should even be possible to wrap 2 or 3 C++ classes into one Lazarus class?

Cheers and thanks for the insights so far.
Chavoux
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150216/d563080b/attachment-0001.html>

Reply by email

Sven Barth
to Chavoux Luyt
"Chavoux Luyt" wrote
I was maybe thinking more low-level (e.g. when using a compiled C++

library without the source code)? All C++ class methods are translated into (mangled) functions in any case, so as long as Lazarus can wrap these as methods in a class of its own it should work? It should even be possible to wrap 2 or 3 C++ classes into one Lazarus class?

Let me say it this way: it is possible (with non virtual functions only), but I definitely don't recommend it.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150216/c64e6e90/attachment.html>

Reply by email