expose .net Core Components to com
Как правильно создать классы COM с .net8? Я могу вызвать C# код из VBA. < /P>
Мой C# выглядит так: < /p>
Код: Выделить всё
using System.Runtime.InteropServices;
namespace MyTest.COM
{
[Guid("9d02f386-c90e-4353-964a-d3bdbad2c9f3")]
[ProgId("MyTest.COM.MyTestCOMDebug")]
public class MyTestCOMDebug : IMyTestCOMDebug
{
public int Add(int x, int y) => x + y;
}
[Guid("e6c5eb34-8412-4f17-a8e7-ef5e091841c5")]
public interface IMyTestCOMDebug
{
int Add(int x, int y);
}
}
< /code>
Мой файл проекта выглядит следующим образом: < /p>
net8.0
enable
enable
true
true
99134f79-a83c-4354-94f0-cfa52ea1ec0e
System.Runtime.InteropServices.ClassInterfaceType.None
true
true
true
all
runtime; build; native; contentfiles; analyzers; buildtransitive
true
< /code>
и мой рабочий метод VBA выглядит следующим образом: < /p>
Sub Test3()
Dim dbg As MyTest_COM.IMyTestCOMDebug
Set dbg = CreateObject("MyTest.COM.MyTestCOMDebug")
Dim b As Integer
b = dbg.Add(2, 2)
MsgBox b
End Sub
Код: Выделить всё
Dim dbg As MyTest_COM.IMyTestCOMDebug
Подробнее здесь: https://stackoverflow.com/questions/796 ... sed-to-com