我使用Robert Giesecke's非托管导出包访问Excel中的c# dll。我遵循了几个示例,并继续获得运行时错误453:“无法在myDllName.dll中找到入口点myDllName.dll”。
我在使用64位Excel的64位计算机上,正在为x64打包dll。
我正在VisualStudio2022中工作,并尝试在.NET 6.0和.Net Framework4.7.2中准备dll。
这是我的导出类:
namespace MyNamespace
{
public static class UnmanagedExports
{
//entry point for dll
static UnmanagedExports()
{
//nothing
}
[DllExport("HelloWorld", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
public static string HelloWorld()
{
return "Hello World";
}
[DllExport("MyDLLFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.IDispatch)]
static object MyDLLFunction()
{
return new InnerNamespace.MyCsharpClass();
}
}
}
下面是我的另一个C#:
namespace MyNamespace.InnerNamespace
{
[ComVisible(true), ClassInterface(ClassInterfaceType.AutoDual)]
public class MyCsharpClass
{
[return: MarshalAs(UnmanagedType.BStr)]
public async Task<string> InnerFunction(string LookupType, string LookupNumber)
{
object Response = await GetResponseAsync(LookupType, LookupNumber);
string ResultAsString = Response.ToString();
return ResultAsString;
}
}
在Excel中:
Private Declare PtrSafe Function AddDllDirectory Lib "kernel32" (ByVal lpLibFileName As String) As Integer
Public Declare PtrSafe Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As LongPtr
Public Declare PtrSafe Function MyDLLFunction Lib "C:\my\long\path\to\my\project\bin\x64\Debug\net472\myDllName.dll" () As Object
Sub Test()
Dim mObj As Object
Set mscObj = MyDLLFunction() //run time error here <- can't find entry point
End Sub
我跟踪了this example,但这不起作用。
我已经搜索并测试了各种配置,并且无法通过错误“无法找到入口点”。
发布于 2021-12-17 01:26:02
我想它已经修好了。我终于能够在dumpbin /exports输出中看到导出的函数。我认为需要做几件事来纠正这个问题。希望这对将来的人有帮助。
打包没有更新-试用VS的旧版本
基于这个包的历史,我怀疑它在VS2022中没有合作,所以我:
中打开旧项目。
DllExportAppDomainIsolatedTask误差
然后,该项目将不会构建,它继续抛出错误:
The "DllExportAppDomainIsolatedTask" task failed unexpectedly.
基于this answer I:
VS2015
之后浏览到它的位置
但我一直收到同样的错误。然后,我将设置: Project>Properties>Build>Errors和Warnings>Warning级别更改为4,从而增加了调试输出。
通过调试日志,我从UnmanagedExports包中找到了几行代码,其中引用了项目平台、框架路径、库工具路径、工具dll路径等。
我的目标是.NET框架4.7.2,因此我将项目降级为.NET Framework4.5,删除bin/obj文件夹内容并重新构建项目。然后,运行dumpbin /exports显示了我的HelloWorld函数!
--该包似乎与.NET Framework4.7.2.不兼容
https://stackoverflow.com/questions/70373749
复制相似问题