正在尝试使用regasm注册接口
我试着玩切换ComVisible的AssemblyInfo.cs,没有成功。我试着签过名。Regasm总是响应
RegAsm :警告RA0000 :未注册任何类型
我的项目是类库,.net 4.5。
我的一个cs文件- Interface.cs如下所示:
using System;
using System.Runtime.InteropServices;
namespace ComTestInterface
{
[ComImport]
[System.Security.SuppressUnmanagedCodeSecurity]
[Guid("647ED2ED-78DB-4168-B50E-DD4C506EAF53")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ImageSourceFilter
{
void SetColor();
}
}发布于 2019-05-23 17:05:45
问题解决了。我在class所在的同一项目中注册了接口。使用下一个代码接口:
[ComVisible(true)]
[System.Security.SuppressUnmanagedCodeSecurity]
[Guid("170BB172-4FD1-4eb5-B6F6-A834B344260F")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IImageSourceFilter
{
void SetColor();
}类:
[ComVisible(true)]
[Guid("170BB172-4FD1-4eb5-B6F6-A834B344268F")]
[ClassInterface(ClassInterfaceType.None)]
public class ImageSourceFilter : BaseSourceFilter,IImageSourceFilter
{
public void SetColor()
{...}
}值得一提的是,该类需要继承此接口。注册已通过项目设置中的Post-Build事件完成,参数为:
"$(TargetDir)install.bat" $(TargetName)和下面包含的install.bat:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe %1.dll /nologo /codebase /tlb: %1.tlb发布于 2019-05-22 23:03:05
删除ComImport属性并添加ComVisible属性:
[ComVisible(true)]
[System.Security.SuppressUnmanagedCodeSecurity]
[Guid("647ED2ED-78DB-4168-B50E-DD4C506EAF53")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ImageSourceFilter
{
void SetColor();
}https://stackoverflow.com/questions/56259607
复制相似问题