1. <legend id='WkEgR'><style id='WkEgR'><dir id='WkEgR'><q id='WkEgR'></q></dir></style></legend>
    <tfoot id='WkEgR'></tfoot>
  2. <i id='WkEgR'><tr id='WkEgR'><dt id='WkEgR'><q id='WkEgR'><span id='WkEgR'><b id='WkEgR'><form id='WkEgR'><ins id='WkEgR'></ins><ul id='WkEgR'></ul><sub id='WkEgR'></sub></form><legend id='WkEgR'></legend><bdo id='WkEgR'><pre id='WkEgR'><center id='WkEgR'></center></pre></bdo></b><th id='WkEgR'></th></span></q></dt></tr></i><div id='WkEgR'><tfoot id='WkEgR'></tfoot><dl id='WkEgR'><fieldset id='WkEgR'></fieldset></dl></div>

    <small id='WkEgR'></small><noframes id='WkEgR'>

      • <bdo id='WkEgR'></bdo><ul id='WkEgR'></ul>

      Excel VBA,无法从 DLL 文件中找到 DLL 入口点

      Excel VBA, Can#39;t Find DLL Entry Point from a DLL file(Excel VBA,无法从 DLL 文件中找到 DLL 入口点)
        <bdo id='J0Trg'></bdo><ul id='J0Trg'></ul>
          <tbody id='J0Trg'></tbody>
        <legend id='J0Trg'><style id='J0Trg'><dir id='J0Trg'><q id='J0Trg'></q></dir></style></legend>
        <tfoot id='J0Trg'></tfoot>

          • <small id='J0Trg'></small><noframes id='J0Trg'>

            <i id='J0Trg'><tr id='J0Trg'><dt id='J0Trg'><q id='J0Trg'><span id='J0Trg'><b id='J0Trg'><form id='J0Trg'><ins id='J0Trg'></ins><ul id='J0Trg'></ul><sub id='J0Trg'></sub></form><legend id='J0Trg'></legend><bdo id='J0Trg'><pre id='J0Trg'><center id='J0Trg'></center></pre></bdo></b><th id='J0Trg'></th></span></q></dt></tr></i><div id='J0Trg'><tfoot id='J0Trg'></tfoot><dl id='J0Trg'><fieldset id='J0Trg'></fieldset></dl></div>

              • 本文介绍了Excel VBA,无法从 DLL 文件中找到 DLL 入口点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用 Excel VBA 的功能来访问和使用 DLL 文件中的函数.

                示例:

                私有声明函数funcName Lib _""_(ByRef a As Double, ByRef b As Double) As Double

                <小时>

                按照

                但无论如何,这个警告是良性的,.dll 仍然被构建,并且符号被导出.

                更进一步,在您的 VBA 模块中声明函数名称 Add(纯文本).基于错误消息:

                <块引用>

                在pathfile.dll"中找不到 DLL 入口点添加

                正如我在我的评论中指出的那样,我认为 Excel 无法导入 C++ 样式导出,因为

                您应该从 Excel 导入的那些(胡言乱语)名称,但我怀疑这是可能的.作为一种解决方法,您可以:

                • 删除 C++ 特性(类和命名空间)并定义和导出 3 个简单函数
                • 编写 3 个 C 函数(封装了 3 个方法),并导出函数而不是方法

                [SO]: 在不同的 VS2010 项目中从 C++ 代码调用 C 函数时出现链接器错误(@CristiFati 的回答) 包含所有细节(注意 extern "C": [MS.Docs]:extern (C++)).>

                I am attempting to use Excel VBA's ability to access and use functions from DLL files.

                example:

                Private Declare Function funcName Lib _
                "<filePathFile.dll>" _
                (ByRef a As Double, ByRef b As Double) As Double
                


                Following the instructions from Mircosoft's tutorial on how to create a DLL file, leads to 3 warnings (C4273) when I try to build the project, for the 3 functions declared:

                'MathLibrary::Functions::Add': inconsistent dll linkage,
                'MathLibrary::Functions::Multiply': inconsistent dll linkage,
                'MathLibrary::Functions::AddMultiply': inconsistent dll linkage
                

                When the VBA in Excel tries to access the created .dll file from this tutorial, it produces a runtime error (453): 'Can't find DLL entry point Add in "pathfile.dll".


                I am a novice when it comes to the CC++ language. I have spent over 6 hours of:

                • trying to make tweaks to the vanilla tutorial
                • starting over
                • googling for help, and similar issues
                • making tweaks to the statements within VBA

                And yet I feel further from a solution.

                I am running 32-bit Excel on 64-bit Windows.


                Any help would be much appreciated :)


                Edit

                Code Files (as requested):

                MathLibrary.cpp

                // MathLibrary.cpp : Defines the exported functions for the DLL application.
                // Compile by using: cl /EHsc /DMATHLIBRARY_EXPORTS /LD MathLibrary.cpp  
                
                #include "stdafx.h"  
                #include "MathLibrary.h"  
                
                namespace MathLibrary
                {
                    double Functions::Add(double a, double b)
                    {
                        return a + b;
                    }
                
                    double Functions::Multiply(double a, double b)
                    {
                        return a * b;
                    }
                
                    double Functions::AddMultiply(double a, double b)
                    {
                        return a + (a * b);
                    }
                }
                

                MathLibrary.h

                // MathLibrary.h - Contains declaration of Function class  
                #pragma once  
                
                #ifdef MATHLIBRARY_EXPORTS  
                #define MATHLIBRARY_API __declspec(dllexport)   
                #else  
                #define MATHLIBRARY_API __declspec(dllimport)   
                #endif  
                
                namespace MathLibrary
                {
                    // This class is exported from the MathLibrary.dll  
                    class Functions
                    {
                    public:
                        // Returns a + b  
                        static MATHLIBRARY_API double Add(double a, double b);
                
                        // Returns a * b  
                        static MATHLIBRARY_API double Multiply(double a, double b);
                
                        // Returns a + (a * b)  
                        static MATHLIBRARY_API double AddMultiply(double a, double b);
                    };
                }
                

                stdafx.h

                // stdafx.h : include file for standard system include files,
                // or project specific include files that are used frequently, but
                // are changed infrequently
                //
                
                #pragma once
                
                #include "targetver.h"
                
                #define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
                // Windows Header Files:
                #include <windows.h>
                
                // TODO: reference additional headers your program requires here
                

                targetver.h

                #pragma once
                
                // Including SDKDDKVer.h defines the highest available Windows platform.
                
                // If you wish to build your application for a previous Windows platform,
                //     include WinSDKVer.h and
                // set the _WIN32_WINNT macro to the platform you wish to support 
                //     before including SDKDDKVer.h.
                
                #include <SDKDDKVer.h>
                

                VBA Module

                Private Declare Function Add Lib _
                "c:<Path>MathLibrary.dll" _
                (ByRef a As Double, ByRef b As Double) As Double
                
                Sub useAddXL()
                    MsgBox Add(1, 2)
                End Sub
                

                解决方案

                I'm going to post this in a solution, as it doesn't fit in an comment.

                The "inconsistent dll linkage" warning: I copied your exact code from the question as it is at this point (it might change in the future), and placed it in a newly created VStudio 2015 project:

                • Configuration type: Dynamic Library (.dll)
                • Using precompiled headers (although, I usually don't do it)

                The project compiled with no warnings, if I define MATHLIBRARY_EXPORTS either:

                • In the MathLibrary.cpp file #define MATHLIBRARY_EXPORTS (before #include "MathLibrary.h")
                • As a project setting: adding it under Project Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions (next to other macros, separated by semicolons (;))

                The only thing that I can imagine for you to still get the warning when building yours, is because you are defining the macro for the wrong configuration.
                Example: you are building your project for Debug - x86, but you define the macro for Release - x86 (or Debug - x64).
                You must check (it would be better select All Platfroms and All Configurations, and only define the macro once) that build configurations and settings configurations match, like in the image below:

                But anyway, this warning is benign, the .dll is still built, and the symbols exported.

                Going further, in your VBA module you declare the function name Add (plain). Based on the error message:

                Can't find DLL entry point Add in "pathfile.dll"

                as I specified on one of my comments, I don't think that Excel is able to import C++ style exports because of [MS.Docs]: Decorated Names (C++ name mangling). While it searches for Add, your .dll exports the following symbols as shown in the (Dependency Walker) image below (you can play with the highlighted button and see how Dependency Walker is able to demangle those names):

                Those (gibberish) names you should import from Excel, but I doubt that's possible. As a workaround you could either:

                • Drop the C++ features (the class and the namespace) and define and export 3 simple functions
                • Write 3 C functions (wrappers over the 3 methods), and export the functions not the methods

                [SO]: Linker error when calling a C function from C++ code in different VS2010 project (@CristiFati's answer) contains all the details (pay attention on extern "C": [MS.Docs]: extern (C++)).

                这篇关于Excel VBA,无法从 DLL 文件中找到 DLL 入口点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                Delay Loading DLLs(延迟加载 DLL)
                Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                Loading a dll from a dll?(从 dll 加载 dll?)
                <i id='YzQUk'><tr id='YzQUk'><dt id='YzQUk'><q id='YzQUk'><span id='YzQUk'><b id='YzQUk'><form id='YzQUk'><ins id='YzQUk'></ins><ul id='YzQUk'></ul><sub id='YzQUk'></sub></form><legend id='YzQUk'></legend><bdo id='YzQUk'><pre id='YzQUk'><center id='YzQUk'></center></pre></bdo></b><th id='YzQUk'></th></span></q></dt></tr></i><div id='YzQUk'><tfoot id='YzQUk'></tfoot><dl id='YzQUk'><fieldset id='YzQUk'></fieldset></dl></div>
              • <small id='YzQUk'></small><noframes id='YzQUk'>

                    <tfoot id='YzQUk'></tfoot>
                      <legend id='YzQUk'><style id='YzQUk'><dir id='YzQUk'><q id='YzQUk'></q></dir></style></legend>

                          <bdo id='YzQUk'></bdo><ul id='YzQUk'></ul>

                            <tbody id='YzQUk'></tbody>