BIQ
Today’s impossible, will be tomorrow’s reality. https://think-biq.com

4 Followers
·
Follow

Image for post
Image for post
Safety first, everyone.

Intro

While intergrating native platform C APIs (e.g. on windows) into a third-party C++ application, I found myself having to make sure that query functions, that allocate and fill results of different data types, are called with the right paramters. And the inquired data is also properly disposed of after the call. This, and the fact that saftey is on the forefront of the collective unconcious, served as the inspiration for this post and the publishing of a small demo, highlighting the architecture proposed in this article. Hope you enjoy reading.

Setup

API example

The goal was, to make the abstraction able to select the appropriate data for the query call on the basis of a type indicated by an enum value. The desired usage of the abstraction should look like the…


Image for post
Image for post
Just imagine she is searching for the right strings.

Intro

There are things, that come up time and time again. One of those things is creating a string version of Enum values in Unreal Engine. For this and other cases, we started to condense some of our utility and helper functions into a module. This module can then be used as part of a plugin, or as a standalone game module. In this article, I want to highlight our approach for to stringify enum values.

Setup

API Example

Imagine we want to log the value of an enum type called EWlanNotificationMSM. The API would look like this.

Now press button ‘Make implementation plz!’

Let’s make this happen. …


Image for post
Image for post
Makes sense to show something Apple related here, right.

Intro

Going directly to source is sometimes the right move. On macOS that would be the core libraries using Objective-C. In this example, we use CoreWLAN to ask for information on the current wlan interface connection. You can find the complete source on github.

Setup

Structure

We have a makefile at project root level, organise our sourcefiles in a directory called src and will produce binaries in a directory called bin.

Making our lives easier

Let’s start by creating a makefile, which lets us manage building the project.

WlanInfo.make

In the make target build, the first step is to create a dynamic library called libwlaninfo via the CXX compiler, which we have specified as clang. The -stdlib=libc++ flag ensures that the compiler links against libc++ (heavily favoured by Apple) and -std=c++11 tells the compiler to use the c++11 standard. Next we declare this operation to produce a dynamic library by specifying -shared. To get access to Apple’s core library, we have to link the appropriate libraries, which in our case is Foundation and CoreWLAN. The -fpic ensures that the library has relative address management. Finally we specify the Objective-C++ source file (indicated by the .mm extension) and tell the compile to put the output file in the bin directory. The next step is to compile our program entry (via the main function) contained in Main.cpp, …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store