我写了一个简单的C++程序
源.cpp:
double __stdcall square(double& x)
{
return x*x;
}
定义.def:
LIBRARY "square"
EXPORTS
square
然后在我的 .xlsm 文件模块中,添加 module1 导入:
Declare PtrSafe Function square _
Lib "C:\Users\user\Documents\AthosCode\Marek Kolman Square\Square\Debug\square.dll" _
(ByRef x As Double) As Double
然后在 Sheet1 中,将 10
放入 A1,并将 =square(A1)
放入 B1。
错误提示:“公式中使用的值的数据类型错误”。
有什么问题,我该如何解决?
我的环境是
- Windows 7 64 位
- Visual Studio 2016 社区(所以它是 32 位)
- Excel 2016 64 位
回复评论,如果我把引用传递改成值传递,还是报错。
我将 Source.cpp 更改为
double __stdcall square(double x)
{
return x*x;
}
并将 module1 更改为
Declare PtrSafe Function square _
Lib "C:\Users\user\Documents\AthosCode\Marek Kolman Square\Square\Debug\square.dll" _
(ByVal x As Double) As Double
同样的错误。
最佳答案
由于架构的差异,无法load a 32-bit DLL in a 64-bit process反之亦然
有可能access 32-bit DLLs from 64-bit code但除非您有没有 64 位版本的遗留 DLL,否则您应该编译为 64 位项目。和 64-bit Office doesn't support 32-bit plugin at all所以你需要一个 64 位 DLL。
关于c++ - 链接 C++ 的 Excel 错误 : "A value used in the formula is of the wrong data type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39113813/