Skip to content

Companion projects for my book: C++ SoftwareInteroperability for Windows Programmers

Notifications You must be signed in to change notification settings

Adam-Gladstone/SoftwareInteroperability

Repository files navigation


logo

SoftwareInteroperability


Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Features
  4. Usage
  5. Roadmap
  6. License
  7. Contact
  8. Acknowledgments

About The Project

SoftwareInteroperability is a set of projects that form a companion to the book: C++ Software Interoperability for Windows Programmers: Connecting C++ code to C#, R and Python clients.

The purpose of the projects is to demonstrate how to connect a simple C++ codebase to

  • C# (and .NET) using C++/CLI
  • R using Rcpp
  • Python using raw python, boost.python and pybind11.

The C++ codebase consists of a small library of statistics functions (descriptive statistics, simple linear regression, and hypothesis testing). The projects demonstrate building wrapper components that expose the C++ functionality to other client languages.

Update

I have added two further projects:

These projects together provide an updated alternative to using the C++/CLI for connecting native C++ to .NET. This is developed in the projects StatsLib, StatsCLR, and StatsClient. The StatsExcel project also makes use of the .NET wrapper component but from an Excel AddIn. The new projects use the same common codebase but create a Windows Runtime Component wrapper around the native C++ library. This is then consumed in a C# desktop application written with WinUI 3.0.

(back to top)

Projects

A brief description of each of the projects follows:

  • Common contains two subdirectories: \include and \source. These contain the common header and source files that form the core of the C++ statistics library.
  • Data contains a number of small datasets that we use at various points for testing.
  • StatsATLCOM is a side-project that illustrates an alternative approach to connecting C++ to .NET, using COM.
  • StatsCLR.UnitTests is a C# unit test library that tests the basic statistics functionality from .NET.
  • StatsCLR is a C++/CLI wrapper. This component connects the C++ static library (StatsLib) to C# (and .NET).
  • StatsClient is a basic C# console application that exercises the functionality from the statistics library via the StatsCLR wrapper component with a minimal user interface.
  • StatsConsole is a Windows console application. This application demonstrates the basic functionality of the statistics library with a minimal user interface.
  • StatsConsoleCB is a Windows console application project using CodeBlocks. This is useful to debug C++ code using gdb on Windows.
  • StatsDll is a dynamic-link library version of the statistics library.
  • StatsExcel is a C# library project. This component connects Excel to the StatsCLR wrapper component and allows Excel to use the functionality available in the statistics library.
  • StatsLib is a static link library version of the statistics library. Both this and the previous component share the same C++ source code.
  • StatsLibCB is the CodeBlocks project that we use for building the R/RStudio ABI compatible static library.
  • StatsLibCM is a CMake equivalent of the StatsLibCB project. It allows building the library from Visual Studio in place of CodeBlocks.
  • StatsLibTest is a Windows console application. We use this specifically as a unit-testing application based on GoogleTest.
  • StatsPython is a Visual Studio Code Python project containing a number of scripts that use the statistics library functionality.
  • StatsPythonBoost is a Boost.Python wrapper. This component connects C++ code to Python.
  • StatsPythonPyBind is a PyBind wrapper. This component connects C++ code to Python.
  • StatsPythonRaw is a CPython wrapper. This component connects C++ code to Python. The reason for having three components that do essentially the same thing is to cover different approaches to connecting C++ to Python.
  • StatsR is the Rcpp wrapper, built using Rtools via RStudio.
  • StatsViewer is a Windows MFC application. This application is used to demonstrate using the functionality available in the statistics library in a GUI application.

The following projects build and distribute a windows runtime component: StatisticsLibraryWRC

  • StatisticsLibrary
  • StatisticsLibraryWRC
  • StatisticsLibraryProjection

This project is described here StatisticsLibrary

The following projects consume the StatisticsLibraryWRC component

  • StatisticsConsole
  • StatisticsViewerWinUI

This project is described here StatisticsViewer

(back to top)

Built With

  • Visual Studio 2019
  • C++17
  • Boost 1.81

(back to top)

Getting Started

The project can be downloaded from the GitHub repository in the usual way.

Prerequisites

Boost 1.81

The solution makes use of the following packages

  • Accord 3.8.0
  • Accord.Controls 3.8.0
  • Accord.IO 3.8.0
  • Accord.MachineLearning 3.8.0
  • Accord.Math 3.8.0
  • Accord.Statistics 3.8.0
  • CommunityToolkit.Mvvm 8.2.1
  • CommunityToolkit.UinUI.UI.Controls.DataGrid 7.1.2
  • Excel-DNA 1.6.0
  • ExcelDna.AddIn 1.6.0
  • ExcelDna.Integration 1.6.0
  • Microsoft.Extensions.DependencyInjection 7.0.0
  • Microsoft.googletest.v140.windesktop.msvcstl.rt-dyn 1.8.1.7
  • Microsoft.NETCore.UniversalWindowsPlatform 6.2.14
  • Microsoft.Windows.CppWinRT 2.0.230706.1
  • Microsoft.Windows.CsWinRT 2.0.3
  • Microsoft.Windows.SDK.BuildTools 10.0.25188-preview
  • Microsoft.WindowsAppSDK 1.4.231008000
  • MSTest.TestAdapter 3.0.2
  • MSTest.TestFramework 3.0.2
  • SharpZipLib 1.4.2
  • System.Buffers 4.5.1
  • System.Memory 4.5.5
  • System.Numerics.Vectors 4.5.0
  • System.Runtime.CompilerServices.Unsafe 6.0.0
  • System.Threading.Tasks.Extensions 4.5.4
  • WinUIEx 2.3.1
  • ZedGraph 5.1.7

Additionally, for developing the R package, we use R 4.3.1, rtools 4.3 and RStudio.

For the python development, we use Python 3.9.

Installation

There are no specific installation requirements.

(back to top)

Features

The wrapper components make use of:

  • C++/CLI for connecting to C# (.NET).
  • Rcpp for connecting to R.
  • Boost.Python and PyBind for connecting to Python.
  • WinRT/C++ for connecting a C# WinUI3.0 desktop application to a C++ static library.

(back to top)

Usage

(back to top)

Roadmap

Future directions:

  • Add Changelog

See the open issues for a full list of proposed features (and known issues).

(back to top)

License

Distributed under the GPL-3.0 License. See LICENSE.md for more information.

(back to top)

Contact

Adam Gladstone - (https://www.linkedin.com/in/adam-gladstone-b6458b156/)

Project Link: SoftwareInteroperability

(back to top)

Acknowledgments

Helpful resources

(back to top)

Issues GPL-3 License LinkedIn