2012-10-12 67 views
2

我有注册我的COM C#组件的问题,这里是代码:注册COM C#组件 - TYPE_E_REGISTRYACCESS

[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

什么,我做错了什么?

+0

错误是[0x8002801C'TYPE_E_REGISTRYACCESS'访问OLE注册表时出错](http://alax.info/blog/1383)。还有其他主题看起来非常相似,例如http://stackoverflow.com/questions/5107840/visual-studio-2010-type-e-registryaccess,建议检查COM互操作设置。 –

回答

2

在Windows Vista及更高版本上,您必须从提升的命令提示符处运行Regasm.exe,以便该工具具有写入注册表的权限。点击开始按钮,程序,附件。右键单击“命令提示符”快捷方式,然后选择“以管理员身份运行”。

如果您仍然遇到麻烦,那么您可以使用SysInternals的ProcMon实用程序来查看Regasm.exe写入注册表。它是写入时遇到的TypeLib键,您会发现它在ProcMon跟踪中失败,并且可能具有更好的诊断功能。

请注意,您应该在开发机器上对Regasm.exe使用/ codebase选项,以便您不必将程序集放入GAC中。您可以忽略生成的警告。