我正在尝试从通过 C++ 生成的 dll 运行 Excel 中的函数。
我已按照Microsoft DLL 创建概述中的步骤操作,并成功使 DLL/客户端示例正常工作。我还发现Excel 中的 Access DLL 文章很有帮助。
最终我想做的只是计算一个数字的平方,一旦我完成了这个工作,我就可以向前迈进。挂起的是我的函数正在接收的参数。
正如您在下面看到的,我正在使用一些 txt 文件输出来帮助调试该过程,我觉得我已经很接近了。
这是我的 MathLibrary.h:
// MathLibrary.h - Contains declarations of math functions
#pragma once
#ifdef MATHLIBRARY_EXPORTS
#define MATHLIBRARY_API __declspec(dllexport)
#else
#define MATHLIBRARY_API __declspec(dllimport)
#endif
extern "C" MATHLIBRARY_API double get_var(double *my_var);
Run Code Online (Sandbox Code Playgroud)
这是我的 MathLibrary.cpp ,其中包含目标函数“get_var”
// MathLibrary.cpp : Defines the exported functions for the DLL.
#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
#include <utility>
#include <limits.h>
#include "MathLibrary.h" …Run Code Online (Sandbox Code Playgroud)