How to get started with ... everything?

Moderators: LCMark, LCfraser

Post Reply
SparkOut
Posts: 1655
Joined: Sun Sep 23, 2007 4:58 pm

How to get started with ... everything?

Post by SparkOut » Tue Jan 09, 2018 9:38 pm

For the life of me, I cannot figure out how to get to set up LCB to do anything useful. I have played with the pink circle widget demo and although that "works" it renders a cropped image. But that isn't helping me learn what to do. I can copy the code and get it to do that, but how do I determine what code I need to do the things I want to do? There just don't seem to be any handles on it. I would love to get more involved, but I don't have an entry point.

My target will only be Windows (10).

What I am ultimately hoping is that LCB will mean that I can leverage other low level functions, and make calls to third party dlls?

For instance, if I have a prepackaged 3rd party (Windows standard) dll is there a way I can use LCB to be the glue to access the functions in a called dll and receive the returned value?

That's the long term goal. But for the life of me, I would love just to get started on the road to learning the way there.

Are there any better intros than the pink circle sample?

MaxV
Posts: 1402
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

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

Post by MaxV » Wed Jan 10, 2018 5:04 pm

Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

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

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

Post by jameshale » Thu Jan 11, 2018 1:11 am

You could also log in to your account at LiveCode.com and look down the left hand list at the “Learning” category. I have a “Widget Course” listed there. It is not too bad, although there are a couple of ‘bugs’. Read the comments for each lesson.


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

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

Post by SparkOut » Thu Jan 11, 2018 10:24 pm

Thanks to everyone for helping - there's a lot more info out there than I thought.
Special thanks to Bernd who contacted me off forum and gave me invaluable help to get me started.

I know I'm trying to run before walking, but my ultimate goal is to access functions in a 3rd party dll on Windows. I have compiled a C++ console file which uses LoadLibrary and then GetProcAddress to access the functions which works by using LCS to poll the state by getting the value returned to the shell console, having set the hideConsoleWindows to true.

I would like to translate this to LCB if possible.

I have used syntax borrowed from n.allen in this thread http://forums.livecode.com/viewtopic.php?f=93&t=25463 which (after correcting the dll path) works to load the library, but fails to return anything, and reports an error "unknown language". Any ideas what that could be about? In the meantime I will carry on practicing with more sensible tasks.

Thanks again

MaxV
Posts: 1402
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

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

Post by MaxV » Fri Jan 12, 2018 4:30 pm

If you just want to work with DLL just read this: http://livecode.wikia.com/wiki/Working_with_DLL
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

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

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

Post by LCMark » Fri Jan 12, 2018 7:23 pm

@SparkOut: Can you share the C code you are trying to convert to LCB? I might be able to help out :)

@MaxV: That explains how to build an external - which is still a viable way to extend LC. However, the advantage of doing it in LCB is that you get greater integration with the engine, and you don't have to touch any C/C++ IDEs (like visual studio) - assuming you have the DLL already compiled and waiting to be used.

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

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

Post by SparkOut » Mon Jan 15, 2018 12:04 am

@LCMark sure, where/how would you like it?
I am trying to access the K8055D.dll provided with Velleman VM110N USB experimentation board. They have a software kit here: https://www.velleman.eu/downloads/files ... ev1206.zip with example sample source and compiled files for Delphi, VB6, C++ etc (looks like it's old stuff, TBH). I used the DevC source and compiled a console exe to call from LC with shell to have a way of getting access to the dll and returning results to LC. I can do the job I need to do with it. I would just love to be able to get there without needing 3rd party IDEs. (Mind you, my familiarity with LCB is even less than some of these other samples, but this is how we learn.)

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

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

Post by LCMark » Tue Jan 16, 2018 2:11 pm

@SparkOut: The velleman API is really simple - so equally simple to bind to from LCB:

Here is an example lcb file with bindings to some of the DLLs functions (the rest are all very similar!), and some example LCB public handlers which wrap them (they are what is called from LCS).

Code: Select all

library velleman

use com.livecode.foreign

private __safe foreign handler _OpenDevice(in pCardAddress as CInt) returns CInt binds to "c:K8055D>OpenDevice!stdcall"
private __safe foreign handler _CloseDevice() returns nothing binds to "c:K8055D>CloseDevice!stdcall"
private __safe foreign handler _ReadAnalogChannel(in pChannel as CInt) returns CInt binds to "c:K8055D>ReadAnalogChannel!stdcall"
private __safe foreign handler _ReadAllAnalog(out rData1 as CInt, out rData2 as CInt) returns nothing binds to "c:K8055D>ReadAllAnalog!stdcall"

public handler vellemanOpenDevice(in pCardAddress as Integer) returns Integer
	return _OpenDevice(pCardAddress)
end handler

public handler vellemanCloseDevice() returns nothing
	_CloseDevice()
end handler

public handler vellemanReadAllAnalog() returns String
	variable tData1 as CInt
	variable tData2 as CInt
	_ReadAllAnalog(tData1, tData2)
	return tData1 formatted as string & "," & tData2 formatted as string
end handler

end library
Create a folder 'velleman' and put the above in as 'velleman.lcb'.
Create a folder code in 'velleman'.
Create a folder 'x86-win32' in 'code'.
Then copy the dll into the x86-win32 folder.

The above sets up the lcb extension source structure. If you then fire up the Extension Builder and point it at the velleman LCB file and click test extension, the vellemanOpenDevice() public handlers etc should be available to call like normal LCS handlers (e.g. answer vellemanOpenDevice(1) - gives me -1 here, as I don't have the board!).

Hope this helps!

P.S. I used '__safe' on the foreign handlers in the above because calling them doesn't require anything passed which can be considered unsafe - they all take ints, return ints, or have out parameters as ints. If any of the calls had required memory blocks to be passed around, or similar things it would not have been appropriate.

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

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

Post by SparkOut » Tue Jan 16, 2018 9:30 pm

@LCMark
This is brilliant, thank you so much. "Simple" is a relative term, obviously! I thought it should be OK in principle but the syntax to declare the handler binding using !stdcall and the folder structure isn't intutive to me. Nevertheless, I am making progress with everyone's kind help.

I have added the following declaration and handler to the .lcb

Code: Select all

private __safe foreign handler _ReadAllDigital(out rData as CInt) returns CInt binds to "c:K8055D>ReadAllDigital!stdcall"

public handler velReadAllDigital() returns Integer
	variable tData as CInt
	return _ReadAllDigital(tData)
end handler
This is actually working to test, and I am getting digital reads from the device. One thing that baffles me is that it refused to work when the foreign handler declaration said "returns nothing" rather than CInt. It makes sense to me that it should require a declaration of "returns CInt", but the _ReadAllAnalog declaration specifically says "returns nothing", although there are "out" variables declared. I am really vague about this syntax, and would love to know what parts of the documentation to study to get more understanding of this.

Post Reply

Return to “LiveCode Builder”