VBA找不到我的DLL,尽管硬编码位置。

问题描述:

我使用C ++创建一个简单的DLL,我可以使用从VBA代码。然而,虽然它在我的开发计算机上工作,当尝试访问不同的计算机上的DLL,VBA说明没有找到DLL文件,尽管硬编码的路径。

I am using C++ to create a simple DLL that I can use from VBA code. However, while it works on my development computer, when attempting to access the DLL on different computers, VBA states the DLL File was not found, despite hardcoding the path in.

我的DLL看起来像这样(使用Visual C ++ 2010 Express作为Win32 dll项目创建):

My DLL looks like this (created with Visual C++ 2010 Express as a Win32 dll project):

DEF文件:

LIBRARY "squareNumber"
EXPORTS
squareNumber


$ b b

Function.cpp:

Function.cpp:

double __stdcall squareNumber(double & x)
{
    return x*x;
}

VBA代码如下所示:

The VBA code looks like this:

Public Declare Function squareNumber Lib "C:\MySimpleDLL.dll" (ByRef number As Double) As Double

Sub test()
    MsgBox squareNumber(2)
End Sub

,我编码的dll错了,还是它的VBA的问题?

I am very new to C++ DLLs, did I code the dll wrong, or is it VBA's problem?

使用RegSvr32也会产生模块[dllpath]加载失败,确保二进制存储指定的路径或调试它检查二进制或依赖.DLL文件的问题。

Using RegSvr32 also yields "The module [dllpath] failed to load. Make sure the binary is stored at the specified path or debug it to check for problems with the binary or dependent .DLL files."

对开发计算机上存在的其他DLL没有依赖性,而是在目标计算机上。当操作系统加载你的DLL,但却找不到依赖的DLL,它报告相同的无法找到文件的错误,使你认为它找不到你的DLL,当它真的做到了。如果是这样,那么你需要分发这些额外的DLL或删除它们的依赖。

It sounds like your DLL has dependancies on other DLLs that exist on your development machine but not on the target machine. When the OS loads your DLL but then can't find the dependent DLLs, it reports the same "cannot find file" error, making you think it cannot find your DLL when it really did. If that is the case, then you need to either distribute those extra DLLs or remove the dependencies on them.