I am trying to use the features of Excel VBA to access and use functions from DLL files.
Example:
Private Declare Function funcName Lib _ "<filePath\File.dll>" _ (ByRef a As Double, ByRef b As Double) As Double
Following the instructions of the Mircosoft tutorial on how to create a DLL file, it leads to 3 warnings ( C4273 ) when I try to build a project for three declared functions:
'MathLibrary::Functions::Add': inconsistent dll linkage, 'MathLibrary::Functions::Multiply': inconsistent dll linkage, 'MathLibrary::Functions::AddMultiply': inconsistent dll linkage
When VBA in Excel tries to access the generated DLL file from this tutorial, it generates a runtime error ( 453 ): 'Cannot find the entry point of the DLL. Add to "path \ .dll file".
I start when it comes to C \ C ++. I spent more than 6 hours:
- trying to do tricks in a vanilla textbook.
- beginning with
- googling for reference and similar problems
- amending statements in VBA
And yet I feel farther from the decision.
I am running 32-bit Excel on 64-bit Windows.
Any help would be greatly appreciated :)
Edit
Code files (on request):
MathLibrary.cpp
// MathLibrary.cpp : Defines the exported functions for the DLL application. // Compile by using: cl /EHsc /DMATHLIBRARY_EXPORTS /LD MathLibrary.cpp
MathLibrary.h
// MathLibrary.h - Contains declaration of Function class
stdafx.h
// 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 <windows.h> // TODO: reference additional headers your program requires here
targetver.h
#pragma once
VBA module
Private Declare Function Add Lib _ "c:\<Path>\MathLibrary.dll" _ (ByRef a As Double, ByRef b As Double) As Double Sub useAddXL() MsgBox Add(1, 2) End Sub