解析 .net tlb 引用
Resolve .net tlb reference
现在我正在编写一个 .net dll,它应该可以在 VBA 代码(Excel、Access 等)中使用。以下设置工作正常:
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true)]
[Guid("8079e4a4-1e4b-4788-92ba-9d5b017fa9be")] //Allocate your own GUID
public interface ICommunication
{
string TestProp { get; set; }
string Login();
string Disconnect();
}
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
[Guid("19fd86e2-f1b9-478c-ba7a-bd76bdf19b85")] //Allocate your own GUID
[ProgId("TestDll.Communication")]
public class Communication : ICommunication
{
public string TestProp { get; set; }
public string Login()
{
// use of BouncyCastle here
return "logged in";
}
public string Disconnect()
{
// ...
return "disconnected";
}
}
通过引用生成的 tlb 文件,我可以正确使用 属性 以及 Disconnect 函数,但是调用 Login 函数会导致问题("File not found" messagebox in Excel),我猜是与引用的BouncyCastle的使用相关。
Sub Button1_Click()
Dim o: Set o = CreateObject("TestDll.Communication")
Dim value As String
value = o.Login()
MsgBox value
End Sub
处理 com 可见库中对其他 .net 程序集的引用的最佳方法是什么?到目前为止,我尝试将 bouncycastle 注册到 GAC 但没有成功。
谢谢:)
确实像上面提示的文件无法读取:
在每次构建时,我都会在项目的 bin 目录中放置一个 .txt 文件,该文件是运行时读取的。
在我的解决方案中使用 dll 可以找到该文件,因为相对路径是我的 bin 目录但是使用 tlb 相对根路径是登录 windows 用户的文档文件夹。
有趣的是,我一直认为错误与我将 dll 设置为 com 可见的方式有关:)。
现在我正在编写一个 .net dll,它应该可以在 VBA 代码(Excel、Access 等)中使用。以下设置工作正常:
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true)]
[Guid("8079e4a4-1e4b-4788-92ba-9d5b017fa9be")] //Allocate your own GUID
public interface ICommunication
{
string TestProp { get; set; }
string Login();
string Disconnect();
}
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
[Guid("19fd86e2-f1b9-478c-ba7a-bd76bdf19b85")] //Allocate your own GUID
[ProgId("TestDll.Communication")]
public class Communication : ICommunication
{
public string TestProp { get; set; }
public string Login()
{
// use of BouncyCastle here
return "logged in";
}
public string Disconnect()
{
// ...
return "disconnected";
}
}
通过引用生成的 tlb 文件,我可以正确使用 属性 以及 Disconnect 函数,但是调用 Login 函数会导致问题("File not found" messagebox in Excel),我猜是与引用的BouncyCastle的使用相关。
Sub Button1_Click()
Dim o: Set o = CreateObject("TestDll.Communication")
Dim value As String
value = o.Login()
MsgBox value
End Sub
处理 com 可见库中对其他 .net 程序集的引用的最佳方法是什么?到目前为止,我尝试将 bouncycastle 注册到 GAC 但没有成功。
谢谢:)
确实像上面提示的文件无法读取: 在每次构建时,我都会在项目的 bin 目录中放置一个 .txt 文件,该文件是运行时读取的。 在我的解决方案中使用 dll 可以找到该文件,因为相对路径是我的 bin 目录但是使用 tlb 相对根路径是登录 windows 用户的文档文件夹。
有趣的是,我一直认为错误与我将 dll 设置为 com 可见的方式有关:)。