I'm using Robert Giesecke's Unmanaged Exports package to access c# dll in Excel VBA. I've followed several examples and continue to get the run-time error 453: "can't find entry point MyDLLFunction in myDllName.dll"
I'm on a 64bit machine using 64bit Excel and am packaging the dll for x64.
I'm working in Visual Studio 2022 and have tried preparing the dll in both .NET 6.0 and .Net Framework 4.7.2.
Here's my exported class:
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();
}
}
}
Then here is my other 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;
}
}
In Excel VBA:
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
I followed this example but it's not working.
I've googled and tested out various configurations and have been unable to get past the error 'can't find entry point'.
I believe it's fixed. I'm finally able to see exported functions in the dumpbin /exports output. There were several things that I believe needed to be done to correct the problem. Hope this helps someone in the future.
Packaged is Not Updated - Try Older Version of VS
Based on the age of the package I suspected it wasn't cooperating in VS2022 so, I:
DllExportAppDomainIsolatedTask Error
Then, the project wouldn't build, it kept throwing the error:
The "DllExportAppDomainIsolatedTask" task failed unexpectedly.
Based on this answer I:
But I kept receiving the same error. I then increased the debug output by changing the setting: Project>Properties>Build>Errors and Warnings>Warning Level to 4.
Digging through the debug log I found several lines from the UnmanagedExports package which referenced the project platform, framework path, library tools path, tools dll path, etc. In that section I found:
System.ArgumentException: Requested value 'Version47' was not found.
I was targeting .NET Framework 4.7.2 so I downgraded the project to target .NET Framework 4.5, deleted the bin/obj folder contents and rebuilt the project. Then, running dumpbin /exports showed my HelloWorld function!
It doesn't appear the package is compatible with .NET Framework 4.7.2.