10 c# com-interop comvisible typelib visual-studio
我使用VS2005制作了一个简单的C#DLL(这是一个更大的项目的一部分).我需要通过VBA代码在Excel中使用DLL,所以我在程序集上使用COM Interop.我正在尝试使构建过程自动生成必要的TLB文件,这样我就不需要在每次构建之后转到命令行并使用regasm.
我的问题是虽然DLL编译和构建正常,但它不会生成TLB文件.相反,标题中的错误在输出框中打印出来.
我已经获得了其他DLL来构建TLB文件,方法是转到VS2005中的项目属性 - > Build - > Output - > Check "Register for COM interop".另外,我在AssemblyInfo.cs中有[assembly:ComVisible(true)].
以下是问题DLL的源代码摘要以及它为返回类型引用的DLL:
using System;
using System.IO;
using System.Runtime.InteropServices;
using SymbolTable;
namespace ProblemLibrary
{
public class Foo
{
public Foo(string filename)
{
...
}
// method to read a text file into a SymbolTable
public SymbolTable BuildDataSet(string[] selected)
{
...
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下是SymbolTable.dll的摘要.它包含ProblemLibrary使用的返回类型.
using System;
using System.Collections.Generic;
namespace SymbolTable
{
public class SymbolTable
{
readonly Dictionary<SymbolInfoStub, string> _symbols = new Dictionary<SymbolInfoStub, string>();
/*methods that interact with Dictionary snipped*/
}
}
Run Code Online (Sandbox Code Playgroud)
Sha*_*men 21
确保你在程序集级别拥有GuidAttribute.
[Guid("<PUT-GUID-HERE-1>")]
[ComVisible(true)]
interface IFoo
{
void DoFoo();
}
[Guid("<PUT-GUID-HERE-2>")]
[ComVisible(true)]
[ProgId("ProgId.Foo")]
class Foo : IFoo
{
public void DoFoo()
{
}
}
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
14262 次 |
| 最近记录: |