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'.