vba 找不到DLL入口点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13980912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 18:55:14  来源:igfitidea点击:

Can't find DLL entry point

c++vbadllentry-point

提问by John Smith

I have been trying to call a DLL function in my VBA project but I keep getting this error message:

我一直试图在我的 VBA 项目中调用一个 DLL 函数,但我不断收到此错误消息:

Run-time error '453': Can't find DLL entry point "CheckStatus" in "Power.dll"

Run-time error '453': Can't find DLL entry point "CheckStatus" in "Power.dll"

Here is the definition for the DLL in the C++ file:

这是 C++ 文件中 DLL 的定义:

#define CLASS_DECLSPEC extern "C" __declspec(dllexport)

#define CLASS_DECLSPEC extern "C" __declspec(dllexport)

CLASS_DECLSPEC int __stdcall CheckStatus();

CLASS_DECLSPEC int __stdcall CheckStatus();

And here is how I'm trying to declare it and call it in VBA:

这是我尝试声明它并在 VBA 中调用它的方式:

Public Declare Function CheckStatus Lib "Power.DLL" () As Long

Dim test As Long
test = CheckStatus

And then when I run it received the aforementioned error message.

然后当我运行它时收到上述错误消息。

Does anyone know how to fix this? Thanks.

有谁知道如何解决这一问题?谢谢。

采纳答案by SeanC

using thisMSDN article, I would try this method of declaring the function:

使用这篇MSDN 文章,我会尝试这种声明函数的方法:

Public Declare Function CheckStatus Lib "Power.DLL" Alias "_CheckStatus@0" () As Long

回答by Dani

This has to do with name mangling (even with extern "C").
Look at what export is really in the DLL, a guess would be either _CheckStatusor _CheckStatus@0.
To force the name to be as-is, make a .deffile in your project with the content:

这与名称修改(即使是extern "C")有关。
看看 DLL 中真正的导出是什么,猜测是_CheckStatus_CheckStatus@0.
要强制名称保持原样,请.def在您的项目中创建一个包含以下内容的文件:

EXPORTS
    CheckStatus=CheckStatus