[Gambas-user] Working with .so library

Admin admin at ...3661...
Thu Jun 15 07:30:32 CEST 2017


01.06.2017 16:25, Admin пишет:
> 31.05.2017 19:50, Benoît Minisini пишет:
>> Le 31/05/2017 à 14:36, Admin a écrit :
>>> 31.05.2017 18:18, Benoît Minisini пишет:
>>>> Le 31/05/2017 à 12:38, Admin a écrit :
>>>>> 31.05.2017 16:58, Benoît Minisini пишет:
>>>>>> Apparently all that black box is written in C++ with QT, and 
>>>>>> without the header of the library interface , I can't tell you if 
>>>>>> it is possible to use the library with Gambas, and how.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>> I was lucky enough to find the header file shared by developers 
>>>>> and an example program in C++ that utilizes this lib.
>>>>>
>>>>> Here they are: http://allunix.ru/back/atol-header.tar.gz
>>>>>
>>>>
>>>> Maybe CreateFptrInterface() is a C++ only thing, and that you must 
>>>> call another function from the C interface to do something similar. 
>>>> But I couldn't find it reading the C header.
>>>>
>>>> You need the documentation of the C interface, or at least an 
>>>> example written in C to know. You usually can't use C++ exported 
>>>> functions from Gambas.
>>>>
>>>> Regards,
>>>>
>>> Maybe it is. One of the authors of the original .so library stated 
>>> on one forum:
>>>
>>> "You can use purely C interface like this:
>>>
>>> void *fptr = CreateFptrInterface();
>>> put_DeviceSingleSetting(fptr, L"Port", "4");
>>> ApplySingleSettings(fptr);
>>>
>>> "
>>>
>>> but I can't see the difference.
>>>
>>>
>>> Dmitry.
>>>
>>
>> Then it should work the way you did. But you did not respect the 
>> interface of put_DeviceSingleSettingAsInt(). It wants a "wchar_t *", 
>> whereas the Gambas strings are encoded in ASCII or UTF-8.
>>
>> You must first convert the Gambas string to wchar_t by using 
>> Conv$(<string>, "UTF-8", "WCHAR_T") or Conv$(<string>, "ASCII", 
>> "WCHAR_T").
>>
>> Regards,
>>
> Oh. My. God. That's exactly what I needed.
>
> Actually, I saw that the library expetcs a variable in wchar_t format, 
> I had no idea what it was, so I googled "gambas wchar_t" and found 
> absolutely nothing. Then I wrote my first letter to this maillist.
>
> And now when you gave me this line of the code, the library works 
> exactly the way it should, doing everything I'm asking it for.
>
> Huge thank you!
>
> Dmitry
>

Greetings again.

All your help was very important for me, I now have completed my cash 
register software to the point where it does everything my company 
needs. I must say Gambas is a great language, it's very easy to learn 
from scratch, I'm surprised how obvious everything is. But there is a 
lot of work for me left to do mostly in terms of managing wrong human 
actions. My software works good if the employee doesn't do any mistakes, 
but that's unrealistic, so there's a lot of things I want to control and 
check. And that's where I'm stuck.

This library (which still calls itself a driver) theoretically is able 
to return a lot of values that I need, but I can't understand basic 
rules of how do we take output from a C-lib in Gambas.

 From http://gambaswiki.org/wiki/howto/extern I understood that I need 
to locate a space in memory and pass a pointer to a library so that it 
can write data into that place in ram, which I would then read and set free.

So I have to declare a pointer, then Alloc(8) it, then pass it to my 
library and then read from it like it is a stream. Does this principle 
still work in current version of Gambas?

What I don't understand is how I construct the code in my particular case.

To make an interface to the library I declare external pointer like this:

     Extern CreateFptrInterface(ver As Integer) As Pointer

Then I declare some pointers that I'll use with help of the interface I 
created:

     Extern put_DeviceEnable(p as Pointer, mode as Integer)

     Extern GetStatus(p as Pointer, StatRequest as String)

Then I declare the pointer which will be that interface:

     Public kkmDrv as Pointer

So then in sub I can do

kkmDrv = CreateFptrInterface(12) ' this establishes the interface

put_DeviceEnabled(kkmDrv, 1) ' this transfers the comand to the library 
through the interface.

And it works great.

But then If I want to get some data from the library, as I understand, I 
have to declare another pointer, allocate ram for it and pass my request.

I don't understand how should I pass that pointer to GetStatus() while 
also passing my interface pointer to it, let alone reading data back. 
Totally confused.

Any advice would be much appriciated. I don't desperately need to listen 
to my library, it's almost enough just to talk to it one way, but this 
ability could make my software much more reliable and self-controlled, 
so I really wish I could hear my library back.

Best regards.

Dmitry.





More information about the User mailing list