Exporting C++ from dlls
This post will cover how to export functions from a windows dynamic-link library starting with the basics and then covering some more advanced examples. The first part of this explanation is very similar to this msdn article, so if you already know that you may want to skip ahead to the [Advanced Exporting]({{ page.url | prepend: site.baseurl }}#advanced-exporting) section.
Basic Exporting
So let's start with the basics, to export a function from a dll you need to inform the compiler which functions and classes you want to be accessible from the library. This can be done in multiple ways but the simplest is to use __declspec(dllexport)
to markup the functions or classes when declaring and __declspec(dllimport)
when using them.
// function declaration in library header
//
__declspec(dllexport) void function();
// function declaration in executable source
//
__declspec(dllimport) void function();