我在注册 COM C# 组件时遇到问题,代码如下:
[Guid("BBA10049-5A29-46f2-9D6A-084A38345F11"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface DBCOM_Events
{
}
[Guid("793DD198-0E9C-4b2d-9C4D-609584D8B4DC"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(DBCOM_Events))]
public class CSharpIstreamWraper : IStream
{
public Stream InnerStream;
public string name;
public CSharpIstreamWraper(Stream NetworkStream, string name_ = null)
{
InnerStream = NetworkStream;
name = name_;
}
public void Clone(out IStream istream)
{
istream = (CSharpIstreamWraper)(new CSharpIstreamWraper(InnerStream));
}
public void Commit(int i1)
{
throw new NotImplementedException();
}
public void CopyTo(IStream istr, long i1, IntPtr ptr1, IntPtr ptr2)
{
throw new NotImplementedException();
}
public void LockRegion(long l1, long l2, int i1)
{
throw new NotImplementedException();
}
public void Read(byte[] pv, int cb, System.IntPtr pcbRead)
{
Marshal.WriteInt64(pcbRead, (Int64)InnerStream.Read(pv, 0, cb));
}
public void Revert()
{
throw new NotImplementedException();
}
public void Seek(long dlibMove, int dwOrigin, System.IntPtr plibNewPosition)
{
Marshal.WriteInt64(plibNewPosition, InnerStream.Seek(dlibMove, (SeekOrigin) dwOrigin));
}
public void SetSize(long l1)
{
throw new NotImplementedException();
}
public void Stat(out System.Runtime.InteropServices.ComTypes.STATSTG st, int i)
{
st = new System.Runtime.InteropServices.ComTypes.STATSTG();
}
public void UnlockRegion(long l1, long l2, int i1)
{
throw new NotImplementedException();
}
public void Write(byte[] pv, int cb, System.IntPtr pcbRead)
{
int written = Marshal.ReadInt32(pcbRead);
InnerStream.Write(pv, 0, written);
// InnerStream.Write(pv, 0, cb);
// Marshal.WriteInt64(pcbRead, cb);
}
}
我使用guidgen.exe实用程序并选择用于生成Guid的注册表格式并创建强名称,使用实用程序SN.EXE。执行这些步骤后,当我尝试使用 regasm 注册它时:[regasm xxx.dll/tlb:xxx.tlb]
我收到错误:RA0000 HRESULT 0x8002801c
我做错了什么?
最佳答案
在 Windows Vista 及更高版本上,您必须从提升的命令提示符运行 Regasm.exe,以便该工具具有写入注册表的权限。单击“开始”按钮、“程序”、“附件”。右键单击“命令提示符”快捷方式并选择“以管理员身份运行”。
如果您仍然遇到问题,则可以使用 SysInternals 的 ProcMon 实用程序来查看 Regasm.exe 写入注册表的情况。它是在写入时遇到问题的 TypeLib 键,您会在 ProcMon 跟踪中看到它失败,并且可能有更好的诊断。
请注意,您应该在开发计算机上使用 Regasm.exe 的/codebase 选项,这样您就不必将程序集放入 GAC 中。您可以忽略生成的警告。
关于c# - 注册 COM c# 组件 - TYPE_E_REGISTRYACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12854006/