I am attempting to use Excel VBA\'s ability to access and use functions from DLL files.
example:
Private Declare Function funcName Lib _
\"
I'm going to post this in a solution, as it doesn't fit in an comment.
The "inconsistent dll linkage" warning: I copied your exact code from the question as it is at this point (it might change in the future), and placed it in a newly created VStudio 2015 project:
The project compiled with no warnings, if I define MATHLIBRARY_EXPORTS either:
#define MATHLIBRARY_EXPORTS
(before #include "MathLibrary.h"
)The only thing that I can imagine for you to still get the warning when building yours, is because you are defining the macro for the wrong configuration.
Example: you are building your project for Debug - x86, but you define the macro for Release - x86 (or Debug - x64).
You must check (it would be better select All Platfroms and All Configurations, and only define the macro once) that build configurations and settings configurations match, like in the image below:
But anyway, this warning is benign, the .dll is still built, and the symbols exported.
Going further, in your VBA module you declare the function name Add (plain). Based on the error message:
Can't find DLL entry point Add in "path\file.dll"
as I specified on one of my comments, I don't think that Excel is able to import C++ style exports because of [MS.Docs]: Decorated Names (C++ name mangling). While it searches for Add, your .dll exports the following symbols as shown in the (Dependency Walker) image below (you can play with the highlighted button and see how Dependency Walker is able to demangle those names):
Those (gibberish) names you should import from Excel, but I doubt that's possible. As a workaround you could either:
[SO]: Linker error when calling a C function from C++ code in different VS2010 project (@CristiFati's answer) contains all the details (pay attention on extern "C"
: [MS.Docs]: extern (C++)).