VS2017开发activex

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gdp12315/article/details/78243397

activex开发有多种方式,可以是用MFC C++, C#,

以C# windows窗体控件库(.NET Framework)

新建IObjectSafety.cs文件

using System;
using System.Runtime.InteropServices;
namespace ActiveXDemo
{


    [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);
    }
}

修改UserControl.cs文件

using System;
using System.Runtime.InteropServices;
namespace ActiveXDemo
{


    [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);
    }
}

然后,修改Guid 改为自己新建的,点击工具->创建Guid

添加 安装包程序
VS2017 installproject 安装包

https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.MicrosoftVisualStudio2017InstallerProjects#qna

参考: http://www.cnblogs.com/li-peng/p/3455247.html
http://jiang.jonvie.com/post/2017/07/22/42c02ee7e97012f5

html页面设置

<object classid="clsid:CB5BDC81-93C1-11CF-8F20-00805F2CD064"></object>

//

<object type="application/x-testactive"></object>

设置 注册表

HKEY_LOCAL_MACHINE
SOFTWARE
Classes
MIME
Database
Content-Type
application/x-testactive

设置键值
CLSID {CB5BDC81-93C1-11CF-8F20-00805F2CD064}

展开阅读全文

没有更多推荐了,返回首页