Excel VBA, Can't Find DLL Entry Point from a DLL file
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:
Configuration type: Dynamic Library (.dll)
Using precompiled headers (although, I usually don't do it)
The project compiled with no warnings, if I define MATHLIBRARY_EXPORTS either:
In the MathLibrary.cpp file
#define MATHLIBRARY_EXPORTS
(before#include "MathLibrary.h"
)As a project setting: adding it under Project Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions (next to other macros, separated by semicolons (;))
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:
Drop the C++ features (the class and the namespace) and define and export 3 simple functions
Write 3 C functions (wrappers over the 3 methods), and export the functions not the methods
[SO]: Linker error when calling a C function from C++ code in different VS2010 project (@CristiFati's answer) contains all the details (pay attention at extern "C"
: [MS.Docs]: extern (C++)).
Need to fix this error: 'Can't find DLL entry point GetSystemInfo in kernel32'
It has been discovered that my client's security program named 'PROTECT' was blocking scripts inside our MS-Access front-end program files from accessing kernel32.dll. Thanks all for taking a shot at this.
Can't find DLL entry point
using this MSDN article, I would try this method of declaring the function:
Public Declare Function CheckStatus Lib "Power.DLL" Alias "_CheckStatus@0" () As Long
Related Topics
How to Handle Key Press Events in C++
Is There Any C/C++ Library to Connect with a Remote Ntp Server
When Extending a Padded Struct, Why Can't Extra Fields Be Placed in the Tail Padding
Two Phase Name Lookup for C++ Templates - Why
Detecting Simulated Keyboard/Mouse Input
Why Do Reference Type Members Cause Implicitly-Declared Copy Assignment Operator to Be Deleted
What's the Difference Between a Const Member Function and a Non-Const Member Function
Using Std:Fstream How to Deny Access (Read and Write) to the File
What Is the Use of 0-Length Array (Or Std::Array)
How Are Local and Global Variables Initialized by Default
C++11 "Overloaded Lambda" with Variadic Template and Variable Capture
Getting Big Random Numbers in C/C++
Diamond Inheritance Lowest Base Class Constructor
How to Use Cin.Fail() in C++ Properly
Why Is Std::Iterator Deprecated
Why Does Wide File-Stream in C++ Narrow Written Data by Default