[英]Error accessing 64bit DLL function
我使用 Microsoft Visual Studio 2015 创建了一个 64 位 DLL 文件。Visual C --> Win32 项目。
squareMain.c 的代码如下:
long _stdcall square(long a)
{
return a*a;
}
Defile.def 的代码如下:
LIBRARY "square"
EXPORTS
squareforExl=square
我已经使用配置管理器设置平台和活动解决方案平台为 64 位 DLL 构建了 x64 的 DLL。
我必须通过 Excel vba7 访问这个 DLL 函数。 VBA中的函数如下:
Private Declare PtrSafe Function squareforExl Lib "C:\math.dll" (ByVal x As Long) As Long
Sub square()
Dim b As Long
b = 5
Dim c As Long
Debug.Print b
c = squareforExl(b)
Debug.Print "Square : " & c
End Sub
在尝试访问上面代码中的 DLL 函数 squareforExl() 时,它显示以下错误 msgBox:
Run time Error '53': File not Found :"C:\math.dll"
我曾尝试将文件放在不同的位置目录中,甚至在系统文件夹中。
我已经在 32 位版本的 Office 中成功编译并执行了 32 位 DLL。 我的问题是如何在 64 位版本的 Office 中访问 64 位 dll 的 DLL 函数?
请检查您的Office安装是64位安装还是32位安装。 这意味着,如果 VBA 编辑器在 VBA7 中,并不意味着 office 是 64 位。 看来,您在 64 位操作系统上安装了 32 位办公软件(即 2007 年以后的版本,即 VBA7)。 请在32位中创建DLL并在VBA中使用Ptrsafe(因为它是VBA7),错误将被取消。 对于 64 位操作系统上的 64 位 Office 安装,使用 Ptrsafe 调用 64 位 DLL 不会有任何问题。 我会同时使用 ie(1. 64bit office on 64bit os. 2. 32bit office with VBA7 on 64bit OS) 和工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.