您的位置:首页 > 其它

VS2017开发activex

2017-10-15 20:07 218 查看
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}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  windows .net activex