首页 新闻 会员 周边 捐助

vs2005 C# 下创建activex 插件,客户端显示红叉,请教

0
悬赏园豆:50 [已解决问题] 解决于 2009-11-05 13:18

相关步骤如下:
==================================================================================
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
=========================

问题补充: 安装正常的,我见过客户端的确是安装成功了.刷新过了,还是一个样子. 所有功能,在本机测试是没有问题的.
蓝色开阔地的主页 蓝色开阔地 | 初学一级 | 园豆:150
提问于:2009-11-02 17:35
< >
分享
最佳答案
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互操作注册"勾上.

收获园豆:50
Launcher | 高人七级 |园豆:45050 | 2009-11-02 21:29
Galactica 兄,给我一份人的email 或者QQ也行,我把程序发你. 另外,我的安装过程是没有问题的,activex 的IE设置部分也处理过了.安装正常. 只是显示不正常..
蓝色开阔地 | 园豆:150 (初学一级) | 2009-11-03 08:21
还是不行,结果一样的,我有看过注册表项,按clsid查询,的确,在客户机上存在这个GUID的..说明安装辽的..到底应该是什么原因呢?
蓝色开阔地 | 园豆:150 (初学一级) | 2009-11-04 08:12
谢谢,问题,解决了,是浏览器设置的问题..
蓝色开阔地 | 园豆:150 (初学一级) | 2009-11-05 13:17
其他回答(1)
0

是不是安装完之后得让页面刷新一下呢,我也不懂,关注中。。。。

dege301 | 园豆:2825 (老鸟四级) | 2009-11-02 17:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册