我制作了一个INF文件,其内容如下
[version]
Signature="$CHICAGO$"
AdvancedINF=2.0
[Add.Code]
MyControl.dll=MyControl.dll
; Now installing the ActiveX
[MyControl.dll]
file-win32-x86=thiscab
clsid={05B7BC83-FCA1-452d-9D33-193784FEC637}
FileVersion=1,0,0,1
RegisterServer=yes
但是在Internet Explorer安装完成后未注册Control,每次按F5刷新网页时,我的浏览器都会显示安装提示。这意味着它没有安装在我的机器上。当我运行regasm /tlb /codebase MyControl.dll
命令它开始工作正常...我已经在C#中编写了我的ActiveX控件,这里是注册函数
[ComRegisterFunction()]
public static void RegisterClass ( string key )
{
// Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need it
StringBuilder sb = new StringBuilder ( key ) ;
sb.Replace(@"HKEY_CLASSES_ROOT\","") ;
// Open the CLSID\{guid} key for write access
RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(),true);
// And create the 'Control' key - this allows it to show up in
// the ActiveX control container
RegistryKey ctrl = k.CreateSubKey ( "Control" ) ;
ctrl.Close ( ) ;
// Next create the CodeBase entry - needed if not string named and GACced.
RegistryKey inprocServer32 = k.OpenSubKey ( "InprocServer32" , true ) ;
inprocServer32.SetValue ( "CodeBase" , Assembly.GetExecutingAssembly().CodeBase ) ;
inprocServer32.Close ( ) ;
// Finally close the main key
k.Close ( ) ;
//MessageBox.Show("Registered");
}
请帮我解释为什么RegisterServer=yes
没有调用此函数,我必须使用regasm /tlb /codebase MyControl.dll
命令手动调用它?
答案 0 :(得分:1)
关于如何在CodeProject上的Downloading C# ActiveX Components through CAB File文章中实现Ummar的变通方法有更多细节
(免责声明:我没有尝试过 - 只是在我使用ATL和C ++后一周才发现这篇文章:-()。
答案 1 :(得分:1)
当注册了RegisterServer = yes指定的CAB内容时,它使用regsvr32。您的C#程序集需要regasm,因此您需要一个额外的机制来强制执行regasm。建议的方法是使用msi包,它将为用户提供卸载组件的方法。