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.csdn.net/laironggui/article/details/79422118

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章