Creating C/C++ Apps

There is more to the MoSync SDK than our HTML5 templates and our Wormhole JavaScript Library. You can write complete cross-platform mobile applications using just our C/C++ libraries and APIs, or create powerful hybrid applications that leverage both HTML5 and C/C++ with MoSync. Here are some great guides and tutorials to get you started.

API References

  • API Reference Manuals

    The MoSync Reference Manuals provide a detailed description of the MoSync JavaScript functions, C++ libraries, C functions, widget constants, panics, and resource compiliation commands. They describe the  latest featured releases of the MoSync SDK and MoSync Reload.

  • Feature/Platform Support

    Our platform support and feature/capability tables show you where we have implemented MoSync JavaScript functions, C++ classes, C syscall functions and IOCTLs, and widget constants across the major mobile platforms.

  • Resource Compiler Reference

    This manual describes how your application resources (such as image, audio, and binary files) are handled by MoSync in C/C++, describes the format and lists that can be used to organize your resource files, and the command switches for the resource compiler.

Beginner's Guides

  • Creating Your First C/C++ Application

    This tutorial walks you through the creation of a simple "Hello World" application in C/C++ using the MoSync IDE and introduces you to some of the basic terminology we use throughout our guides, tutorials, and examples.

  • HelloWorld, Deconstructed

    In our beginners tutorial Creating Your First C/C++ Application we asked you to paste our "Hello World" application into the IDE. In this tutorial we are going to take a much deeper look at that code, including how we handle events like key presses using our Moblet framework.

  • MoSync for Java and C# Developers

    Mobile offers developers a new world, with cool devices and nice, easy, small projects compared to that monstrous and boring enterprise code you've been doing in Java or C#, right? Right! It is easy move your Java/C# skill to C++ in MoSync.

Developer's Guides

  • C++ Standard Template Library (STL)

    The C++ Standard Template Library provides a set of common classes and interfaces that greatly extend the core C++ language. It provides a set of classes such as containers, associative arrays, iterators, functions objects, and strings. It also provides algorithms for counting, sorting,  finding, coping, and replacing elements in a container.

  • Collections in MoSync

    The MoSync SDK provides several different collection objects, suitable for different occasions.  Collections let you deal with sets of object collectively, but the way you access the collection varies.

  • Creating a Bluetooth Server

    Many people are developing Bluetooth applications in MoSync. Some of the most interesting applications involve creating a new Bluetooth service so that the user’s phone can receive incoming messages on Bluetooth and act on them. In this tutorial we take a look at using the MAUtil::Server class to provide Bluetooth services.

  • Creating Bluetooth Clients

    The MAUtil::BluetoothDiscoverer class can be used to locate nearby devices and find out which Bluetooth services they support. Once you’ve discovered a device and a service you will need to write a client for that service and open a data connection to the server. That's what we will be doing in this tutorial.

  • Creating User Interfaces With MoSync

    MoSync provides you with a choice of multiple solutions for cross-platform user interface development: the NativeUI C++ Library and the NativeUI HTML/JavaScript Library, the basic C Native UI Widget API, and the non-native C++ MAUI Library. Let's take a look.

  • Custom Downloaders

    There are obvious occasions when you want do download data from the Internet for your games or application.  There are even obvious occasions when you want to download images and sounds using the ImageDownloader and AudioDownloader.  What might appear less obvious is the use of a Custom Downloader.

  • Detecting Events

    Throughout the execution of your program, the MoSync SDK can supply it with events. These are typically things which is happening to the phone. For instance, a button has been pressed or the screen has been touched. They also cover more advanced functions such as 'nothing has happened for a few seconds' or 'the phone has a new location from the GPS'.

  • Determining Location

    In this tutorial we take a look at how to detect a device's current geographical location and how to use location data in your application. We also describe some basic strategies for updating location data on a regular basis.

  • Developing Android Applications

    Android developers will find much to like in the MoSync SDK. Like the native Android SDK, the MoSync SDK utilizes Eclipse as its development environment. Here we provide some advice on building Android application using the MoSync SDK.

  • Developing iPhone Applications

    All of Apple's iPhone, iPad and iPod touchscreen devices run the same operating system: iOS. Currently, the only way to download applications to an iOS device without voiding its warranty is via the Apple App Store. Here we provide advice on building successful iPhone apps with the MoSync SDK.

  • Development Models

    MoSync supports several application development models. We call them the "classic procedural", "event driven, object oriented" and "full GUI-based". The model that you should choose when developing an application depends both on the type of application you are developing and your personal preference.

  • Discovering Devices and Services with Bluetooth

    Implementing Bluetooth in your application is done in three stages. Firstly, there is device discovery: getting the phone to scan for other devices in range. Secondly, there is a service discovery: querying a discovered device to see which protocols and services it supports. Lastly, there is the implementation of a service, a specific transfer of data.

  • Downloading Audio from the Internet

    In addition to the standard methods of downloading data using Connection, HttpConnection, or Downloader objects, the MoSync SDK provides a special downloader, the C++ AudioDownloader class, for retrieving sound files from the Internet.

  • Downloading Data from the Internet

    There are a thousand reasons why you might want your application to get information from the Internet. Perhaps you want to download today’s Dilbert cartoon, or get specific data for the user, or serve adverts, or  connect to a web interface. Maybe you want to implement a new protocol, like FTP or Jabber. In this tutorial we’re going to show you how to get data over HTTP.

  • Downloading Images from the Internet

    Often when using images in MoSync, then the images are available to you as a developer, and you can package them with your application, as described in the tutorial 'Adding Resources to a Project'.  However, there will be many scenarios where you want to show a picture you've not been able to package.  

  • Draw Targets, Clipping

    MoSync graphics operations are always performed to a "draw target". By default, this draw target is the screen, but you can create images that can be drawn to, using maCreateDrawableImage().

  • Framebuffer API

    The Framebuffer API provides an API for overriding the backbuffer of MoSync. In order to use this API, the program should use maFrameBufferGetInfo to fill a structure containing such information as the native pixel format and screensize of the underlying system. These parameters should then in turn be used to allocate memory for a backbuffer.

  • Graphics Primitives

    MoSync provides a number of primitive graphics operations at the syscall level. The maSetColor() function sets a "current color" which will be used by any subsequent primitive operations. The maSetClipRect() and maGetClipRect() functions are used to either define or query a rectangular area of the screen that is affected by graphics operations.

  • HTTP Connections

    This tutorial will show you the basics of HTTP connections in MoSync. You will see how easy it is to write applications which can access HTTP-based information. You will also see how easy it is to stream information over HTTP. This example is written from a Moblet template.

  • Introduction to MAUI

    This tutorial introduces the MoSync API for User Interfaces (MAUI). It describes how to use the MAUI library classes to build screens and widgets and how to extend the MAUI model with your own custom components.

  • MAUtil FrameBuffer

    MAUtil::FrameBuffer emulates a 4 or 8 bits per pixel, palletized display using the FrameBuffer API of MoSync. To initialize the library you provide the FrameBuffer_init with information about the size, colour format and orientation of the screen.

  • MAUtil Graphics

    The graphics API provides a set of functions equivalent to those found in the standard MoSync API, with the addition of a transformation stack. This provides a useful mechanism for keeping transformation state without explicitly managing it on the application side. It is useful for any sort of hierarchical rendering, ranging from UI to advanced graphical effects.

  • MTXml Parser

    MoSync's Tiny XML parser, MTXml, provides an efficient, callback-based way of parsing XML files. MTXml has a SAX-like interface, and is re-entrant: it can start with just the beginning of an XML document and request additional data when needed.

  • MTXml Wrapper

    There is a C++ wrapper for the C-based MTXml parser. It can be used in many ways, but one of the most useful ways is by coupling it to a Connection. This allows the CPU-intensive parsing to be split up into more than one call, spreading the load and improving the application UI's response times. Here we provide an example of how to implement such an XmlConnection.

  • PIM Access and Control

    Our PIM API module is still in the early stage of development, but we have already implemented many vital elements of PIM management, including low-level functions for accessing contact lists. Here we take a quick look at this new interface.

  • Push Notification Tutorial

    Push notifications are a useful way to inform users of external events, such as game updates or mail deliveries. In this tutorial we will take you through the steps of creating a simple application that uses the MoSync C++ Notification Library to register and receive push notifications.

  • Resource Compilation

    Various different types of resources (such as image, audio, and binary files) can be included in your application. Here we discuss how you make MoSync aware of them and ensure type safety. We also give a brief overview of how MoSync compiles resources during the build process.

  • Sensor Control

    Modern smartphones have a variety of in-built sensors to detect, for example, movement, orientation, rotation, proximity, and magnetic fields. This tutorial explains how to start and stop sensors, and to receive sensor data in your application through the MoSync Sensor API.

  • Starting a New Moblet Project

    This tutorial gives you a short introduction to developing mobile applications with MoSync. If you’ve never created a mobile application with MoSync before, this is a great place to start. In this tutorial, we’re going to create a new project in Eclipse, create a new screen, and interact with the user.

  • The Advertising Library and API

    The MoSync Advertising C++ Library and Advertising C API make it easy for C/C++ programmer's to create advertisements and display them in mobile applications. You can get and set properties to determine if the advertisement should be visible in a certain context.

  • The Audio C API

    The MoSync Audio C API make it possible to play multiple audio tracks simultaneously on Android and iOS. In this guide we take a  look at the functions in this API and give you two example programs which demonstrate the capabilities of this API.

  • The Camera C API

    In this tutorial we take a look at how to control a device's cameras through the MoSync Camera C API. With the Camera C API you can discover the number of cameras a device supports, set properties like zoom and image format, embed previews in your application, and, of course, take a picture.

  • The Capture C API

    The MoSync Capture C API provides a set of simple C-level functions for accessing the default camera interface on the device and providing the user with a simple interface without you needing to set up a complete user interface in your application. (This API is also used under-the-hood by the Wormhole JavaScript Library's Capture API.)

  • The Database C API

    The MoSync Database API provides a set of syscall functions that enable you to create and access databases from your C/C++ code using the SQL query language. The Database API makes use of the SQLite database manager.

  • The Device Fonts C API

    The Device Font C API provides a set of syscall functions that create and manage font handles. The font handles behave like any other MAHandle object and can be used either in the context of maDrawTextW or NativeUI as needed by the application (Note that MAUI does not support this font system). 

  • The Facebook C++ Library

    The MoSync Facebook C++ Library implements most of the Facebook Graph C API. Here we describe how to connect to Facebook through the Facebook library, retrieve information about them, post links, vidoes and other object types, create new albums, and a whole host of other cool operations.

  • The MAFS C++ Library

    MAFS is a reimplementation of the Standard C File I/O routines. It operates on either a binary image attached as a resource or using local stores for permanent storage. The binary image is actually a virtual filesystem generated using our tool Bundle.

  • The NativeUI C++ Library

    The MoSync NativeUI C++ Library is built on our Widget C API. It provides classes and functions for high-level control of native user-interface elements.

  • The Notification Library and API

    The MoSync Notifications Library provides a set of C++ classes and methods for handling both push notifications (coming from a service provider) and local notifications (originating from the device itself.) The Library is built on top of the MoSync Notifications API which provides a comprehensive set of C syscall functions.

  • The Sound C API

    In many games and applications you will want to play a sound. This may be backing music in a game, sound effects or alerts which require user input. The MoSync Sound C API to help you do that.

  • The Testify Test Framework

    MoSync's test framework, Testify, simplifies the writing of complex test cases. You can use it to test several methods in a class, or just to write a single test for one function. There is not much more you need to do than write your tests (unfortunately it can't do that part for you) and press Run.

  • Using Connection Sockets

    Here we take a look at how to use the MAUtil's Connection API to communicate over sockets using TCP. We will illustrate how to use them by making a simple FTP client.

  • Using MAUtil Set, Map, HashMap

    The MAUtil classes Set, Map and HashMap provide generic containers similar to std::set, map and unordered_map in the STL or Java's Set, Map and Hashtable. They provide many of the same familiar operations. Here we describe examples for Set, Map, and HashMap:

  • Using MAUtil Vector

    The MAUtil::Vector class provides a generic, dynamically resizeable container similar to std::vector in the STL, Java's Vector or a .NET List. It provides many of the same familiar operations. 

  • Using Placeholders and Handles

    In MoSync, you can use handles to refer to data objects, such as binary data, images, audio data, text data and other resources. In this guide we take a look at placeholders — a type of handle that is used to refer to dynamically created resource im memory, and at the syscall functions that manage them.

  • Using Resources in a Project

    This tutorial provides an introduction to adding resources, such as images and sounds, to a MoSync application. These external files need to be added into the project, so that they can be packaged with your code and deployed to the device.

  • Using the MAP Library

    The Mosync MAP library is a standard library that provides a MapWidget for displaying geographical maps, sometimes called slippy or panning maps, consisting of tiles provided by a map source. This guide introduces the basics of the MAP library and shows you how to create map applications from scratch.

  • Working with Fonts in MAUI

    The MAUI::Font class draws text using bitmap fonts defined in a mof-file. In this guide we show how to convert a bitmap font to a mof-file, and how to add the file as a resource to a MoSync project. We then create a MAUI::Font instance and draw some text with it.

  • Working with MoSync Libraries

    MoSync's libraries provide you with thousands of pre-written classes and functions that you can use within your application. Here we show how to connect to the libraries from your applications, and give you a brief overview of each of the main libraries.

  • Working with OpenGL ES

    OpenGL ES 2.0 is the latest standard for accessing the graphics hardware on embedded devices (in our case Android and iOS). It is heavily based on the concept of shader programs, written using the C-like language GLSL.

Example Applications

  • 3DLines

    3dLines demonstrates basic graphics and key input handling.

  • AccelerometerOpenGLES

    This example application makes use of the MoSync Sensor API and OpenGL API to graphically display the orientation of the device.

  • AdvGraphics

    AdvGraphics tests advanced graphics on the phone and keyboard input.

  • BluetoothClient

    This example application acts as a Bluetooth client. It is designed to work with our BluetoothServer example application.

  • BluetoothServer

    This application acts as a Bluetooth server. It is designed to work with our BluetoothClient example application.

  • CameraDemo

    CameraDemo is a simple C++ application built with the MoSync SDK that demonstrates how to control a device's camera. It makes use of the MoSync Widget C API.

  • Connection

    This example application checks the ability of the application and device to connect to the internet.

  • DatabaseTest

    This simple example application demonstrates how to use the MoSync Database API. This example works on all platforms supported by the API (see Feature/Platfom Support).

  • Debugging

    This example application uses the debug logging and user panic functions in MoSync. Note: The purpose is to stress the system, and create an error. There is no output to screen.

  • DeviceFonts

    This example application demonstrates how to count, load, and manage device fonts for text drawing using maDrawText and maDrawTextW and the Device Fonts API.

  • DeviceFontsNativeUI

    This example application demonstrates how to count, load, and manage a device fonts for your NativeUI applications.

  • FacebookDemo

    This example application demonstrates how to log on to Facebook from your application, how to retrieve JSON information, and how to manage posts (publish and delete posts). This application makes use of the MoSync C++ Facebook Library, C++ NativeUI Library, and C Widget API.

  • GLMoblet_OpenGLES1

    This example application demonstrates how to use OpenGL ES 1.1 to control a device's graphics hardware.

  • GLMoblet_OpenGLES2

    This example application demonstrates how to use OpenGL ES 2.0 to control a device's graphics hardware.

  • Graphun

    Graphun is a 3d graph visualizer built with MoSync. It evaluates a custom expression for every point on a grid and displays the result. This advanced application makes extensive use of NativeUI, and it uses an OpenGL view to display the graphs.

  • HelloMap

    HelloMap is a simple application that displays a slippy (i.e. panning) map.

  • HelloMAUI

    HelloMAUI is a well-commented example application for beginners. It consists of a very simple graphical user interface application that uses the MAUI library and Moblet framework. It illustrates how to create MAUI screens, and how to position and control widgets.

  • HelloMoblet

    HelloMoblet is a well-commented example application for beginners. It demonstrates how to use MoSync's Moblet framework to wrap your application to ensure timely response to key events.

  • HelloNativeUI

    HelloNativeUI is a well-commented example application for beginners. It consists of a very simple graphical user interface application that uses the NativeUI library and Moblet framework. It illustrates how to create NativeUI screens, and how to position widgets and handle events.

  • HelloOpenGLES

    HelloOpenGLES is a well-commented example application for beginners. It demonstrates how to use OpenGL for Embedded Systems from your MoSync Application.

  • HelloWorld

    HelloWorld is a well-commented example for beginners of a very simple MoSync application that uses the Moblet framework. The application demonstrates how to structure the simplest possible application that responds to key events.

  • Location

    This application tests the on-board GPS functionality of the phone, via the MoSync Location API.

  • MapDemo

    The MapDemo application displays slippy maps and makes use of the MAUI library to provide a simple menu system. The menu system enables the user to switch between map sources and is easy to extend with your own code.

  • MAStx

    Tests the console, heap management and memory allocation on the device.

  • MAUIEx

    This application demonstrates the variety of widgets available in the MAUI library and how to use the ListBox and Layout widgets to arrange widgets on a screen.

  • MoSketch

    This application demonstrates simple key input, graphics output, and the permanent storage option.

  • MoSound

    This example application hows how to use MoSync's Sound C API. The example demonstrates how to play and loop a sound once.

  • MoTooth

    This example application demonstrates how to scan for Bluetooth devices and services, store the results in a database, display a list of services, and connects to one of them.

  • MoTris

    Motris is a variation of the old classic game with a similar name.

  • MultiTouch

    This simple application shows how to handle multitouch events so that your applications can react to pinches, swipes and rotatation. This application is based on the MoSync Moblet framework.

  • NativeUIDemo

    This example application demonstrates many of the important features of MoSync's NativeUI Library. The library provides a set of C++ classes for handling native user interface components (buttons, toolbars, list boxes, etc.). Under the hood, the library makes use of the C functions in MoSync's Widget API. In the latest version of this example we also demonstrate banner ads.

  • OtaLoad

    OtaLoad demonstrates network connections, the downloading of an application "over-the-air", and the ability of one MoSync application to run another.

  • PIMExample

    This example application demonstrates how to add, modify and remove a new contact from an address book and how to read contacts from address book.

  • QuakeMDL

    This application either renders a Quake 1 model or, in benchmark mode, measures the raw speed of the target device's CPU. This application is useful for comparing performance across devices.

  • ResourceTest

    ResourceTest is a simple application for all platforms that demonstrates how to use the Resource Compiler and how to handle the resource loading/unloading.

  • RockPaperScissors

    This application demonstrates the use of NativeUI screens and widgets to play the traditional game Rock-Paper-Scissors.

  • ScreenOrientation

    This is a well-commented example application for beginners. It demonstrates how to detect and respond to changes in screen orientation, and also how to set the orientation mode on platforms that support it. This application is based on the MoSync Moblet framework.

  • SensorTest

    SensorTest is a simple application that demonstrates how to use the functions of the MoSync Sensor API to control a device's sensors, and to receive current measurements.

  • Simple

    This example application catches key events and displays the keycodes of pressed keys.

  • Soap

    This application demonstrates connecting to a Web Service using SOAP. It contains a class called SoapRequest which formats an easily modifiable XML Soap request, and a Moblet to test the SOAP communication using a currency converter as an example.

  • Stylus

    Stylus is a simple drawing program, where you draw with your mouse/stylus.

  • Timer

    This program tests simple graphics on the phone, catching a key event and adding some action.

  • Unit Test

    This application provides a battery of tests to help you check the capabilities and limitations of a mobile device.

  • VideoNativeUIExample

    This example application makes use of the MoSync NativeUI Library and demonstrates how to use the VideoView widget to embed video in your application.

  • WikiSearchNativeUI

    This example application searches Wikipedia, based on user input and selected categories. It makes use of functions in the MoSync Widget API.

IDE User Guides

  • Creating Projects from Templates

    This guide shows you how to create a new application project in the MoSync IDE and describes the project templates that are available to you. It also introduces the concepts of projects and workspaces. We have templates for various types of C/C++ projects, and templates for hybrid HTML/Javascript/C/C++ projects.

  • Using the Debugger

    The MoSync SDK includes a powerful debugger that makes it easy to step through your code and get an overview of the state of your program as each statement executes.

MoSync Extension Guides

  • Coding Conventions

    These coding conventions are guidelines for developers creating MoSync code. These conventions are largely inspired by and derived from existing ones in well-known programming environments such as Java and SDL. As such, they shouldn't come across as exotic to any moderately experienced programmer.

  • Writing Extensions for MoSync

    We encourage everyone to help us develop MoSync, and writing new extensions for MoSync is probably the most common thing you will want to do. In this topic we introduce you to some important core concepts that you need to understand and lead you step-by-step through creating an API extension.

Screencasts

  • HelloWorld Screencast

    This screencast shows how to write a simple C++ program using the Moblet template. The program sets the background colour, draws text "Hello World", updates the screen, and handles a key press event.

Tutorials

  • Creating New Fonts in MAUI

    The MAUI user interface components use bitmap fonts in its own format. These files are converted from a specific, but common, format for bitmap fonts. The MoSync download comes supplied with a freeware tool called BMFont for creating bitmap fonts from the fonts installed in Windows. MoSync developers can use BMFont to create their own fonts for use in their applications.

  • Creating New MAUI Screens

    Screens are the skeleton of your application. Screens provide the navigation and structure you will want. You can create screens with their widgets at design time, when you are writing your code, or you can interpret some data to create screens at runtime. We’ll be looking at both of these in this tutorial.

  • GUI-Based Applications with MAUI

    Using the MAUI library helps you develop powerful graphical user interface applications. You get access to a variety of ready-made user interface widgets and you can register different types of listeners with the widgets, thus responding to higher-level events.

  • Processing XML

    If you are writing cross-platform mobile apps in the MoSync® SDK, you will probably want at some point to connect to the Internet to get data. Typically, this data will be in XML or in JSON format. If you are getting XML data, the MoSync SDK has a built in XML parser (MTXml) you can use to parse it.

  • Using Data Stores

    There are several ways to save or read data from a mobile device. Reading and writing to the Internet can be done with Connection classes, but can be labourious without specific helper classes. The simplest way of saving your data is with a MoSync store. This tutorial looks at creating stores, writing to them and reading them.

  • Using MAUI Layouts

    Layouts format your widgets on screen. They provide a grid into which all of your widgets can be aligned. Almost every screen you’ll create will have a Layout widget on it, and whilst they can’t do everything you can imagine, they can help you create some attractive and useful screens.