C# DLL 使用 DllExport : No entry point when called in VBA

标签 c# excel dll dllexport entrypointnotfoundexcept

为了避免要求为电子表格的所有用户注册 Dll,我尝试使用后期绑定(bind),这样用户就不需要添加对 Dll 的引用。

我已经使用 Visual Studio 在 C# 中创建了 Dll,尽管我已经包含了“using RGiesecke.DllExport;”并在函数上使用 DllExport 返回包含我需要在 VBA 中访问的函数的对象,我仍然收到错误“运行时错误‘453’:无法在 C 中找到 DLL 入口点 CreateDotNetObject :\temp\MyFunctions.dll."

DLL代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System.Data;
using System.Text.RegularExpressions;
using Microsoft.TeamFoundation.Client;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Collections;
using System.Collections.ObjectModel;
using System.Threading;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework;
using Microsoft.TeamFoundation.Common;
using Microsoft.VisualBasic;
using System.Diagnostics;
using RGiesecke.DllExport;

namespace MyFunctions
{
    public interface IMyFunctions
    {
        string GetWorkItemLinkList(string WIIDs);
    }

    [CLSCompliant(true), ComVisible(true), ClassInterface(ClassInterfaceType.AutoDual)]
    public class MyFunctions : IMyFunctions
    {
        TfsConfigurationServer server;
        WorkItemStore store;

        private void TFSconnect()
        {
        //Code to connect
        }

        [CLSCompliant(true), ComVisible(true), Description("GetWorkItemLink func")]
        public string GetWorkItemLink(int WIID)
        {
            TFSconnect();

        //Code to build return string "message"

            return message;
        }



        [CLSCompliant(true), ComVisible(true), Description("GetWorkItemLinkList func")]
        public string GetWorkItemLinkList(string WIIDs)
        {
            TFSconnect();

        //Code to build return string "returnStr"

            return returnStr;
        }


    }
    static class UnmanagedExports
    {
        [DllExport]
        [return: MarshalAs(UnmanagedType.IDispatch)]
        static Object CreateDotNetObject()
        {
            return new MyFunctions();
        }
    }
}

在VBA中的声明如下:

Private Declare Function CreateDotNetObject Lib "c:\temp\MyFunctions.dll" () As Object

但是当我尝试实例化一个对象时,我得到了上面提到的错误。

Sub test()

    Dim o As Object
    Set o = CreateDotNetObject()

End Sub

这是我第一次尝试在 Excel 中使用自定义 dll 函数而不在 VBA 中添加引用。如果我添加一个引用(早期绑定(bind)),这些函数确实可以工作,但 DLL 不会传播给使用电子表格的每个人,我需要它在运行正常函数时不会崩溃。

编辑:附加信息。我只是注意到,除了 DLL 之外,当我在 Visual Studio 中构建解决方案时,我还会得到一个“Object FileLibrary”和一个“Exports Library File”。当我注册 DLL 时,我应该用 .exp 或 .lib 做些什么吗?

谢谢,

迈克

最佳答案

我在构建解决方案时将类库属性中的平台目标设置为“任何 PC”,这显然不允许导出。当我将它切换到“x86”时,它完全可以工作。

关于C# DLL 使用 DllExport : No entry point when called in VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23415566/

相关文章:

sql - 使用当前连接从 sql 存储过程调用 dll 函数

asp.net - ASP 创建对象时没有此类接口(interface)支持错误

c# - 为什么不允许指向泛型类型的指针?

c# - 如何使用 Monotouch 遍历 CGPDFDictionary?

excel - Excel 中具有多个条件的 SumIf 公式

Excel - 日期范围包括一天中的给定时间(更好的方法)

c# - 在c#中创建dll文件

c# - 在 C# 中为不同的类使用类型化变量

c# - 可拖动的 WinForm 问题

excel - 将一个大的 xls 文件读入 R