Archive for the ‘Extensions and API’ Category

Extensions and API

Posted: 2017-01-17 in Extensions and API

Q:
I have just had the time to have a look at the example.c code in c:\lianja\extensions\
It’s very well done and easy to follow.
This just works great.

Code:
myObject = createObject("example_class")
wait window myObject.Sayhello()

Visual Studio 2010 is giving me all sorts of fits on my Windows 10 machine. I assume that I can use mingw32 for my compiles (I have QT and codeblocks installed).
A:
The extensions are normally built using Visual Studio.
I haven’t tried building them using mingw32 but as long as you use the Qt 5.5 install it should be fine.
If you are using Qt in your extensions then you need to use Qt 5.5 and mingw32 NOT visual studio.

Just so you know, you cannot install Visual Studio 2010 on windows 10, you need to install a later version e.g. Visual Studio 2013 or Visual Studio 2015.

Remember that you can also build extensions as hybrid HTML5/JavaScript/Lianja .rsp pages and use a “WebView”.
Also… ChilKat built all their components as native Lianja components using the C/C++ extensions API.
Internally, I use this API extensively also.
This is why I occasionally get impatient with developers who keep asking for something without actually understanding that Lianja has an extensible architecture. It was written this way on purpose.
So the answer to the “Can I do xxx questions” is usually “yes if you understand the extensions capabilities of Lianja”.


Q:
I created a DLL called testlib.dll.
It is basically a copy of the example with the class name changed to herb_class. like so.

{“herb_class”, “clsMyClass”, API_CLASS},

I put the dll (and the .h, .cpp files) in c:\lianja\extensions directory
I modified the extensions.ini file to look like this.

[windows]
library=lianja_extension_example.dll
library=testlib.dll
[linux]
#library=example.so
[mac]
#library=example.dylib

But Lianja cannot see herb_class.
A:
Try rebuilding the example with the make file supplied and see if that still loads and works.
If it does then check the dependencies of your dll using depends if you have it.


The following article describes how to mix C and C++ code when you are developing a Lianja extension using the SDK.
https://isocpp.org/wiki/faq/mixing-c-and-cpp#call-cpp


Q:
Is it possible to use a shared DLL compiled in C only and load it via LoadLibrary()?
A:
Yes.
loadLibrary() can used to load .js, .php, .py or .dll files.
If you SET DEBUG ON and it fails to load the appropriate error message will be written to the debug.txt file in \lianja\debug.


Q:
how to add Lianja extensions to server-side code?
In a desktop app you put the dll in the lianja/extensions folder and modify extensions.ini.
My extension in there works fine if you run my app as a desktop app. I’ve done the same thing for lianja/cloudserver/tenants/public/extensions but it doesn’t seem to work for me when I preview my app in browser. Is there something extra I should be doing?

For reference, in my little test app I have a little proc called testextension.prg which when called creates an object from the extension and returns “successful” if it worked. I then call that on a commandbutton click with Lianja.evaluate() in my app. On desktop this works and “successful” is returned but in a webapp it spits out the page not found error in the browser console which as I understand it simply means “something went wrong and your call didn’t work”.

I have a third party Lianja extension whose functions I want to access in my code. Specifically I want to call them in my server-side procs. I have no access to the source code but it comes as a .dll file so I would assume it’s written with the C/C++ API? Yes it works fine in desktop development mode. It is indeed the chilkat extension!
A:
Extensions are written in C/C++.
Are you just wanting to use Lianja/VFP libraries? If so just open them using SET PROCEDURE TO filename ADDITIVE or REQUIRE().
Incudentally, you can only use compiled code with the cloud server so you need the .dbo files.
Try manually loading it with a full path.
http://www.lianja.com/doc/index.php/LOADLIBRARY()

Q2:
After a bit of testing with loadlibrary it looks like the library gets loaded as it should, even without needing to do it manually, but the createobject command fails when I attempt to build a chilkat object.
A2:
Maybe there is a dependency missing that needs copied into the same directory as your dll is in.
I can confirm that on the current Beta build, the Chilkat Crypt2 extension does load in .rsp pages


The extensions API is for C/C++ only.