How to get started with ... everything?.

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 192
Joined: Thu Apr 18, 2013 2:48 pm

Re: How to get started with ... everything?

Post by livecodeali » Wed Jan 17, 2018 4:46 pm

@jameshale
For example if we were calling a Mac binary, what code folder would be required?
In terms of what folder to put code in, this release note should be somewhat helpful:
https://github.com/montegoulding/liveco ... support.md

(and the platform ID document it leads to).

For Mac dylibs, you'd want them in /code/universal-mac/
When calling parts of the Mac or iOS framework we do not actually need a code folder I guess.
Correct
When calling any binary how do we signal to lc that this or that code binary is required.
You should only need to put the binary in the right place and load the extension using the extension builder - everything else is handled by the IDE.

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to get started with ... everything?

Post by SparkOut » Wed Jan 17, 2018 10:14 pm

@livecodeali
Thanks, that was a "duh" by me with the ampersand, but correcting that doesn't fix the function. In fact, now it completely crashes out LC.
I have added the foreign data type declaration above the foreign handler binding declaration

Code: Select all

private foreign type CIntArray2 binds to "MCAggregateTypeInfo:EE"
As there are only two analog channels and I can read back the state of each one at a time, I can probably leave it out of the conversion, but I am wondering what the correct syntax for such a structure should be, and why as it is, does Livecode force close (just completely bombs out).

Again, I am learning a lot and really appreciate the help.

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 474
Joined: Thu Sep 04, 2008 6:23 am
Location: Melbourne Australia

Re: How to get started with ... everything?

Post by jameshale » Wed Jan 17, 2018 11:44 pm

Thanks @livecodeali

Some of these release notes really need to be migrated into the guides.
More on the todo list.

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to get started with ... everything?

Post by SparkOut » Thu Jan 18, 2018 11:21 pm

Well I have completed the conversion of all the library functions for the K8055D.dll and can get and set all inputs and outputs, with the exception of the two readback functions.

I will need to read more, but I can't see where things are going wrong at the moment. If I introduce LCMark's _ReadBackAnalogOut function with its foreign data type declaration, Livecode just crashes off the screen. Some further guidance here would be gratefully appreciated.


EDIT: OK, brainwave... the foreign data type declaration was set as "private" - changing this to "public" to make the definition available to the handler has allowed it to work successfully.

I now have a complete interface to the board accessing all the dll functions directly from LCB. YAY! Thank you so much for your help! This has really triggered me to get invested with LCB and I will try hard to find time to study and learn, but I am so, so, so much more able to see where to head than before, although I know I will hit many brick walls very hard.

Thank you to everyone who helped, especially LCMark

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 192
Joined: Thu Apr 18, 2013 2:48 pm

Re: How to get started with ... everything?

Post by livecodeali » Fri Jan 19, 2018 4:25 pm

I'm glad you figured that out - it is in fact a known issue that didn't have a bug report! I've added one now.
http://quality.livecode.com/show_bug.cgi?id=20889

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to get started with ... everything?

Post by SparkOut » Wed Sep 18, 2019 12:47 pm

Hi everyone, hoping for some more help.
After a long hiatus with trying LCB, I have revisited this interface board and the LCB wrapper to the provided dll.
Using now LC v 9.5 I can't get it to work any more. It no longer works with either the self-same scripts cut and pasted from before on this thread, nor the exact same .lcb file from before where I created a complete library to wrap all the dll functions.
Given LCMark's code from above, the simple statement

Code: Select all

answer vellemanOpenDevice(1)
now gives error:

execution error at line 2 (LCB error in file C:/MyName/LCB/LCMark/velleman/velleman.lcb at line 11: unable to load foreign library)

This used to work fine. I have in the meantime changed my computer and now running 64 bit edition of Windows 10 which I thought may have had some bearing, but the Vellman demo still works with the 32 bit dll. I have also tried with the 64 version of the K8055D.dll that Velleman support directed me to, but still get error, this time it says unexpected libffi error.


Any ideas how to solve this?

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to get started with ... everything?

Post by SparkOut » Wed Sep 18, 2019 3:04 pm

Thanks to a suggestion from Trevor, I can confirm that the library is working fine on LC 9.0.4 (on my Windows 10 64-bit laptop).

The problem seems to be with the 64 bit engine version of LC 9.5

Bug reported: https://quality.livecode.com/show_bug.cgi?id=22379

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: How to get started with ... everything?

Post by LCMark » Wed Sep 18, 2019 6:22 pm

@SparkOut : 64-bit windows processes cannot load 32-bit DLLs (and vice-versa) - so (as you already figured out) you need to include the 64-bit version of the DLL in the relevant code folder to work with the 64-bit engine.

The subsequent error would appear to be a bug in the LCB VM - try a version of your LCB file but without the "!<callconv>" at the end of each binding string. e.g.

Code: Select all

private __safe foreign handler _OpenDevice(in pCardAddress as CInt) returns CInt binds to "c:K8055D>OpenDevice!stdcall"
=>
private __safe foreign handler _OpenDevice(in pCardAddress as CInt) returns CInt binds to "c:K8055D>OpenDevice"
64-bit Win32 only has a single calling convention (as opposed to 32-bit Win32 having half-a-dozen); so the VM should be ignoring it (so that you can use the same binding strings with 32-bit and 64-bit versions of the same DLL) - however my guess would be that it isn't currently...

Note: Doing the above will cause the LCB file to not work with 32-bit Windows, so this is just to check my hypothesis is correct rather than a viable solution - if the above does fix it, then it should be easy to fix in the engine for the upcoming 9.5 maintenance release.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: How to get started with ... everything?

Post by trevordevore » Wed Sep 18, 2019 6:28 pm

@LCMark - If the 64-bit only has a single calling convention does that mean that callback functions will now work on Windows?

Example: https://docs.microsoft.com/en-us/window ... _enumproca
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: How to get started with ... everything?

Post by LCMark » Wed Sep 18, 2019 6:45 pm

@trevordevore: Yes - callbacks passed to win32 API functions should work on 64-bit Windows for this reason (callbacks work in 32-bit too, but they pass a cdecl calling convention function pointer - which isn't compatible with Win32 API callback functions usually).

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: How to get started with ... everything?

Post by trevordevore » Wed Sep 18, 2019 7:27 pm

@LCMark - That is great news! I've been unable to wrap a number of Win32 API calls due to this limitation in the 32-bit interface.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to get started with ... everything?

Post by SparkOut » Thu Sep 19, 2019 9:21 am

@LCMark thanks very much. I will try when I can, but currently I am away taking part in the Screwball Rally, a charity fundraising ecpedition, dressed as Shpock, along with 3 other Trekkers driving around northern Europe in a converted Starship.

https://www.screwballrally.co.uk/

https://uk.virginmoneygiving.com/fundra ... Id=1030664

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 474
Joined: Thu Sep 04, 2008 6:23 am
Location: Melbourne Australia

Re: How to get started with ... everything?

Post by jameshale » Thu Sep 19, 2019 9:23 am

You have to love this community :mrgreen:

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to get started with ... everything?

Post by SparkOut » Thu Sep 19, 2019 9:56 am

13 Shuttle lights coming to life sm.jpg
13 Shuttle lights coming to life sm.jpg (21.24 KiB) Viewed 9460 times

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to get started with ... everything?

Post by SparkOut » Thu Sep 19, 2019 9:59 am

18 Deep space really brings out the best in our lighting sm.jpg
18 Deep space really brings out the best in our lighting sm.jpg (11.27 KiB) Viewed 9457 times

Post Reply

Return to “LiveCode Builder”