繁体   English   中英

使用 DllExport 的 C# DLL:在 VBA 中调用时没有入口点

[英]C# DLL using DllExport: No entry point when called in VBA

为避免要求为电子表格的所有用户注册 Dll,我尝试使用后期绑定,以便用户无需添加对 Dll 的引用。

我已经使用 Visual Studio 在 C# 中创建了 Dll,即使我已经包含了“使用 RGiesecke.DllExport;” 并在函数上使用 DllExport 返回一个包含我需要在 VBA 中访问的函数的对象,我仍然收到错误“运行时错误‘453’:无法在 C:\\temp\\MyFunctions 中找到 DLL 入口点 CreateDotNetObject。 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 中添加引用。 如果我添加引用(早期绑定),这些函数确实可以工作,但 DLL 不会传播给使用电子表格的每个人,我需要它在运行正常函数时不会崩溃。

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

谢谢,

麦克风

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM