VS 2017 OCX

先写下inf文件,这鬼东西耗了我好久。

先是用的这种,项目的配置ini文件怎么都不能复制到指定的目录里,设置的目录是DestDir=53; 53是用户目录。

[version]
signature="$CHICAGO$"
AdvancedINF=2.0

[Add.Code]
SoundIPMFCActiveXControl2.ocx=SoundIPMFCActiveXControl2.ocx
Callstation.dll=Callstation.dll
libmp3lame.dll=libmp3lame.dll
mp3gain.dll=mp3gain.dll
SoundIPNew.dll=SoundIPNew.dll
mylame.dll=mylame.dll
soundipminimedia.ini=soundipminimedia.ini

[SoundIPMFCActiveXControl2.ocx]
file-win32-x86=thiscab
clsid={47FDDF50-0BD1-4BFC-B687-7726478CD3A2}
FileVersion=1,0
RegisterServer=yes

[Callstation.dll]
file-win32-x86=thiscab

[libmp3lame.dll]
file-win32-x86=thiscab

[mp3gain.dll]
file-win32-x86=thiscab

[SoundIPNew.dll]
file-win32-x86=thiscab

[mylame.dll]
file-win32-x86=thiscab

[soundipminimedia.ini]
file-win32-x86=thiscab
DestDir=53

;END OF INF FILE

然后换成了下面这种,文件才

[version]
signature="$CHICAGO$"
AdvancedINF=2.0

[DefaultInstall]
CopyFiles=InstallFilesSection,InstallInfSection
RegisterOCXs=RegisterFiles

[DefaultUninstall]
cleanup=1
Delfiles=InstallFilesSection,InstallInfSection
UnRegisterOCXs=RegisterFiles

[RegisterFiles]
"%11%\SoundIPMFCActiveXControl2.ocx"

[InstallFilesSection]
SoundIPMFCActiveXControl2.ocx=SoundIPMFCActiveXControl2.ocx
Callstation.dll=Callstation.dll
libmp3lame.dll=libmp3lame.dll
mp3gain.dll=mp3gain.dll
SoundIPNew.dll=SoundIPNew.dll
mylame.dll=mylame.dll


[InstallInfSection]
soundipminimedia.ini=soundipminimedia.ini


[SoundIPMFCActiveXControl2.ocx]
file-win32-x86=thiscab
clsid={47FDDF50-0BD1-4BFC-B687-7726478CD3A2}
FileVersion=1,0

[Callstation.dll]
file-win32-x86=thiscab

[libmp3lame.dll]
file-win32-x86=thiscab

[mp3gain.dll]
file-win32-x86=thiscab

[SoundIPNew.dll]
file-win32-x86=thiscab

[mylame.dll]
file-win32-x86=thiscab

[soundipminimedia.ini]
file-win32-x86=thiscab

[DestinationDirs]
InstallFilesSection=11
InstallInfSection=53

 

关于inf文件的说明,微软的关于inf的说明DestinationDirs按照 files-section=dirid,"path",path 中指定的目录需要存在。

一:OCX控件在web页面不能加载的问题 SCRIPT3: 找不到成员 需要添加 IObjectSafety接口

二:制作完OCX控件之后,就要给控件加上数字签名,否则当用户下载安装时,系统会直接禁止该控件的安装,除非事先对IE设置降低了安全级别。

三:hook

1:How To Download Dependent DLLs in Internet Explorer with an .inf File

这个链接的文章里也涉及到了hook.

2:https://technet.microsoft.com/en-us/windows/aa741209(v=vs.60)

这个链接的文章里也涉及到了hook.

A hook is a way to override or customize the installation process of one or more pieces required for a component. There are two types of hooks—unconditional and conditional.

Unconditional Hooks
Conditional Hooks


Unconditional Hooks
Unconditional hooks are hooks that always get executed. These hooks are mentioned in the [Setup Hooks] section of the Internet Component Download INF file. A good example of an unconditional hook is a setup program. The following is an example of a case using a custom setup program to install the component. Its packaging is as follows:

CODEBASE= points to an example.cab that contains an example_setup.exe, example.ocx, and example.inf file. The example_setup.exe, when run with the /q parameter, will install example.ocx silently in the windows\occache directory.
example.inf has:
  
[Setup Hooks] 
hook1=hook1 
 
[hook1] 
run=%EXTRACT_DIR%\example_setup.exe /q 
 
[Version] 
; This section is required for compatibility on both Windows 95 and Windows NT. 
Signature="$CHICAGO$" 
AdvancedInf=2.0 
 
When the Code Downloader pulls down example.cab, it trust verifies the cabinet and then processes the INF. After Windows Internet Explorer finds that there is no [Add.Code] section, it processes the [Setup Hooks] section. It extracts all the files in example.cab in a unique temporary directory and then runs the command line listed in the run= key. All the files left in the temporary directory after the completion of example_setup.exe, including example_setup.exe, are discarded.

Conditional Hooks
Conditional hooks are run only when a certain condition evaluates as TRUE. This is typically when the [Add.Code] section points to a certain piece, and that piece is not available on the client's computer. The above example of example.ocx could be rewritten using conditional hooks as follows:

CODEBASE= points to an example.cab that contains an example_setup.exe, example.ocx, and example.inf file. The example_setup.exe, when run with the /q parameter, will install example.ocx silently in the windows\occache directory.
example.inf has:
[Add.Code] 
example.ocx=example.ocx 


 //在这个项里,不能添加File-win32-x86=thiscab、RegisterServer=yes,这类的信息,仅见过能添加FileVersion、Clsid这2个。
[example.ocx] 
Clsid={...} 
hook=hook1 
 
[hook1] 
run=%EXTRACT_DIR%\example_setup.exe /q 
 
[Version] 
; This section is required for compatibility on both Windows 95 and Windows NT. 
Signature="$CHICAGO$" 
AdvancedInf=2.0 
 
When the Code Downloader sees the above INF, it processes the [Add.Code] section. When processing the example.ocx section, it sees that the CLSID (example.ocx) is not registered/available on the client computer and so proceeds to execute the hook mentioned in the hook= key when it is hook1. Execution of hook1 is identical to the previous description of the hook as an unconditional hook. When only one component is in question, it doesn't make any difference whether it's marked conditional or unconditional as the whole code download was triggered because the CLASSID attribute in the object tag could not be found on the client computer. However, when installing a component that relies on some dependency that is separately installable by itself, such as Microsoft Foundation Classes (MFC) DLLs, it is good to use conditional hooks to install them.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

制作OCX

VS2017,WIN10

客户,嗯,就是给钱的主,要求提供OCX控件以方便Web上用Js调用。

脑子一片空白!

搜!

结果多数是VS2010、VS2012,没有VS2017分享。果然OCX要没落了。

但是客户是上帝啊!

先是下载到2个VS老版本的,还是一头雾水。一遍一遍看,一遍一遍查,过程如下。

1,自动生成工程,基本上一路下一步

 改了这一部分

2,先编译一下,正确生成

3,注册

regsvr32  C:\Users\dvs-1\Documents\Visual Studio 2017\Projects\MFCActiveXControl1\Debug\MFCActiveXControl1.ocx

如果OCX用到了其它自定义的DLL,需要跟普通EXE一样部署,同路径下或者Windows路径下。

4,debug调试, OCX在网页中是以object方式实现引用的。在VS中设置断点是不能被触发的。

<OBJECT  type="application/x-oleobject"  classid="clsid:2F434CDB-87F8-4474-A712-68B7E5D6F49F" id="TestOCX" name="TestOCX" width="1px" height="1px" ></OBJECT>

classid 是在这样位置的uuid。idl中有多个uuid,需要用这个。 idl中最后一个。

或者在注册表中查询控件名称,找到如下路径也可以。不清楚是不是因为控件是32位的,路径为wow6432node。 

5,添加接口方法,需要切换到“类视图”

 

6,添加接口事件,同上,需要切换到“类视图”

7,接口事件不能被JS响应

如果在构造函数调用事件,在web端不能触发此事件。最后我初始化放在了一个接口方法中(线程问题?没研究)。也就是由JS调用接口方法,在方法中完成初始化。在接口函数中调用接口事件进行反馈。

8,SCRIPT3: 找不到成员。参考 https://blog.youkuaiyun.com/laironggui/article/details/79422118

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值