Excel VBA, no se puede encontrar el punto de entrada de DLL desde un archivo DLL
Estoy intentando usar la capacidad de Excel VBA para acceder y usar funciones de archivos DLL.
ejemplo:
Private Declare Function funcName Lib _
"<filePath\File.dll>" _
(ByRef a As Double, ByRef b As Double) As Double
Siguiendo las instrucciones deTutorial de Mircosoft sobre cómo crear un archivo DLL, lleva a 3 advertencias (C4273) cuando intento construir el proyecto, para las 3 funciones declaradas:
'MathLibrary::Functions::Add': inconsistent dll linkage,
'MathLibrary::Functions::Multiply': inconsistent dll linkage,
'MathLibrary::Functions::AddMultiply': inconsistent dll linkage
Cuando el VBA en Excel intenta acceder al archivo .dll creado desde este tutorial, produce un error de tiempo de ejecución (453): 'No se puede encontrar el punto de entrada de DLL Agregue "path \ file.dll".
Soy un novato cuando se trata del lenguaje C \ C ++. He pasado más de 6 horas de:
tratando de hacer ajustes al tutorial de vainillaempezar de nuevobuscar ayuda en Google y problemas similareshaciendo ajustes a las declaraciones dentro de VBAY sin embargo, me siento más lejos de una solución.
Estoy ejecutando Excel de 32 bits en Windows de 64 bits.
Cualquier ayuda sería muy apreciada :)
Editar
Archivos de código (según lo solicitado):
MathLibrary.cpp
// 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);
}
}
MathLibrary.h
// 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);
};
}
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
// 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 <SDKDDKVer.h>
Módulo VBA
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