title: Excel VBA, Can't Find DLL Entry Point from a DLL file
body: <p>I am attempting to use Excel VBA's ability to access and use functions from DLL files.</p>
  
  <p>example:</p>
  
  <pre><code>Private Declare Function funcName Lib _
  "&lt;filePath\File.dll&gt;" _
  (ByRef a As Double, ByRef b As Double) As Double
  </code></pre>
  
  <hr>
  
  <p>Following the instructions from <a href="https://msdn.microsoft.com/en-CA/library/ms235636.aspx" rel="nofollow noreferrer">Mircosoft's tutorial</a> on how to create a DLL file, leads to 3 warnings (<a href="https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4273" rel="nofollow noreferrer">C4273</a>) when I try to build the project, for the 3 functions declared:</p>
  
  <pre><code>'MathLibrary::Functions::Add': inconsistent dll linkage,
  'MathLibrary::Functions::Multiply': inconsistent dll linkage,
  'MathLibrary::Functions::AddMultiply': inconsistent dll linkage
  </code></pre>
  
  <p>When the VBA in Excel tries to access the created .dll file from this tutorial, it produces a runtime error (<a href="https://msdn.microsoft.com/en-us/library/office/gg251579.aspx" rel="nofollow noreferrer">453</a>): 'Can't find DLL entry point Add in "path\file.dll".</p>
  
  <hr>
  
  <p>I am a novice when it comes to the C\C++ language.
  I have spent over 6 hours of:</p>
  
  <ul>
  <li>trying to make tweaks to the vanilla tutorial</li>
  <li>starting over</li>
  <li>googling for help, and similar issues</li>
  <li>making tweaks to the statements within VBA</li>
  </ul>
  
  <p>And yet I feel further from a solution.</p>
  
  <p>I am running 32-bit Excel on 64-bit Windows.</p>
  
  <hr>
  
  <p>Any help would be much appreciated :)</p>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>Code Files (as requested):</p>
  
  <p>MathLibrary.cpp</p>
  
  <pre><code>// MathLibrary.cpp : Defines the exported functions for the DLL application.
  // Compile by using: cl /EHsc /DMATHLIBRARY_EXPORTS /LD MathLibrary.cpp  
  
  #include "stdafx.h"  
  #include "MathLibrary.h"  
  
  namespace MathLibrary
  {
      double Functions::Add(double a, double b)
      {
          return a + b;
      }
  
      double Functions::Multiply(double a, double b)
      {
          return a * b;
      }
  
      double Functions::AddMultiply(double a, double b)
      {
          return a + (a * b);
      }
  }
  </code></pre>
  
  <p>MathLibrary.h</p>
  
  <pre><code>// MathLibrary.h - Contains declaration of Function class  
  #pragma once  
  
  #ifdef MATHLIBRARY_EXPORTS  
  #define MATHLIBRARY_API __declspec(dllexport)   
  #else  
  #define MATHLIBRARY_API __declspec(dllimport)   
  #endif  
  
  namespace MathLibrary
  {
      // This class is exported from the MathLibrary.dll  
      class Functions
      {
      public:
          // Returns a + b  
          static MATHLIBRARY_API double Add(double a, double b);
  
          // Returns a * b  
          static MATHLIBRARY_API double Multiply(double a, double b);
  
          // Returns a + (a * b)  
          static MATHLIBRARY_API double AddMultiply(double a, double b);
      };
  }
  </code></pre>
  
  <p>stdafx.h</p>
  
  <pre><code>// stdafx.h : include file for standard system include files,
  // or project specific include files that are used frequently, but
  // are changed infrequently
  //
  
  #pragma once
  
  #include "targetver.h"
  
  #define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
  // Windows Header Files:
  #include &lt;windows.h&gt;
  
  // TODO: reference additional headers your program requires here
  </code></pre>
  
  <p>targetver.h</p>
  
  <pre><code>#pragma once
  
  // Including SDKDDKVer.h defines the highest available Windows platform.
  
  // If you wish to build your application for a previous Windows platform,
  //     include WinSDKVer.h and
  // set the _WIN32_WINNT macro to the platform you wish to support 
  //     before including SDKDDKVer.h.
  
  #include &lt;SDKDDKVer.h&gt;
  </code></pre>
  
  <p>VBA Module</p>
  
  <pre><code>Private Declare Function Add Lib _
  "c:\&lt;Path&gt;\MathLibrary.dll" _
  (ByRef a As Double, ByRef b As Double) As Double
  
  Sub useAddXL()
      MsgBox Add(1, 2)
  End Sub
  </code></pre>