For details, see How to Use.
Wrapping a C Program with a GUI (1: Simple Edition)
This example invokes a C-language "Hello, World" program from VCSSL and displays the output on the screen.
How to Use
Download and Extract
At first, click the "Download" button at the above of the title of this page by your PC (not smartphone). A ZIP file will be downloaded.
Then, please extract the ZIP file. On general environment (Windows®, major Linux distributions, etc.), you can extract the ZIP file by selecting "Extract All" and so on from right-clicking menu.
» If the extraction of the downloaded ZIP file is stopped with security warning messages...
Execute this Program
Next, open the extracted folder and execute this VCSSL program.
For Windows
Double-click the following batch file to execute:
For Linux, etc.
Execute "VCSSL.jar" on the command-line terminal as follows:
java -jar VCSSL.jar
» If the error message about non-availability of "java" command is output...
After Launching
When you run this VCSSL program, a security warning like the one below appears first. Click "Yes" to continue.
Note: The "execute external programs" feature we use here runs outside VCSSL's security monitoring, so it is effectively able to do anything. The dialog is asking whether you want to allow that. Don't click "Yes" lightly for untrusted programs.
If this warning is annoying each time, open "Security" > "Allow executing system commands" from the VCSSL toolbar and check it to stop showing the dialog.
If you continue, a C program named program.exe will be invoked and executed internally.
Its output, "Hello, World!", appears in the VCSSL console (the black window).
Because program.exe is compiled for Windows, it cannot run on other operating systems such as Linux. If you want to run the same logic on another OS, recompile the C source program.c and adjust the VCSSL invocation accordingly (the extension will likely be .out instead of .exe).
About This Example
It is common to want to call a program written in another language such as C from a lightweight scripting language like VCSSL.
A typical scenario when creating a small GUI tool is:
- Write the user-facing UI in a scripting language
- Write complex or heavy internal processing in C or a similar language
This series will follow that theme over the next few articles. This first entry simply calls a "Hello, World!" program.
Code Walkthrough
The main program is written in VCSSL. VCSSL uses a simple C-like syntax, so C programmers should read and write it without issue.
Full Code
Let's look at the VCSSL code. The entire script looks like this:
- `GUIWrapperSimple.vcssl` -
coding UTF-8;
// Load required libraries
import File;
import Process;
// Get the absolute path of the program file to run
string programPath = getFilePath("program.exe");
// Prepare the program so it can be executed
int processID = newProcess(programPath);
// If Japanese text in the I/O becomes garbled, specify encodings here
// setProcessInputEncoding(processID, "CP932");
// setProcessOutputEncoding(processID, "CP932");
// setProcessErrorEncoding(processID, "CP932");
// Run the program and wait for it to finish
startProcess(processID);
waitForProcess(processID);
// Get the program's output and print it to the VCSSL console (black window)
string output = getProcessOutput(processID);
println(output);
GUIWrapperSimple.vcssl
This script calls the Windows executable program.exe. The source code of that program is below:
#include
int main() {
printf("Hello, World!\n");
return 0;
}
program.c
A plain Hello World program. When you execute it directly, it prints:
Now let's walk through the VCSSL code step by step.
Importing Libraries
The script declares it is written in UTF-8 (to avoid misinterpretation) and loads the required libraries:
coding UTF-8;
// Load required libraries
import File;
import Process;
import.txt
The File library provides utilities for obtaining and converting file paths. Here it is used to get the absolute path of the target program.
The Process library handles executing and controlling external programs, which is what most of this script does.
Preparing the Target Program
We inform newProcess about the external program and have it prepare the program in an executable state:
// Get the absolute path of the program file to run
string programPath = getFilePath("program.exe");
// Prepare the program so it can be executed
int processID = newProcess(programPath);
new.txt
For newProcess, pass the file path of the external program. We recommend using an absolute path because relative paths or just a file name may fail depending on how the script is launched.
Here we use getFilePath to retrieve the absolute path of program.exe before passing it to newProcess.
newProcess returns a process ID, which we store in processID. This ID identifies the external program when executing and controlling it.
Optional Encoding Settings
Next are optional settings before running the external program. They remain commented out in this example but may be useful when handling Japanese text.
// If Japanese text in the I/O becomes garbled, specify encodings here
// setProcessInputEncoding(processID, "CP932");
// setProcessOutputEncoding(processID, "CP932");
// setProcessErrorEncoding(processID, "CP932");
set.txt
It is common to specify character encodings like this to avoid garbled text.
The encoding used by an external program depends on the program or compiler. If VCSSL reads the output with the wrong encoding, the text becomes garbled.
Programs compiled on Windows that print Japanese often use the CP932 (≈ Shift_JIS) encoding. If the output garbles, teach VCSSL to use CP932 as shown. If nothing is specified, UTF-8 is assumed.
Starting Execution and Waiting
We execute the external program with startProcess and wait for it to finish with waitForProcess:
// Run the program and wait for it to finish
startProcess(processID);
waitForProcess(processID);
start.txt
Waiting ensures the script pauses until the program completes, which is simple for programs that just print something and exit.
You could also continue running while exchanging I/O, but here waiting immediately after starting suffices; the output can be collected afterward.
Collecting Output and Displaying It in VCSSL
Finally, retrieve what the external program printed and display it in the VCSSL console:
// Get the program's output and print it to the VCSSL console (black window)
string output = getProcessOutput(processID);
println(output);
output.txt
getProcessOutput returns everything the external program has printed so far.
Alternatively, you can define an onProcessOutput event handler to capture output line by line in real time:
void onProcessOutout(int processID, string output) {
print(output);
}
event.txt
Choose the method that best fits how you want to handle the output.
That concludes the code walkthrough.
If you continued further in the series, you would progressively expand this concept with richer GUI interactions.
License
This VCSSL/Vnano code (files with the ".vcssl" or ".vnano" extensions) is released under the CC0 license, effectively placing it in the public domain. If any sample code in C, C++, or Java is included in this article, it is also released under the same terms. You are free to use, modify, or repurpose it as you wish.
* The distribution folder also includes the VCSSL runtime environment, so you can run the program immediately after downloading.
The license for the runtime is included in the gLicenseh folder.
(In short, it can be used freely for both commercial and non-commercial purposes, but the developers take no responsibility for any consequences arising from its use.)
For details on the files and licenses included in the distribution folder, please refer to "ReadMe.txt".
* The Vnano runtime environment is also available as open-source, so you can embed it in other software if needed. For more information, see here.










