相关步骤如下:
==================================================================================
1.编写activex 插件DLL功能组件,并配置生成
//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
=============================
通过IE安全控件认证,实现IObjectSafeTy接口
#####################################
/// <summary>
/// 创建IObjectSafety接口
/// </summary>
[ComImport, Guid("415fa9ac-887c-48da-a7c2-db8fc31c44f1")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IObjectSafety
{
[PreserveSig]
void GetInterfacceSafyOptions(
int riid,
out int pdwSupportedOptions,
out int pdwEnabledOptions);
[PreserveSig]
void SetInterfaceSafetyOptions(
int riid,
int dwOptionsSetMask,
int dwEnabledOptions);
}
#####################################
实现IObjectSafety接口代码:
#####################################
#region IObjectSafety 成员
public void GetInterfacceSafyOptions(int riid, out int pdwSupportedOptions, out int pdwEnabledOptions)
{
pdwSupportedOptions = 1;
pdwEnabledOptions = 2;
}
public void SetInterfaceSafetyOptions(int riid, int dwOptionsSetMask, int dwEnabledOptions)
{
throw new System.NotImplementedException();
}
#endregion
#####################################
===========================
2.添加安装项目,以DLL文件项目为主输出,生成activex插件的msi格式的可安装文件
=========================
改动ActiveX控件的主输出文件的属性,将其Register属性改为vsdrpCOM.
=========================
3.编写inf文件(内容见底部)
4.根据msi文件和inf文件用CABARC.EXE生成cab文件(打包)
CABARC.EXE -s 6144 n C:\ControlSetUp.cab C:\ControlSetUp.msi C:\ControlSetUp.inf
5.生成pfx密钥(测试证书及密钥)
===================
makecert -r -n "CN= BroadWay Firm" -b 01/01/2008 -e 01/01/2018 -sv c:\myselfName.pvk c:\myselfName.cer
cert2spc c:\myselfName.cer c:\myselfName.spc
pvkimprt -pfx c:\myselfName.spc c:\myselfName.pvk
===================
6.为cab包签名
signtool signwizard
给数据盖时间戳
http://timestamp.verisign.com/scripts/timstamp.dll
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
以上生成过程中,都没有出问题,最后在客户端安装过以后,显示是个红叉.. 望大侠指教.谢谢
附:
[inf文件]
=========================
[Setup Hooks]
hook1=hook1
[hook1]
run=msiexec.exe /i %EXTRACT_DIR%\ControlSetUp.msi /qn
[Version]
; This section is required for compatibility on both Windows 95 and Windows NT.
Signature="$CHICAGO$"
AdvancedInf=2.0
=========================
在IE的设置里,把ActiveX相关设置都改成 提示 或者 启用.
你要是不嫌弃的话,可以把控件发一份给我,我帮你调试下.
修改你的部分源代码:
/// <summary>
/// 创建IObjectSafety接口
/// </summary>
[ComImport, GuidAttribute("CB5BDC81-93C1-11CF-8F20-00805F2CD064")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IObjectSafety
{
[PreserveSig]
int GetInterfaceSafetyOptions(
ref Guid riid,
[MarshalAs(UnmanagedType.U4)]
ref int pdwSupportedOptions,
[MarshalAs(UnmanagedType.U4)]
ref int pdwEnabledOptions);
[PreserveSig()]
int SetInterfaceSafetyOptions(
ref Guid riid,
[MarshalAs(UnmanagedType.U4)]
int dwOptionSetMask,
[MarshalAs(UnmanagedType.U4)]
int dwEnabledOptions);
}
#region IObjectSafety 成员
private const string _IID_IDispatch = "{00020400-0000-0000-C000-000000000046}";
private const string _IID_IDispatchEx = "{a6ef9860-c720-11d0-9337-00a0c90dcaa9}";
private const string _IID_IPersistStorage = "{0000010A-0000-0000-C000-000000000046}";
private const string _IID_IPersistStream = "{00000109-0000-0000-C000-000000000046}";
private const string _IID_IPersistPropertyBag = "{37D84F60-42CB-11CE-8135-00AA004BB851}";
private const int INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001;
private const int INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002;
private const int S_OK = 0;
private const int E_FAIL = unchecked((int)0x80004005);
private const int E_NOINTERFACE = unchecked((int)0x80004002);
private bool _fSafeForScripting = true;
private bool _fSafeForInitializing = true;
public int GetInterfaceSafetyOptions(ref Guid riid, ref int pdwSupportedOptions, ref int pdwEnabledOptions)
{
int Rslt = E_FAIL;
string strGUID = riid.ToString("B");
pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;
switch (strGUID)
{
case _IID_IDispatch:
case _IID_IDispatchEx:
Rslt = S_OK;
pdwEnabledOptions = 0;
if (_fSafeForScripting == true)
pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;
break;
case _IID_IPersistStorage:
case _IID_IPersistStream:
case _IID_IPersistPropertyBag:
Rslt = S_OK;
pdwEnabledOptions = 0;
if (_fSafeForInitializing == true)
pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA;
break;
default:
Rslt = E_NOINTERFACE;
break;
}
return Rslt;
}
public int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions)
{
int Rslt = E_FAIL;
string strGUID = riid.ToString("B");
switch (strGUID)
{
case _IID_IDispatch:
case _IID_IDispatchEx:
if (((dwEnabledOptions & dwOptionSetMask) == INTERFACESAFE_FOR_UNTRUSTED_CALLER) && (_fSafeForScripting == true))
Rslt = S_OK;
break;
case _IID_IPersistStorage:
case _IID_IPersistStream:
case _IID_IPersistPropertyBag:
if (((dwEnabledOptions & dwOptionSetMask) == INTERFACESAFE_FOR_UNTRUSTED_DATA) && (_fSafeForInitializing == true))
Rslt = S_OK;
break;
default:
Rslt = E_NOINTERFACE;
break;
}
return Rslt;
}
#endregion
assembly中这一行不要注释掉:
[assembly: Guid("415fa9ac-887c-48da-a7c2-db8fc31c44f1")]
另外,release版本也要在项目属性中把"为COM互操作注册"勾上.
是不是安装完之后得让页面刷新一下呢,我也不懂,关注中。。。。