Wrapping C++ objects in C

Introduction Using C functions from C++ is very easy but going the other way isn’t. However, it can be done with a little ingenuity. Really, this isn’t as crazy as it sounds. I’ll use a simple adder for the object. It takes an integer as a starting value and has two functions for adding and getting the current value. This could be expanded later into a complex object for mathematical operations but that’s really not necessary right now....

August 18, 2017 · John

s2n Memory Hardening Analysis

Recently Amazon.com introduced s2n as a new TLS implementation. The idea is to have a small and simplified TLS library. Looking at it I noticed it’s very Linux centric. It cannot be compiled on Windows. There are patches to make it work on OS X. There is a report that it works on FreeBSD but I didn’t look closely at it to determine if patches were necessary. Amazon is positioning s2n as a replacement for OpenSSL but it can’t work in nearly as many places as OpenSSl....

July 2, 2015 · John

Effective Threading Using Qt

Effective Threading Using Qt Introduction Over the years using Qt I’ve seen a lot of difficulty using threads with Qt. Threads can be difficult and Qt provides a lot of ways to make threads easy to work with. Still basic / direct / low level threading (I’ll just call this basic) is often seen as difficult with Qt. It really isn’t though. There are three main ways I’ve seen people handle basic threading in their Qt applications....

May 2, 2015 · John

Extending an Application with Lua Plugins

Introduction A very common use of the Lua language (which is a very versatile) is using Lua to extend an application via plugins. Many popular games use Lua for this very purpose. Adding a plugin framework to an existing application is trivial with Lua. Also, Lua provides a very capable and easy to use language for writing plugins. To demonstrate using Lua for plugins I’m going to make very basic text editor and allow features to be added via Lua scripts (user installable plugins)....

August 16, 2014 · John

Calling Functions in EXE From Plugins in Windows

When writing an application that uses plugins sometimes it’s necessary to have the plugin call functions from the application. This is fairly easy to do on pretty much any OS but on Windows it requires the plugin to link to the application. Sometimes explicit linking is unreasonable. One situation where you don’t want the plugin linking to the application is when the plugin will be used by multiple applications. Windows allows for runtime resolution of exported functions (GetProcAddress) and this is typically used to access functions in a loaded DLL....

July 15, 2012 · John

Wrapping a C library in COM/ActiveX

Introduction Not very long ago my boss walked up to my desk, put a pile of books down beside me and said “Not it”. The books were all related to COM programming. The project he gave me was to create a COM wrapper for an existing C library we had developed. Windows is not my primary development platform, so I was tasked with learning COM and then writing a wrapper around our C library....

April 8, 2012 · John

Retrieve Formatting Set by QSyntaxHighlighter

I have been working on adding inline spell check to Sigil recently and ran into a quirk on Qt that isn’t immediately obvious. I ended up having to look though the Qt source code to understand exactly what was happening. When dealing with a QPlainTextEdit you can get the QTextCursor and use the charFormat() function to retrieve the QTextCharFormat for the character before the cursor. This does not work when the formatting is set by a QSyntaxHighlighter!...

October 29, 2011 · John

Qt Remove Directory and Its Contents

When dealing with directories, Qt has a large number of functions to make manipulating them easy. However, it does not include a way to delete a non-empty directory. This little omission is easily solved. Following is a recursive function that will delete a directory along with all of it’s contents. This will delete depth first. Meaning it will recurse into sub-directories and only start deleting once the directory has no sub-directories....

June 8, 2010 · John

C++ Derived Classes and Object Destruction

While working on lebookread I realized that the destructor for my reader classes would never be called. lebook read has a base class (FormatReader) that exports all of the necessary functionality for use by applications using the library. All of the readers are a subclass of FormatReader. The library will find the appropriate reader for the specified ebook create a reader object and return it as a FormatReader pointer. When you are dealing with a pointer p of type base that points to an object of type derived you need to take special care....

May 29, 2010 · John

lebookread

I have been taking a short break from blogging again. The pressure at work has only increased and is eating into a lot of my time. I haven’t been motivated to work on personal projects because well they are work. However, this has recently changed a bit. I’ve started a Qt based library for reading ebooks in a generic manner. It is called lebookread! It is it’s early stages. So far I have it supporting epub, palmdoc pdb, ztxt pdb, tcr, and rb files....

May 16, 2010 · John