First Application - Hello, Glasswall
This section describes the steps required to ensure your application has been linked with or has loaded the Glasswall SDK Library successfully. The Glasswall engine is developed in C++ but also included with the SDK are four wrappers allowing use of the Glasswall Library with C#, Java, JavaScript and Python.
This section provides example code for the ‘Hello Glasswall’ example in C++ and each of the four wrapper languages. This code calls the Glasswall SDK ‘Get Library Version’ function. Glasswall will return the version number of the library in use.
- C++
- C#
- Java
- Python
- JavaScript
Steps
- Ensure that the Glasswall SDK has been installed successfully.
- Create a new project/solution in your preferred IDE and link it to the glasswall_core2 library.
- Use the following sample code to return the version number:
Test Application Code
int main()
{
printf("> Request Library version...\n");
printf("> Library Version: %s\n", GW2LibVersion());
return 0;
}
Prerequisites
- Ensure that the DLL (“glasswall.core2.csharp.wrapper”) is added as a reference to your environment to be able to use it.
- Ensure that the Core2 Libraries and all required folders are accessible to the wrapper.
Test Application Code
The following code tests the wrapper code and runs the GW2LibVersion function:
using glasswall.core2.wrapper;
using system;
class Program
{
static void Main(string[] args)
{
Glasswall gw = new Glasswall(pathToLib);
Console.WriteLine("> Request Library version...");
Console.WriteLine("> Library Version: " + gw.LibVersion());
}
}
Prerequisites
- The Java wrapper requires a 64 bit version of the JRE to be installed. This wrapper has been tested with Java SRE 18.
Environment Variables (Linux)
- The Glasswall library uses signal handling in order to prevent crashes from occurring, but this can interfere with the JVM. Signal chaining will need to be setup in order to prevent errors in Glasswall from propagating into the JVM. More information can be found on the Installation page.
Test Application Code
The following code tests the wrapper code and runs the GW2LibVersion function:
import java.io.IOException;
import com.glasswall.core2javabridge.*;
public class Core2JavaExample {
public static void main(String argv[]) throws IOException
{
System.loadLibrary("Core2JavaBridge");
Core2JavaBridge gw = new Core2JavaBridge();
try
{
// Request Library Version
System.out.println("> Request Library Version...");
System.out.println("> Library Version: " + gw.GW2LibVersion());
}
catch (Exception error)
{
System.out.println("error - exception caught: " + error.getMessage());
}
}
}
Output
> Request Library Version...
> Library Version: 2.0
Prerequisites
The following code examples work with 64-bit versions of Python 2.7 and 3.8. The required dependencies are specified in the code examples.
Test Application Code
The following code tests the wrapper code and runs the GW2LibVersion function:
import sys
import logging
import Core2Py
def main():
from Core2Py import Interface_GwCore2
sys.path.append("C:\\temp\\Core2Py.py")
print('Loading Library')
gw = Interface_GwCore2("C:\\temp\\Core2\\glasswall_core2.dll")
print('Done')
libVer = gw.GW2LibVersion()
print('> Request Library version... ')
print('> Library version: ' + str(libVer.text))
if __name__ == "__main__":
main()
Prerequisites
- The JavaScript wrapper requires Node.js version 10.16.3. More recent versions of Node may not be compatible.
- Additional required modules include ffi and ref. Appropriate versions should be installed prior to running the test application.
- Ensure that the Core2 Libraries and all required folders are accessible to the wrapper.
let path = require('path');
let main = function () {
// Include the Glasswall JavaScript Wrapper module
try {
let engine_path = "c:\\temp\\glasswall_core2.dll";
let glasswall = require("c:\\temp\\Core2JS.js");
// Change working directory to allow correct loading of GW library and its sub-libraries
process.chdir(path.dirname(engine_path.toLowerCase()));
// Create an instance of the Glasswall Library
var gw = new glasswall(engine_path);
}
catch (err) {
console.log("\n Unable to load Glasswall JavaScript wrapper");
console.log(err)
}
// Call the GWFileVersion API function
console.log("> Request Library version...");
console.log("> Library version: " + gw.GW2LibVersion());
};
if (require.main === module) {
main();
}
Output
<... other output removed ...>
> Request Library version...
> Library version: 2.0
Please note that the version number and any additional information returned is dependent on the version of Glasswall installed.