【发布时间】:2018-09-17 15:29:43
【问题描述】:
我对 C-plus-plus 很陌生,并试图用它来为 excel 创建用户定义的函数。我在 Cpp 中编写了一个非常简单的测试函数,它只是将两个参数加在一起(Excel 单元格引用)。
我在 Visual Studio 2013 中使用相同的 *.cpp 和 *.def 文件编译了一个 32 位 DLL 和一个单独的 64 位 DLL 项目。
当我在 32 位 Excel 安装上运行 32 位 DLL 时,新的 excel 函数工作正常(例如:5 + 10 = 15)。
当我在 64 位 Excel 安装上运行 64 位 DLL 时,单元格中出现 #VALUE 错误。
任何人都可以看到我在使用 64 位 DLL 时出现的明显错误吗?谢谢!
***** VBA (32-bit) *****
Declare Function ExPlus Lib _
"C:\AKH-VSWS\Ex-Plus32\Debug\Ex-Plus32.dll" _
(ByVal a As Double, _
ByVal b As Double) As Double
计算机 1:Windows 7(64 位)、Office 2016(32 位)、Visual Studio 2013
***** VBA (64-bit) *****
Declare PtrSafe Function ExPlus Lib _
"C:\AKH-VSWS\Ex-Plus64\x64\Debug\Ex-Plus64.dll" _
(ByVal a As Double, _
ByVal b As Double) As Double
计算机 2:Windows 7(64 位)、Office 2016(64 位)
Microsoft (R) COFF/PE Dumper Version 12.00.21005.1
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file c:\AKH-VSWS\Ex-Plus64\x64\Debug\Ex-Plus64.dll
PE signature found
File Type: DLL
FILE HEADER VALUES
8664 machine (x64)
7 number of sections
5AC930F1 time date stamp Sat Apr 07 16:58:25 2018
0 file pointer to symbol table
0 number of symbols
F0 size of optional header
2022 characteristics
Executable
Application can handle large (>2GB) addresses
DLL
【问题讨论】:
-
您不能使用 C++ 构建导出 COM 类型或 C 样式函数的 DLL 文件并使其在 32 位和 64 位环境中工作。
-
@ashleedawg,如果我正确阅读了您的评论,那么您是正确的。 DLL 不会在 voth 世界中工作。我有两个单独的 VStudio 项目。 1 编译一个 32 位的 DLL。和 1 编译一个单独的 64 位 DLL。 32 位按预期工作,但 64 位函数在 Excel 中返回错误。我不知道它是编译器错误还是 VBA 错误...建议?从哪里/如何开始调试?
标签: c++ excel visual-studio-2013 32bit-64bit vba